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

void main()
{
readln;
auto xs = readln.chomp.split.to!(ulong[]);
ulong sum;
auto sums = [sum];
foreach (x; xs)
    sums ~= (sum += x);
sum = 0;
foreach (g; sums.sort)
    sum += g[1]*(g[1]-1)/2;
sum.writeln;
}