from collections import defaultdict

N = int(eval(input()))

A = [int(a) for a in input().split()]



series = [0] * (N + 1)

for i in range(1, N+1):

    series[i] = series[i-1] + i

sumDict = defaultdict(int)

sumDict[0] = 1

sum = 0

for a in A:

    sum += a

    sumDict[sum] += 1



total = 0

for key in sumDict:

    total += series[sumDict[key] - 1]

print(total)
import sys



def solve():

    input = sys.stdin.readline

    N = int(eval(input()))

    A = [int(a) for a in input().split()]

    sumDict = dict()

    sumA = 0

    sumDict[0] = 1

    for i, a in enumerate(A):

        sumA += a

        if sumA in sumDict: sumDict[sumA] += 1

        else: sumDict[sumA] = 1

    ans = 0

    for key in sumDict: ans += sumDict[key] * (sumDict[key] - 1) // 2

    print(ans)



    return 0



if __name__ == "__main__":

    solve()
from collections import defaultdict

N = int(eval(input()))
A = [int(a) for a in input().split()]
series = [0] * (N + 1)
for i in range(1, N + 1):
    series[i] = series[i - 1] + i
sumDict = defaultdict(int)
sumDict[0] = 1
sum = 0
for a in A:
    sum += a
    sumDict[sum] += 1
total = 0
for key in sumDict:
    total += series[sumDict[key] - 1]
print(total)

import sys


def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    sumDict = dict()
    sumA = 0
    sumDict[0] = 1
    for i, a in enumerate(A):
        sumA += a
        if sumA in sumDict:
            sumDict[sumA] += 1
        else:
            sumDict[sumA] = 1
    ans = 0
    for key in sumDict:
        ans += sumDict[key] * (sumDict[key] - 1) // 2
    print(ans)
    return 0


if __name__ == "__main__":
    solve()

-from collections import defaultdict +import sys -N = int(eval(input())) -A = [int(a) for a in input().split()] -series = [0] * (N + 1) -for i in range(1, N + 1): -    series[i] = series[i - 1] + i -sumDict = defaultdict(int) -sumDict[0] = 1 -sum = 0 -for a in A: -    sum += a -    sumDict[sum] += 1 -total = 0 -for key in sumDict: -    total += series[sumDict[key] - 1] -print(total) + +def solve(): +    input = sys.stdin.readline +    N = int(eval(input())) +    A = [int(a) for a in input().split()] +    sumDict = dict() +    sumA = 0 +    sumDict[0] = 1 +    for i, a in enumerate(A): +        sumA += a +        if sumA in sumDict: +            sumDict[sumA] += 1 +        else: +            sumDict[sumA] = 1 +    ans = 0 +    for key in sumDict: +        ans += sumDict[key] * (sumDict[key] - 1) // 2 +    print(ans) +    return 0 + + +if __name__ == "__main__": +    solve()