#include <iostream>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
const int N = 310; // O(n^3)
int n;
int s[N], a[N], f[N][N];
void solve(){
memset(f, 0x3f, sizeof(f));
cin >> n;
for (int i = 1; i <=n; ++i) {
cin >> a[i];
s[i] = s[i-1] + s[i];
f[i][i] = 0;
}
for (int len = 2; len <= n; ++len)
for (int l = 1; len+l-1 <= n; ++l)
{
int r = len+l-1;
for (int k = l; k < r; k++){
f[l][r] = min(f[l][r], f[l][k]+f[k+1][r]+s[r]-s[l-1]);
}
}
cout << f[1][n];
}
int main()
{
ios;
solve();
}
09-03