from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf

from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement

from collections import deque,defaultdict,Counter

from bisect import bisect_left,bisect_right

from operator import itemgetter

from heapq import heapify,heappop,heappush

from queue import Queue,LifoQueue,PriorityQueue

from copy import deepcopy

from time import time

import string

import sys

sys.setrecursionlimit(10 ** 7)

def input() : return sys.stdin.readline().strip()

def INT()   : return int(eval(input()))

def MAP()   : return list(map(int,input().split()))

def LIST()  : return list(MAP())



n = INT()

a = LIST()

s = accumulate(a)



d = defaultdict(int)

for x in s:

    d[x] += 1



ans = d[0]

for x in d:

    ans += d[x]*(d[x]-1)//2



print(ans)
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf

from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement

from collections import deque,defaultdict,Counter

from bisect import bisect_left,bisect_right

from operator import itemgetter

from heapq import heapify,heappop,heappush

from queue import Queue,LifoQueue,PriorityQueue

from copy import deepcopy

from time import time

import string

import sys

sys.setrecursionlimit(10 ** 7)

def input() : return sys.stdin.readline().strip()

def INT()   : return int(eval(input()))

def MAP()   : return list(map(int,input().split()))

def LIST()  : return list(MAP())



n = INT()

a = LIST()

b = Counter(list(accumulate(a))+[0])



ans = 0

for x in b:

    ans += b[x] * ( b[x] - 1 ) // 2



print(ans)
from math import (
    ceil,
    floor,
    factorial,
    gcd,
    sqrt,
    log2,
    cos,
    sin,
    tan,
    acos,
    asin,
    atan,
    degrees,
    radians,
    pi,
    inf,
)
from itertools import (
    accumulate,
    groupby,
    permutations,
    combinations,
    product,
    combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys

sys.setrecursionlimit(10**7)


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(MAP())


n = INT()
a = LIST()
s = accumulate(a)
d = defaultdict(int)
for x in s:
    d[x] += 1
ans = d[0]
for x in d:
    ans += d[x] * (d[x] - 1) // 2
print(ans)

from math import (
    ceil,
    floor,
    factorial,
    gcd,
    sqrt,
    log2,
    cos,
    sin,
    tan,
    acos,
    asin,
    atan,
    degrees,
    radians,
    pi,
    inf,
)
from itertools import (
    accumulate,
    groupby,
    permutations,
    combinations,
    product,
    combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys

sys.setrecursionlimit(10**7)


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(MAP())


n = INT()
a = LIST()
b = Counter(list(accumulate(a)) + [0])
ans = 0
for x in b:
    ans += b[x] * (b[x] - 1) // 2
print(ans)

-s = accumulate(a) -d = defaultdict(int) -for x in s: -    d[x] += 1 -ans = d[0] -for x in d: -    ans += d[x] * (d[x] - 1) // 2 +b = Counter(list(accumulate(a)) + [0]) +ans = 0 +for x in b: +    ans += b[x] * (b[x] - 1) // 2