unittest
{
	assert( [ "6", "1 2 3 4 5 6" ].parse.expand.solve == 12 );
	assert( [ "5", "-1000 -100 -10 0 10" ].parse.expand.solve == 0 );
	assert( [ "10", "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000" ].parse.expand.solve == 5000000000 );
	assert( [ "27", "18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49" ].parse.expand.solve == 295 );
}



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

auto solve( long[] as )
{
	// 3つ以下なら一番大きい数を選ぶだけ
	if( as.length <= 3 ) return as.reduce!max;
	
	// dp[ i番目 ][ 選ばなかった要素の数 ] = 選んだ要素の和
	auto dp = new long[][]( as.length + 2, ( as.length.signed % 2 ) + 2 );
	foreach( ref dpp; dp ) dpp[] = long.min;
	dp[ 0 ][ 0 ] = 0;
	foreach( i, a; as )
	{
		foreach( j; 0 .. dp[ i ].length.signed )
		{
			if( dp[ i ][ j ] == long.min ) continue;
			
			// 選ぶ
			if( i + 2 < dp.length ) dp[ i + 2 ][ j ] = max( dp[ i + 2 ][ j ], dp[ i ][ j ] + a );
			
			// 選ばない
			if( j + 1 < dp[ i ].length ) dp[ i + 1 ][ j + 1 ] = max( dp[ i + 1 ][ j + 1 ], dp[ i ][ j ] );
		}
	}
	return dp[ $ - 1 ][ $ - 1 ];
}
