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()
    C[0]=1
    for i in range(N):
        if A[i]==x:
            s=S[i+1]
            ANS+=C[s]-1
        C[S[i+1]]+=1
print(1+N*(N-1)//2-ANS)