def slove():

    import sys

    import collections

    input = sys.stdin.readline

    n = int(input().rstrip('\n'))

    a = list(map(int, input().rstrip('\n').split()))

    t = 0

    tl = [0]

    for v in a:

        t += v

        tl.append(t)

    tl = collections.Counter(tl)

    s = 0

    for k, v in list(tl.items()):

        s += (v * (v - 1) // 2)

    print(s)





if __name__ == '__main__':

    slove()

def slove():

    import sys

    import collections

    input = sys.stdin.readline

    n = int(input().rstrip('\n'))

    a = list(map(int, input().rstrip('\n').split()))

    ans = [0]

    t = 0

    for i in range(n):

        t += a[i]

        ans.append(t)

    ans = collections.Counter(ans)

    t = 0

    for k, v in list(ans.items()):

        t += (v * (v - 1) // 2)

    print(t)





if __name__ == '__main__':

    slove()

def slove():
    import sys
    import collections

    input = sys.stdin.readline
    n = int(input().rstrip("\n"))
    a = list(map(int, input().rstrip("\n").split()))
    t = 0
    tl = [0]
    for v in a:
        t += v
        tl.append(t)
    tl = collections.Counter(tl)
    s = 0
    for k, v in list(tl.items()):
        s += v * (v - 1) // 2
    print(s)


if __name__ == "__main__":
    slove()

def slove():
    import sys
    import collections

    input = sys.stdin.readline
    n = int(input().rstrip("\n"))
    a = list(map(int, input().rstrip("\n").split()))
    ans = [0]
    t = 0
    for i in range(n):
        t += a[i]
        ans.append(t)
    ans = collections.Counter(ans)
    t = 0
    for k, v in list(ans.items()):
        t += v * (v - 1) // 2
    print(t)


if __name__ == "__main__":
    slove()

+    ans = [0] -    tl = [0] -    for v in a: -        t += v -        tl.append(t) -    tl = collections.Counter(tl) -    s = 0 -    for k, v in list(tl.items()): -        s += v * (v - 1) // 2 -    print(s) +    for i in range(n): +        t += a[i] +        ans.append(t) +    ans = collections.Counter(ans) +    t = 0 +    for k, v in list(ans.items()): +        t += v * (v - 1) // 2 +    print(t)