#include <bits/stdc++.h>
using namespace std;
long long N;
long long a[101010];
long long rec(long long l, long long r, long long turn) {
  if (l == r)
    return 0;
  else if (turn == 0)
    return ((rec(l + 1, r, 1) + a[l]) > (rec(l, r - 1, 1) + a[r - 1])
                ? (rec(l + 1, r, 1) + a[l])
                : (rec(l, r - 1, 1) + a[r - 1]));
  else
    return ((rec(l + 1, r, 0) - a[l]) < (rec(l, r - 1, 0) - a[r - 1])
                ? (rec(l + 1, r, 0) - a[l])
                : (rec(l, r - 1, 0) - a[r - 1]));
}
int main(void) {
  cin >> N;
  long long i;
  for (i = 0; i < N; i++) cin >> a[i];
  cout << rec(0, N, 0) << "\n";
}
