var q = require("fs").readFileSync("/dev/stdin", "utf8").split(/\s+/).filter(x => x.length);
q.shift();
var a = q.map(x => +x);
// imos' method
for (var i = 1, l = a.length; i < l; i++)
    a[i] += a[i-1];
a.unshift(0);
// sort & count
a.sort((a, b) => a - b);
var j = 0, sum = 0;
for (var i = 1, l = a.length; i <= l; i++) {
    if (i === l || a[j] !== a[i]) {
        sum += (i - j) * (i - j - 1);
    }
}
console.log(sum / 2);