use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        a: [isize; n],
    }

    let mut cum = vec![0; n + 1];

    let mut acc = 0;
    for i in 0..n {
        acc += a[i];
        cum[i + 1] = acc;
    }

    let mut map = HashMap::new();
    for &c in &cum {
        let entry = map.entry(c).or_insert(0);
        *entry += 1;
    }

    let mut ans = 0;
    for (_, value) in &map {
        ans += value * (value - 1) / 2;
    }
    println!("{}", ans);
}
