Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = [int(x) for x in input().split()]
- n = a[0]
- a.pop(0)
- stack = []
- ans = i = 0
- while i < n:
- x = a[i]
- if len(stack) == 0:
- stack.append( [x, 1] )
- elif stack[-1][0] == x:
- stack[-1][1] += 1
- else:
- y = stack[-1]
- if y[1] > 2:
- stack.pop()
- ans += y[1]
- continue
- stack.append( [x, 1] )
- i += 1
- if stack[-1][1] > 2:
- ans += stack[-1][1]
- print(ans)
Advertisement
Add Comment
Please, Sign In to add comment