import bisect
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]


a_sum = [0]
for i in range(n):
    a_sum.append((a_sum[-1]+a[i]))

val = deque()
cnt = deque()
for i in range(n+1):
    idx = bisect.bisect_left(val, a_sum[i])
    if len(val) > idx and val[idx] == a_sum[i]:
        cnt[idx] += 1
    else:
        # val.insert(idx, a_sum[i])
        # cnt.insert(idx, 1)

ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)