# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
num, leader = 1, A[0]
for a in A[1:]:
if a == leader:
num += 1
elif num > 0:
num -= 1
else:
num = 1
leader = a
num = A.count(leader)
if num <= len(A) / 2:
return 0
curNum = 0
Sum = 0
for i, a in enumerate(A):
if a == leader:
curNum += 1
if curNum > (i+1) / 2 and num - curNum > (len(A)-i-1) / 2:
Sum += 1
return Sum