n = int(input())

a = list(map(int, input().split()))

count = 0
zero = [[]]
zerocount = 0

for i in range(n):
    sum = 0
    #print(len(zero)-1)
    if zero[len(zero)-1] == i:
        count += len(zero)
        zero.pop()
    else:
        for j in range(i,n):
            sum += a[j]
            if sum == 0:
                count += 1
                flag = 1
                zero[zerocount].append(j)

        if flag == 1:
            zero[zerocount].reverse()
            zero[zerocount].pop()
            zero.append([])
            zerocount += 1
            flag = 0


#print(zero)
print(count)
