#include <bits/stdc++.h>
using namespace std;
long long findit(long long arr[], int i, int j, long long dp[3001][3001]) {
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  if (i == j) {
    return arr[i];
  }
  if (j == i + 1) {
    return max(arr[i], arr[j]);
  }
  long long way1 =
      arr[i] + min(findit(arr, i + 2, j, dp), findit(arr, i + 1, j - 1, dp));
  long long way2 =
      arr[j] + min(findit(arr, i, j - 2, dp), findit(arr, i + 1, j - 1, dp));
  dp[i][j] = max(way1, way2);
  return dp[i][j];
}
int main() {
  int n;
  cin >> n;
  long long arr[n];
  long long dp[3001][3001];
  for (int i = 0; i < 3001; i++) {
    for (int j = 0; j < 3001; j++) {
      dp[i][j] = -1;
    }
  }
  long long total = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    total = total + arr[i];
  }
  long long maxxget = findit(arr, 0, n - 1, dp);
  long long yget = total - maxxget;
  cout << maxxget - yget;
  return 0;
}
