#include<bits/stdc++.h>
using namespace std;
const int N=310;
int f[N][N];
int s[N];
int main()
{
memset(f,0x3f3f,sizeof(f));
int n,i,j,k,len;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>s[i];
s[i]+=s[i-1];
f[i][i]=0;
}
for(len=2;len<=n;len++)
{
for(i=1;i+len-1<=n;i++)
{
j=i+len-1;
for(k=1;k<=j-1;k++)
f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+s[j]-s[i-1]);
}
}
cout<<f[1][n]<<endl;
}