#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define X first
#define Y second
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define sd(x) scanf("%d",&(x))
#define Pi acos(-1.0)
#define sf(x) scanf("%lf",&(x))
#define ss(x) scanf("%s",(x))
#define maxn 50005
const int inf=0x3f3f3f3f;
const ll mod=1000000007;
int sum[105];
int dp[105][105];
int main()
{
#ifdef local
freopen("in","r",stdin);
//freopen("out","w",stdout);
int _time=clock();
#endif
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>sum[i];
sum[i]+=sum[i-1];
}
memset(dp,127/3,sizeof dp);
for(int i=0;i<=n;i++)
{
dp[i][i]=0;
}
for(int v=1;v<n;v++)
{
for(int i=1;i<=n-v;i++)
{
int j=i+v;
for(int k=1;k<j;k++)
{
dp[i][j]=min(dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1],dp[i][j]);
}
}
}
cout<<dp[1][n]<<endl;
#ifdef local
printf("time: %d\n",int(clock()-_time));
#endif
}