import sys
input = sys.stdin.readline
from itertools import accumulate
from collections import Counter


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    S = [0] + list(accumulate(A)) + [10**9+1]
    S.sort()
    prev = -10**9+1
    count = 0
    ans = 0
    for s in S:
        if prev == s:
            count += 1
        else:
            if count >= 2:
                ans += count * (count-1) // 2
            count = 1
        prev = s
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
