import math
n = int(input())
a = list(map(int,input().split()))
list_S = [0]
S = 0
ans = 0
for i in range(n):
    S += a[i]
    list_S.append(S)
S_set = list(set(list_S))
for i in range(len(S_set)):
    I = list_S.count(S_set[i])
    if 3 <= I:
        ans += math.factorial(I) // (math.factorial(I-2)*2)
    elif I == 2:
        ans += 1
    else:
        pass
print(ans)
