#include using namespace std; using ll = long long int; ll N; vector A(4000),R(4000,0); vector> DP(4000,vector(4000,1e18)); void solve(ll l,ll r,ll L,ll RR,ll t){ if(l >= r) return; ll m = (l + r) / 2; ll ans = 1e18,idx = -1; for(ll n = L;n < min(m + 1,RR);n++){ if(ans > DP[n][t] + (R[m-1] - R[n]) * (R[m-1] - R[n])){ ans = DP[n][t] + (R[m-1] - R[n]) * (R[m-1] - R[n]); idx = n; } } DP[m][t + 1] = ans; solve(l,m,L,idx + 1,t); solve(m + 1,r,idx,RR,t); } int main(){ cin >> N; for(ll i = 0;i < N;i++){ cin >> A[i]; R[i + 1] = R[i] + A[i]; } for(ll i = 0;i <= N;i++){ DP[0][i] = 0; solve(1,N + 2,0,N + 2,i); /*for(ll j = 0;j <= N;j++){ cout << DP[j][i] << " "; } cout << endl;*/ } for(ll i = 1;i <= N;i++){ cout << DP[N + 1][N - i + 1] << endl; } }