import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    ls = [0] * (N+1)
    ls[0] = 1
    s = 0
    for a in A:
        s += a
        ls[s] += 1
    ans = 0
    for i in ls:
        if i > 1:
            ans += i * (i - 1) // 2
    print(ans)

if __name__ == '__main__':
    main()

