#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
const int mod=1e9+7;
ll dp[3001][3001];

int solve(vector<ll>a,int i,int j){
	if(i>j || i>=n || j<0) return 0;
	if(dp[i][j]!=-1) return dp[i][j];
	ll x=0;
	x+=max(a[i]+min(solve(a,i+1,j-1),solve(a,i+2,j)),
		   a[j]+min(solve(a,i+1,j-1),solve(a,i,j-2)));
	return dp[i][j]=x;
}

int main(){
	ll n;
	cin>>n;
	vector<ll>a(n);
	ll sum=0;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++) {
		cin>>a[i];
		sum+=a[i];
	}
	cout<<2*solve(a,0,n-1)-sum<<endl;
	return 0;
}