#include <iostream>
#include <cstring>
using namespace std;
const int MaxInt=2147483646;
int n, Sands[101], Cost[101][101], Dp[101][101];
int Min(int a, int b) {
return a < b ? a : b;
}
int main() {
freopen("shizi.in","r",stdin);
freopen("shizi.out","w",stdout);
cin >> n;
memset(Sands, 0, sizeof(Sands));
memset(Cost, 0, sizeof(Cost));
for (int i = 0; i < n; i++) cin >> Sands[i];
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++)
for (int k = i; k <= j; k++)
Cost[i][j] += Sands[k];
for (int t = 1; t < n; t++) {
for (int i = 0; i < n; i++) {
int j = i + t;
Dp[i][j] = MaxInt;
for (int k = i; k < j; k++) {
Dp[i][j] = Min(Dp[i][k] + Dp[k + 1][j] + Cost[i][j], Dp[i][j]);
}
}
}
cout << Dp[0][n - 1] << endl;
return (0);
}