a=b=m=s=0 for c in[*open(0)][1].split():c=int(c);m+=a+c==b*2or 2-m;s+=s