import std.stdio, std.conv, std.math, std.string, std.range, std.array,
       std.algorithm;

void main(){
    auto buf = readln().strip().split().map!(to!int)();
    immutable N = buf[0];

    auto a = readln().strip().split().map!(to!int)();

    long[long] m;
    long ans;
    long shift;

    foreach(ea; a) {
        shift += ea;
        m[ea-shift] += 1;
        ans += m.get(-shift, 0);
    }

    writeln(ans);
}
