unittest
{
	assert( [ "3", "2 4 3" ].parse.expand.solve == 3 );
	assert( [ "12", "100 104 102 105 103 103 101 105 104 102 104 101" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.math;
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 l = 0L;
	auto r = as.sum;
	auto ans = r - l;
	foreach( a; as )
	{
		l += a;
		r -= a;
		ans = min( ans, abs( r - l ) );
	}
	return ans;
}
