n = int(input())
aa = list(map(int, input().split()))

s =[0]*(n+1)
for i in range(n):
    s[i+1] = s[i] + aa[i]
print(sorted(s))
ans=0
for x in set(s):
    c = s.count(x)
    ans+= c*(c-1)//2
print(ans)