use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let n = stdin.lock().gets().parse::<usize>().unwrap();
    let a = stdin.lock().gets().split(' ').take(n)
        .map(|x| x.parse::<i64>().unwrap()).collect::<Vec<_>>();
    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = acc[i] + a[i];
    }
    acc.sort();
    acc.push(std::i64::MAX);	// sentinel
    let mut prev = std::i64::MAX;
    let mut count = 0u32;
    let mut ans = 0;
    for x in acc {
        if x == prev {
            count += 1;
        } else {
            if count >= 2 {
                ans += count * (count - 1) / 2;
            }
            count = 1;
        }
        prev = x;
    }
    println!("{}", ans);
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }
