n = int(input())

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

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

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

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

        if flag == 1:
            zero[zerocount].reverse()
            #print("zreo追加 = ",zero)
            zero.append([])
            zerocount += 1
            flag = 0


#print(zero)
print(count)
