RT,WA20分
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 205;
const int inf = 0x3f3f3f3f;
int n, mn, mx, dp_max[N][N], dp_min[N][N], a[N], pre[N];
int main() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i + n] = a[i];
pre[i] = pre[i - 1] + a[i];
}
for(int i = n + 1; i <= (n << 1); i++) pre[i] = pre[i - 1] + a[i];
for(int k = 1; k < n; k++)
for(int i = 1, j = 1 + k; j < (n << 1); i++, j++) {
dp_min[i][j] = inf;
for(int p = i; p < j; p++) {
dp_max[i][j] = max(dp_max[i][j], dp_max[i][p] + dp_max[p + 1][j] + pre[j] - pre[i - 1]);
dp_min[i][j] = min(dp_min[i][j], dp_min[i][p] + dp_min[p + 1][j] + pre[j] - pre[i - 1]);
}
}
for(int i = 1; i <= n; i++) {
mx = max(mx, dp_max[i][i + n - 1]);
mn = min(mx, dp_min[i][i + n - 1]);
}
cout << mn << endl << mx << endl;
return 0;
}