unittest
{
	assert( [ "3", "1 2 3" ].parse.expand.solve == 0 );
	assert( [ "4", "1 3 1 1" ].parse.expand.solve == 2 );
	assert( [ "8", "27 23 76 2 3 5 62 52" ].parse.expand.solve == 2 );
}



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 ws = input.front.split.to!( long[] );
	return tuple( ws );
}

auto solve( long[] ws )
{
	auto ans = long.max;
	auto wl = 0L;
	auto wg = ws.sum;
	for( auto i = 0L; i < ws.length; i++ )
	{
		wl += ws[ i ];
		wg -= ws[ i ];
		ans = min( ans, abs( wl - wg ) );
	}
	return ans;
}
