#include #pragma GCC optimize("unroll-loops") #define ull unsigned long long using namespace std; const int MAX_N = 3005; ull sm[MAX_N], dp[2][MAX_N], ans[MAX_N]; int pos[2][MAX_N]; #define getchar getchar_unlocked #define putchar putchar_unlocked inline int in() { int n = 0; short c; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } inline void out(ull n) { short res[20], i = 0; do { res[i++] = n % 10, n /= 10; } while (n); while (i) putchar(res[--i] + '0'); putchar('\n'); } int main() { int i, j, k, n = in(); ull res; for(i = 0; i < n; ++i) sm[i+1] = sm[i] + in(); for(i = 0; i < n+1; ++i) dp[0][i] = (1LL << 60); for(j = 1; j <= n; ++j){ auto dp1 = dp[(j+1)&1]; auto dp2 = dp[j&1]; auto pos1 = pos[(j+1)&1]; auto pos2 = pos[j&1]; for(i = j; i <= n; ++i) dp2[i+1] = (1LL << 60); dp1[j-1] = 0, pos2[n+2] = n; for(i = n; i >= j; --i){ for(k = pos1[i+1]; k <= pos2[i+2]; ++k){ res = dp1[k] + (sm[i] - sm[k]) * (sm[i] - sm[k]); if(dp2[i+1] > res) dp2[i+1] = res, pos2[i+1] = k; } } ans[n-j] = dp2[n+1]; } for(i = 0; i < n; ++i) out(ans[i]); return 0; }