zhukov000

Balls

Nov 8th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. a = [int(x) for x in input().split()]
  2. n = a[0]
  3. a.pop(0)
  4.  
  5. stack = []
  6. ans = i = 0
  7. while i < n:
  8.   x = a[i]
  9.   if len(stack) == 0:
  10.     stack.append( [x, 1] )
  11.   elif stack[-1][0] == x:
  12.     stack[-1][1] += 1
  13.   else:
  14.     y = stack[-1]
  15.     if y[1] > 2:
  16.       stack.pop()
  17.       ans += y[1]
  18.       continue
  19.     stack.append( [x, 1] )
  20.   i += 1
  21.  
  22. if stack[-1][1] > 2:
  23.   ans += stack[-1][1]
  24. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment