import sys input = sys.stdin.readline from collections import Counter N=int(input()) A=list(map(int,input().split())) ANS=0 for x in range(1,31): B=[A[i]-x for i in range(N)] S=[0] for b in B: S.append(S[-1]+b) C=Counter() CX=Counter() C[0]=1 for i in range(N): if A[i]==x: s=S[i+1] ANS+=C[s]-1 CX[s]+=1 C[S[i+1]]+=1 #print(S) #print(C) #print(x,ANS) for cv in CX.values(): ANS-=cv*(cv-1)//2 #print(x,ANS) B.reverse() S2=[0] for b in B: S2.append(S2[-1]+b) C=Counter() C[0]=1 A.reverse() for i in range(N): if A[i]==x: s=S2[i+1] ANS+=C[s]-1 C[S2[i+1]]+=1 #print(x,ANS) print(1+N*(N-1)//2-ANS)