# coding:utf-8



import sys





input = sys.stdin.readline

INF = float('inf')





def inpl(): return list(map(int, input().split()))





N = int(eval(input()))

A = inpl()



S = [0]

for i in range(N):

    S.append(S[-1] + A[i])



S.sort()

cnt = 1

prev = None

ans = 0

for s in S:

    if prev == s:

        prev = s

        cnt += 1

    else:

        prev = s

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

        cnt = 1



if cnt != 1:

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



print(ans)

# coding:utf-8



import sys

from collections import Counter





input = sys.stdin.readline

INF = float('inf')





def inpl(): return list(map(int, input().split()))





N = int(eval(input()))

A = inpl()



S = [0]

for i in range(N):

    S.append(S[-1] + A[i])



cnt_num = Counter(S)

ans = 0

for num in list(cnt_num.keys()):

    cnt = cnt_num[num]

    if cnt < 2:

        continue

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



print(ans)

# coding:utf-8
import sys

input = sys.stdin.readline
INF = float("inf")


def inpl():
    return list(map(int, input().split()))


N = int(eval(input()))
A = inpl()
S = [0]
for i in range(N):
    S.append(S[-1] + A[i])
S.sort()
cnt = 1
prev = None
ans = 0
for s in S:
    if prev == s:
        prev = s
        cnt += 1
    else:
        prev = s
        ans += cnt * (cnt - 1) // 2
        cnt = 1
if cnt != 1:
    ans += cnt * (cnt - 1) // 2
print(ans)

# coding:utf-8
import sys
from collections import Counter

input = sys.stdin.readline
INF = float("inf")


def inpl():
    return list(map(int, input().split()))


N = int(eval(input()))
A = inpl()
S = [0]
for i in range(N):
    S.append(S[-1] + A[i])
cnt_num = Counter(S)
ans = 0
for num in list(cnt_num.keys()):
    cnt = cnt_num[num]
    if cnt < 2:
        continue
    ans += cnt * (cnt - 1) // 2
print(ans)

+from collections import Counter -S.sort() -cnt = 1 -prev = None +cnt_num = Counter(S) -for s in S: -    if prev == s: -        prev = s -        cnt += 1 -    else: -        prev = s -        ans += cnt * (cnt - 1) // 2 -        cnt = 1 -if cnt != 1: +for num in list(cnt_num.keys()): +    cnt = cnt_num[num] +    if cnt < 2: +        continue