#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
#define maxn 100 + 10
#define ll long long
#define INF 1000000000
#define FOR(i, a, b) for(int i = a; i < b; ++i)
using namespace std;
bool vis[maxn][maxn];
int a[maxn], sum[maxn], d[maxn][maxn];
int dp(int i, int j)
{
if(vis[i][j]) return d[i][j];
vis[i][j] = true;
int m = 0;
FOR(k, i+1, j+1) m = min(m, dp(k, j));
FOR(k, i, j) m = min(m, dp(i, k));
d[i][j] = sum[j] - sum[i-1] - m;
return d[i][j];
}
int main()
{
int n;
while(scanf("%d", &n), n)
{
sum[0] = 0;
FOR(i, 1, n+1) {scanf("%d", &a[i]);sum[i] = sum[i-1] + a[i];}
memset(vis, false, sizeof(vis));
printf("%d\n", 2*dp(1, n) - sum[n]);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
#define maxn 100 + 10
#define ll long long
#define INF 1000000000
#define FOR(i, a, b) for(int i = a; i < b; ++i)
using namespace std;
int g[maxn][maxn], f[maxn][maxn], d[maxn][maxn], a[maxn], sum[maxn];
int main()
{
int n;
while(scanf("%d", &n), n)
{
sum[0] = 0;
FOR(i, 1, n+1) {scanf("%d", &a[i]);sum[i] = sum[i-1] + a[i];}
FOR(i, 1, n+1) f[i][i] = g[i][i] = d[i][i] = a[i];
FOR(l, 1, n) for(int i = 1; i + l <= n; ++i){
int j = i+l;
int m = 0;
m = min(m, f[i+1][j]);
m = min(m, g[i][j-1]);
d[i][j] = sum[j] - sum[i-1] - m;
f[i][j] = min(d[i][j], f[i+1][j]);
g[i][j] = min(d[i][j], g[i][j-1]);
}
printf("%d\n", 2*d[1][n] - sum[n]);
}
return 0;
}