#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; int a[100+10]; int dp[120][120]; int sum[120]; int vis[120][120]; int dfs(int f,int t) { int i,j,k; if(vis[f][t]==1) return dp[f][t]; vis[f][t]=1; int minn=0; for(i=f;i<t;i++) { minn=min(minn,dfs(f,i)); } for(i=f+1;i<=t;i++) { minn=min(minn,dfs(i,t)); } dp[f][t]=sum[t]-sum[f-1]-minn; return dp[f][t]; } int main() { int n; int i,j,k; while(scanf("%d",&n),n) { sum[0]=0; memset(vis,0,sizeof(vis)); for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum[i]=sum[i-1]+a[i]; } dfs(1,n); printf("%d ",dp[1][n]-(sum[n]-dp[1][n])); } return 0; }