#include using namespace std; struct LineFunc { mutable int64_t m, a, p; bool operator<(const LineFunc& l) const { return m < l.m; } bool operator<(int64_t x) const { return p < x; } int64_t eval(int64_t x) const { return m * x + a; } }; struct LineContainer : multiset> { const int64_t inf = numeric_limits::max(); int64_t fdiv(int64_t a, int64_t b) { return a / b - ((a ^ b) < 0 && a % b); } bool isect(iterator x, iterator y) { if (y == end()) return x->p = inf, false; if (x->m == y->m) x->p = x->a > y->a ? inf : -inf; else x->p = fdiv(y->a - x->a, x->m - y->m); return x->p >= y->p; } void add(int64_t m, int64_t a) { auto z = insert({ m, a, 0 }), y = z++, x = y; while (isect(y, z)) z = erase(z); if (x != begin() && isect(--x, y)) isect(x, y = erase(y)); while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y)); } int64_t query(int64_t x) { return lower_bound(x)->eval(x); } }; int main() { ios::sync_with_stdio(false); int N; cin >> N; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } vector ans(N, (int64_t) 1 << 60); for (int _ = 0; _ < 2; ++_) { vector pa(N + 1); for (int i = 0; i < N; ++i) { pa[i + 1] = pa[i] + A[i]; } function dvcq = [&](int lb, int rb) { if (rb - lb == 1) { ans[lb] = min(ans[lb], 1 + A[lb]); return; } int mb = lb + rb + _ >> 1; LineContainer lcn; for (int i = mb + 1; i <= rb; ++i) lcn.add(2 * i, -(pa[i] + (int64_t) i * i)); vector best(mb - lb, (int64_t) 1 << 60); for (int i = lb; i < mb; ++i) best[i - lb] = -lcn.query(i) + (int64_t) i * i - pa[i]; for (int i = 1; i < mb - lb; ++i) best[i] = min(best[i], best[i - 1]); for (int i = lb; i < mb; ++i) ans[i] = min(ans[i], best[i - lb]); dvcq(lb, mb); dvcq(mb, rb); }; dvcq(0, N); reverse(A.begin(), A.end()); reverse(ans.begin(), ans.end()); } for (int i = 0; i < N; ++i) cout << ans[i] << endl; return 0; }