# coding : utf-8

import numpy as np

N = int(input())

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


count = 0

dist = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
	suml = A[i]
	for j in range(i+1,N):
		suml += A[j]
		if suml == 0:
			#    t  s
			dist[j][i] = 1 + max(dist[i-1])
			break

count = sum([sum(i) for i in dist])


print(count)