Taro and Jiro will play the following game against each other.

Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:

* Remove the element at the beginning or the end of a. The player earns x points, where x is the removed element.



Let X and Y be Taro's and Jiro's total score at the end of the game, respectively. Taro tries to maximize X - Y, while Jiro tries to minimize X - Y.

Assuming that the two players play optimally, find the resulting value of X - Y.

Constraints

* All values in input are integers.
* 1 \leq N \leq 3000
* 1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:


N
a_1 a_2 \ldots a_N


Output

Print the resulting value of X - Y, assuming that the two players play optimally.

Examples

Input

4
10 80 90 30


Output

10


Input

3
10 100 10


Output

-80


Input

1
10


Output

10


Input

10
1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1


Output

4999999995


Input

6
4 2 9 7 1 5


Output

2
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

/*
 * L - Deque
 */
public class Main
{
long[][] cache;

public static void main( String[] args ) throws Exception
{
	new Main().run();
}

public void run() throws Exception
{
	final Scanner sc = new Scanner( getInputStream() );
	final int N = sc.nextInt();
	cache = new long[ N ][ N ];
	long[] data = new long[ N ];
	for( int i = 0; i < N; ++i )
	{
		data[ i ] = sc.nextLong();
	}
	long sum = sum( data, 0, N - 1 );
	long x = getScore( data, 0, N -1 );
	long y = sum - x;
	/*
	p( x );
	p( y );
	p( sum );
	*/
	p( sum - 2*y );
}

public long getScore( final long[] data, int start, int end )
{
	if( start == end )
	{
		return data[ start ];
	}
	else
	{
		long cached = cache[ start ][ end ];
		if( cached != 0 )
		{
			return cached;
		}
		else
		{
			long sum = sum( data, start, end );
			long leftScore = sum - getScore( data, start + 1, end );
			long rightScore = sum - getScore( data, start, end -1 );
			
			long result = leftScore > rightScore ? leftScore : rightScore;
			cache[ start ][ end ] = result;
			return result;
		}
	}
}

public static long sum( long[] data, int start, int end )
{
	long sum = 0;
	for( int i = start; i <= end; ++i )
	{
		sum += data[ i ];
	}
	return sum;
}

public static void p( Object o )
{
	System.out.println( o );
}

public static InputStream getInputStream() throws IOException
{
	//p( System.getProperties() );
	if( System.getProperty( "test" ) != null )
	{
		return new FileInputStream( "1" );
	}
	else
	{
		return System.in;
	}
}

}
