from collections import Counter N=int(input()) A=list(map(int,input().split())) ans=N*(N+1)//2 for i in range(1,30): cum=[0]*(N+1) for j in range(N): cum[j+1]=cum[j]+(A[j]-i) left=Counter() dl=Counter() cnt2=Counter({0:1}) for j in range(N): if A[j]!=i: left[cum[j]]+=1 if A[j]!=i: dl[cum[j+1]]+=left[cum[j+1]] cnt2[cum[j+1]]+=1 for c in cnt2: ans-=(cnt2[c]*(cnt2[c]-1)//2-dl[c]) print(ans)