#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
using namespace std;
int f[201][201],dp[201][201];
int a[201],n,m;
int main()
{
int i,j,k;
while(scanf("%d",&n)!=EOF)
{
if(n==0)break;
memset(f,0,sizeof(f));
memset(dp,127/3,sizeof(dp));
for(i=1; i<=n; i++)
scanf("%d",&a[i]);
for(i=1; i<=n; i++)a[i+n]=a[i];
m=n;
n*=2;
for(i=1; i<=n; i++)
{
f[i][i]=0;
dp[i][i]=0;
}
for(i=1; i<=n-1; i++)
{
f[i][i+1]=a[i]+a[i+1];
dp[i][i+1]=a[i]+a[i+1];
}
for(i=2; i<=n; i++)a[i]=a[i-1]+a[i];
for(i=3; i<=n; i++)
{
for(j=1; j<=n-i+1; j++)
{
for(k=j+1; k<=j+i-1; k++)
{
f[j][j+i-1]=max(f[j][j+i-1],f[j][k-1]+f[k][j+i-1]+a[j+i-1]-a[j-1]);
}
}
}
for(i=3; i<=n; i++)
{
for(j=1; j<=n-i+1; j++)
{
for(k=j+1; k<=j+i-1; k++)
{
dp[j][j+i-1]=min(dp[j][j+i-1],dp[j][k-1]+dp[k][j+i-1]+a[j+i-1]-a[j-1]);
}
}
}
int mmax=0,mmin=2000000000;
for(i=1;i<=m;i++)
{
mmax=max(mmax,f[i][i+m-1]);
mmin=min(mmin,dp[i][i+m-1]);
}
cout<<mmin<<‘ ‘<<mmax<<endl;
}
}