def comb(n, r):
    ret = 1
    if (n == r) or (n == 0) or (r == 0):
        ret = 1
    else:
        for i in range(1, n + 1):
            ret *= i
        for i in range(1, r + 1):
            ret //= i
        for i in range(1, n - r + 1):
            ret //= i
    return ret

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

s = [0, a[0]]
for i in range(1, n):
    s.append(s[i]+a[i])
d = {}
for x in s:
    if x in d.keys():
        d[x] += 1
    else:
        d[x] = 1

ans = 0
for k, v in d.items():
    if v >= 2:
        ans += comb(v, 2)
print(ans)