#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() struct CHT { struct point { long long x, y; point(long long x_ = 0, long long y_ = 0) : x(x_), y(y_) {} friend point operator-(point a, point b) { a.x -= b.x; a.y -= b.y; return a; } }; long long cross(point a, point b) { return a.x * b.y - a.y * b.x; } deque H; long long eval(point a, long long x) { return a.x * x + a.y; } void push(long long x, long long y) { point p(x, y); while (H.size() >= 2 && cross(H[H.size() - 1] - H[H.size() - 2], p - H[H.size() - 1]) >= 0) { H.pop_back(); } H.push_back(p); } long long maximum(long long x) { if (H.empty()) return -1e18; while (H.size() >= 2 && eval(H[0], x) <= eval(H[1], x)) H.pop_front(); return eval(H[0], x); } }; int main() { int N; cin >> N; vector A(N + 1); rep(i, N) cin >> A[i]; vector S(N + 2); rep(i, N + 1) S[i + 1] = S[i] + A[i]; vector> dp(N + 2, vector(N + 2, 1e18)); dp[0][0] = 0; vector cht(N + 2); constexpr ll inf = 1e18; cht[0].push(0, 0); for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { ll v = -cht[j].maximum(S[i]); if (v == inf) continue; dp[i + 1][j + 1] = v + S[i] * S[i]; cht[j + 1].push(2*S[i+1], -dp[i+1][j+1] - S[i+1]*S[i+1]); } } for (int i = N; i >= 1; i--) { cout << dp[N+1][i] << endl; } }