from collections import Counter

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

ans = 0

b = [A[0]]

for i in range(1, N):
    b.append(b[-1]+A[i])

cnt = Counter(b)
cnt[0] += 1

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    return fact[n] * factinv[r] * factinv[n-r] % p

for v in cnt.values():
    ans += cmb(v, 2, 10**9+7)

print(ans)