#zero_sum slow
import sys

N = int(input())
A =  list(map(int,input().split()))

res = 0
s = 0
s_list = [[0,0]]
i = 0
while i < N:
    s += A[i]
    inside = True
    j = 0
    while j < len(s_list):
        if s == s_list[j][1]:
            temp = s_list[j][0]
            s_list[j][0] += 1
            res -= temp * (temp + 1) / 2.
            res += (temp + 1) * (temp + 2) / 2.
            inside = False
            j = len(s_list) + 1
        j += 1
    if inside:
        s_list.append([0,s])
    i += 1
    
print(int(res))