n=int(input()) A=list(map(int,input().split())) pre=-1 kouho=set() out=[] for i in range(n): if A[i]==pre: continue if A[i] in kouho: out.appen(A[i]) kouho.add(A[i]) pre=A[i] if not out: if len(out)==1 and A[0]==A[-1]: print(1) else: print(0)