#[allow(unused_imports)] use proconio::{ input, marker::{Bytes, Chars, Usize1}, }; const C: i64 = 100_000 * 30 + 10; fn main() { input! { n: usize, a: [i64; n], } let mut res = n * (n + 1) / 2; for x in 1..=30 { let mut b = vec![0; n + 1]; for i in 0..n { b[i + 1] = b[i] + (a[i] - x); } let mut cnt1 = vec![0; (C * 2) as usize]; let mut cnt2 = vec![0; (C * 2) as usize]; for i in 0..=n { if i > 0 { if a[i - 1] == x { res -= cnt1[(b[i] + C) as usize]; } res -= cnt2[(b[i] + C) as usize]; } if i < n { if a[i] == x { cnt2[(b[i] + C) as usize] += 1; } else { cnt1[(b[i] + C) as usize] += 1; } } } } println!("{}", res + 1); }