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 void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        int n;
        long[][] dp;
        boolean[][] set;
        int[] a;

        private void res(int left, int right, boolean max) {
            if (left == right) return;
            if (!set[left+1][right]) res(left+1, right, !max);
            if (!set[left][right-1]) res(left, right-1, !max);
            if (max) dp[left][right] = Math.max(a[left] + dp[left+1][right], a[right] + dp[left][right-1]);
            else dp[left][right] = Math.min(-a[left] + dp[left+1][right], -a[right] + dp[left][right-1]);
            set[left][right] = true;
        }

        private void solve(InputReader inp, PrintWriter out) {
            n = inp.nextInt();
            dp = new long[n][n];
            set = new boolean[n][n];
            a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = inp.nextInt();
                set[i][i] = true;
                dp[i][i] = a[i];
                if (n % 2 == 0) dp[i][i] *= -1;
            }
            res(0, n-1, true);
            out.print(dp[0][n-1]);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

