N = int(input())
num_list = list(map(int, input().split()))
cumulative_sum_list = [0]
c_s = 0
for i in num_list:
    c_s += i
    cumulative_sum_list.append(c_s)
cumulative_sum_list.sort()
cumulative_sum_set = set(cumulative_sum_list)
cumulative_dif = [0, 0]
for idx, i in enumerate(range(1, 2 * (10 ** 5)), 2):
    cumulative_dif.append(cumulative_dif[idx - 1] + i)
s = 0
for i in cumulative_sum_set:
    s += cumulative_dif[cumulative_sum_list.count(i)]
print(s)
