import itertools
import collections
n = int(input())
a = list(map(int,input().split()))

b = [0] + a
s = list(itertools.accumulate(b))


c = collections.Counter(s)
cm = c.most_common()
print(cm)
cnt = 0
for v in cm:
    if v[1] > 1:
        cnt += (v[1]*(v[1]-1) // 2) 
print(cnt)