from collections import Counter

import numpy as np



N = int(eval(input()))

A = np.array(input().split(), dtype=np.int64)



c = Counter(A.cumsum())

c[0] += 1 # np.cumsum(), 0start では無い為 0を加える

ans = sum(v*(v-1)//2 for v in list(c.values()))

print(ans)


from itertools import accumulate

from collections import defaultdict

def resolve():

    N = int(eval(input()))

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



    Acum = [0] + list(accumulate(A))

    dic = defaultdict(int)

    ans = 0

    for i in range(N + 1):

        ans += dic[Acum[i]]

        dic[Acum[i]] += 1



    print(ans)





if __name__ == "__main__":

    resolve()
from collections import Counter
import numpy as np

N = int(eval(input()))
A = np.array(input().split(), dtype=np.int64)
c = Counter(A.cumsum())
c[0] += 1  # np.cumsum(), 0start では無い為 0を加える
ans = sum(v * (v - 1) // 2 for v in list(c.values()))
print(ans)

from itertools import accumulate
from collections import defaultdict


def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    Acum = [0] + list(accumulate(A))
    dic = defaultdict(int)
    ans = 0
    for i in range(N + 1):
        ans += dic[Acum[i]]
        dic[Acum[i]] += 1
    print(ans)


if __name__ == "__main__":
    resolve()

-from collections import Counter -import numpy as np +from itertools import accumulate +from collections import defaultdict -N = int(eval(input())) -A = np.array(input().split(), dtype=np.int64) -c = Counter(A.cumsum()) -c[0] += 1  # np.cumsum(), 0start では無い為 0を加える -ans = sum(v * (v - 1) // 2 for v in list(c.values())) -print(ans) + +def resolve(): +    N = int(eval(input())) +    A = list(map(int, input().split())) +    Acum = [0] + list(accumulate(A)) +    dic = defaultdict(int) +    ans = 0 +    for i in range(N + 1): +        ans += dic[Acum[i]] +        dic[Acum[i]] += 1 +    print(ans) + + +if __name__ == "__main__": +    resolve()