unittest
{
	assert( [ "6", "1 3 -4 2 2 -2" ].parse.expand.solve == 3 );
	assert( [ "7", "1 -1 1 -1 1 -1 1" ].parse.expand.solve == 12 );
	assert( [ "5", "1 -2 3 -4 5" ].parse.expand.solve == 0 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	auto t = 0L;
	long[ long ] cs;
	foreach( i, a; as )
	{
		// as[ 0 .. i ].sum を計算
		t += a;
		
		// as[ 0 .. i ].sum == 0 だったら答えに加算
		ans += ( t == 0 );
		
		// as[ 0 .. i ].sum - as[ 0 .. k ].sum == 0 ( k < i ) だったら答えに加算
		if( t in cs ) ans += cs[ t ];
		
		// as[ 0 .. k ].sum の個数を加算
		cs[ t ]++;
	}
	return ans;
}
