#include <bits/stdc++.h>
using namespace std;
long long int dp[3003][3003];
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int l = n - 1; l >= 0; l--) {
    for (long long int r = l; r < n; r++) {
      if (l == r)
        dp[l][r] = a[l];
      else {
        dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
}
int main() {
  long long int T = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (T--) solve();
  return 0;
}
