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.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    public static boolean[][] use1, use2;
    public static long[][] dp1, dp2;
    public static int[] a;
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        a = in.ni(n);
        dp1 = new long[n][n];
        dp2 = new long[n][n];
        use1 = new boolean[n][n];
        use2 = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            dp1[i][i] = a[i];
            dp2[i][i] = -a[i];
            use1[i][i] = true;
            use2[i][i] = true;
        }
        out.println(dfs(0, n-1, true));
    }
    public static long dfs(int i, int j, boolean first){
        if(first){
            if(!use1[i][j]){
                long val1 = a[i]+dfs(i+1,j, false);
                long val2 = a[j]+dfs(i,j-1, false);
                dp1[i][j] = Math.max(val1, val2);
                use1[i][j] = true;
            }
            return dp1[i][j];
        }else{
            if(!use2[i][j]){
                long val1 = dfs(i+1,j, true)-a[i];
                long val2 = dfs(i,j-1, true)-a[j];
                dp2[i][j] = Math.min(val1, val2);
                use2[i][j] = true;
            }
            return dp2[i][j];
        }
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}