N = int(input())
A = list(map(int,input().split()))

S = []
for i in range(N):
	if i == 0:
		S.append(A[i])
	else:
		S.append(S[i-1] + A[i])
S.sort()

ans = 0
cnt = 1
cur_s = None
for s in S:
	if cur_s == s:
		cnt += 1
	else:
		if cur_s == 0:
			ans += (cnt + 1) * cnt // 2
		else:
			ans += cnt * (cnt - 1) // 2
		cnt = 1
		cur_s = s
ans += cnt * (cnt - 1) // 2
print(ans)
