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) cnt=Counter({0:1}) cnt2=Counter({0:1}) for j in range(N): if cum[j]!=cum[j+1]: cnt[cum[j+1]]+=1 cnt2[cum[j+1]]+=1 for c in cnt: ans-=(cnt2[c]*(cnt2[c]-1)//2-cnt[c]*(cnt[c]-1)//2) print(1+ans)