use std::collections::HashMap;
use std::io;
use std::io::{BufRead, Write};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let _n: usize = buf.trim_right().parse().unwrap();
    buf.clear();
    input.read_line(&mut buf).unwrap();
    let a: Vec<i32> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let mut acc = 0;
    let mut counts = HashMap::new();
    counts.insert(0, 1);
    for sum in a.iter().map(|&x| {
        acc += x;
        acc
    }) {
        *counts.entry(sum).or_insert(0usize) += 1;
    }
    let result: usize = counts.values().map(|x| x * (x - 1) / 2).sum();
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "6
1 3 -4 2 2 -2
",
            "3\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "7
1 -1 1 -1 1 -1 1
",
            "12\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "5
1 -2 3 -4 5
",
            "0\n",
        );
    }
}
