import math

N = int(input())
A = [int(x) for x in input().split()]

A_accum = A[:]
for i in range(1, N):
    A_accum[i] = A[i] + A_accum[i-1]

int_dict = {0:1}
for a in A_accum:
    if not a in int_dict.keys():
        int_dict[a] = 1
    else:
        int_dict[a] += 1

cnt = 0
for v in int_dict.values():
    if v >= 2:
        cnt += math.factorial(v-1)
print(cnt)
