def find_single_set(A):
    if(len(A)<=1):
        return 0
    cnt = 1
    sub_sum = A[0]
    for a in A[1:]:
        sub_sum += a
        cnt += 1
        if sub_sum == 0:
            return cnt
    return 0

def find_serial(A):
    if(len(A) < 2):
        return []
    ret = 0
    posi = 0
    serial = []
    while True:
        ret = find_single_set(A[posi:])
        if ret == 0:
            break
        serial += [[posi, ret]]
        posi += ret
    return serial


N = int(input())
A = list(map(int, input().split()))

B = [0 for i in range(len(A))]
cnt = 0
for j in range(len(A)):
    if B[j] == 0:
        serial = find_serial(A[j:])
        if len(serial) > 0:
            sub_cnt = 0
            for s in serial:
                posi = j + s[0]
                B[posi] = 1
                sub_cnt += 1
            cnt += int(round((sub_cnt + 1)*sub_cnt/2))
        B[j] = 1
print(cnt)