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.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
 
public class Main {
	
	public static final long MOD = 1000000007;
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] as = new long[N];
			for(int i = 0; i < N; i++) { as[i] = sc.nextLong(); }
			
			long[][] x_y = new long[N + 1][N];
			for(int i = 0; i < N; i++) {
				x_y[1][i] = as[i] * (N % 2 != 0 ? 1 : -1);
			}
			
			for(int len = 2; len <= N; len++) {
				
				for(int st = 0; st + len <= N; st++) {
					final int start = st;
					final int end = st + len;
					
					final int left = st, left_other = st + 1;;
					final int right = st + len - 1, right_other = st;
					final long left_value = as[left];
					final long right_value = as[right];
					
					boolean own_turn = (N - len) % 2 == 0;
					if(own_turn) {
						final long left_x_y  = left_value  + x_y[len - 1][left_other];
						final long right_x_y = right_value + x_y[len - 1][right_other];
						
						if(left_x_y > right_x_y) {
							x_y[len][st] = left_x_y;
						}else {
							x_y[len][st] = right_x_y;
						}
					}else {
						final long left_x_y  = -left_value  + x_y[len - 1][left_other];
						final long right_x_y = -right_value + x_y[len - 1][right_other];
						
						if(left_x_y > right_x_y) {
							x_y[len][st] = right_x_y;
						}else {
							x_y[len][st] = left_x_y;
						}
					}
				}
			}
			
			//System.out.println(Arrays.deepToString(x_y));
			
			System.out.println(x_y[N][0]);
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}