use std::io::Read;
use std::collections::HashMap;

pub fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut ary: Vec<i64> = vec![0;n];
    for i in 0..n {
        ary[i] = iter.next().unwrap().parse().unwrap();
    }
    let mut csum: Vec<i64> = vec![0;n + 1];
    for i in 0..n {
        csum[i+1] = csum[i] + ary[i];
    }

    // println!("{:?}", csum);

    let mut ret: i64 = 0;
    let mut hmap: HashMap<i64, i64> = HashMap::new();
    for c in csum {
        hmap.insert(c, (&hmap).get(&c).unwrap_or(&0) + 1);
    }
    for (_, v) in hmap {
        if v >= 2 {
            ret += v * (v - 1) / 2;
        }
    }
    println!("{}", ret);
}
