"use strict";
function Main(input) {
    let lines = input.split("\n");
    const N = lines.shift().split(/\s/).map((v) => v - 0)[0];
    const a = lines.shift().split(/\s/).map((v) => v - 0);

    // 累積和と連想配列
    let s = new Array(N+1).fill(0);
    let nums = {};
    for (let i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
    for (let i = 0; i < N+1; ++i) {
        let num = nums[s[i]] || 0;
        nums[s[i]] = ++num;
    }

    // 集計処理
    let res = 0;
    for (let it in nums) {
        let num = nums[it];
        res += (num * (num - 1) / 2);
    }
    console.log(res);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));