unittest
{
	assert( [ "3", "10 10", "20 20", "30 30" ].parse.expand.solve == 20 );
	assert( [ "3", "20 10", "20 20", "20 30" ].parse.expand.solve == 20 );
	assert( [ "6", "1 1000000000", "1 1000000000", "1 1000000000", "1 1000000000", "1 1000000000", "1 1000000000" ].parse.expand.solve == -2999999997 );

	assert( [ "3", "20 10", "20 20", "10 30" ].parse.expand.solve == 10 );		// 追加ケース
	assert( [ "3", "20 10", "20 20", "10 40" ].parse.expand.solve == 10 );		// 追加ケース
	assert( [ "3", "20 10", "30 20", "10 40" ].parse.expand.solve == 10 );		// 追加ケース
}



import std.algorithm;
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 ) )
{
	auto n = input.front.to!( long );
	auto abs = new long[ 2 ][ n ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( abs );
}

auto solve( long[ 2 ][] abs )
{
	auto anss = [ 0L, 0L ];
	auto t = 0L;
	foreach( c; abs.map!( x => x ~ ( x[ 0 ] + x[ 1 ] ) ).array.sort!( ( x, y ) => y[ 2 ] < x[ 2 ] ) )
	{
		anss[ t ] += c[ t ];
		t = ( t + 1 ) % anss.length;
	}
	return anss[ 0 ] - anss[ 1 ];
}
