import numpy as np
import pandas as pd

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

def get_sum0_subsets(x):
    x = np.array(x)
    tmp = pd.value_counts(x.cumsum())
    tmp = tmp[tmp > 1]
    return np.sum([np.sum(np.arange(x)) for x in tmp])

print(get_sum0_subsets(a))