n = int(eval(input()))

a = list(map(int, input().split()))



cum = [0] * (n+1)

for i in range(n):

    cum[i+1] = cum[i] + a[i]



cum.sort()

num = cum[0]

count = 1

ans = 0

for i in range(n):

    if cum[i+1] == num:

        count += 1

    else:

        ans += count * (count - 1) // 2

        num = cum[i+1]

        count = 1



if count > 1:

    ans += count * (count - 1) // 2



print(ans)





from collections import Counter

n = int(eval(input()))

a = list(map(int, input().split()))



cum = [0] * (n+1)

for i, ai in enumerate(a):

    cum[i+1] += cum[i] + ai



cnt = Counter(cum)

ans = 0

for num in list(cnt.values()):

    ans += num * (num-1) // 2



print(ans)
n = int(eval(input()))
a = list(map(int, input().split()))
cum = [0] * (n + 1)
for i in range(n):
    cum[i + 1] = cum[i] + a[i]
cum.sort()
num = cum[0]
count = 1
ans = 0
for i in range(n):
    if cum[i + 1] == num:
        count += 1
    else:
        ans += count * (count - 1) // 2
        num = cum[i + 1]
        count = 1
if count > 1:
    ans += count * (count - 1) // 2
print(ans)

from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
cum = [0] * (n + 1)
for i, ai in enumerate(a):
    cum[i + 1] += cum[i] + ai
cnt = Counter(cum)
ans = 0
for num in list(cnt.values()):
    ans += num * (num - 1) // 2
print(ans)

+from collections import Counter + -for i in range(n): -    cum[i + 1] = cum[i] + a[i] -cum.sort() -num = cum[0] -count = 1 +for i, ai in enumerate(a): +    cum[i + 1] += cum[i] + ai +cnt = Counter(cum) -for i in range(n): -    if cum[i + 1] == num: -        count += 1 -    else: -        ans += count * (count - 1) // 2 -        num = cum[i + 1] -        count = 1 -if count > 1: -    ans += count * (count - 1) // 2 +for num in list(cnt.values()): +    ans += num * (num - 1) // 2