#include #define rep1(n) for(int i = 0; i < (int)n; i++) #define rep2(i, n) for(int i = 0; i < (int)n; i++) #define rep3(i, l, r) for(int i = (int)l; i < (int)r; i++) #define overloadrep(a, b, c, x, ...) x #define rep(...) overloadrep(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(i, n) for(int i = (n)-1; i >= 0; i--) #define rrep3(i, l, r) for(int i = (r)-1; i >= l; i--) #define all(v) v.begin(), v.end() #define si(v) (int)v.size() using namespace std; template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using vi = vector; using vl = vector; using pll = pair; const int iinf = 1e9 + 10; const ll linf = 1e18 + 100; template struct CHT { #define x first #define y second CHT() = default; deque v; bool empty() { return v.empty(); } void clear() { return v.clear(); } inline int sgn(ll x) { return !x ? 0 : (x < 0 ? -1 : 1); } using D = long double; inline bool check(const pll& a, const pll& b, const pll& c) { if(b.y == a.y or c.y == b.y) return sgn(b.x - a.x) * sgn(c.y - b.y) >= sgn(c.x - b.x) * sgn(b.y - a.y); return D(b.x - a.x) * sgn(c.y - b.y) / D(abs(b.y - a.y)) >= D(c.x - b.x) * sgn(b.y - a.y) / D(abs(c.y - b.y)); } void add(ll a, ll b) { if(!isMin) a *= -1, b *= -1; pll line(a, b); if(empty()) v.emplace_front(line); else { if(ll c = v[0].x; c <= a) { if(c == a) { if(v[0].y <= b) return; v.pop_front(); } while(si(v) >= 2 and check(line, v[0], v[1])) v.pop_front(); v.emplace_front(line); } else { assert(a <= v.back().x); if(v.back().x == a) { if(v.back().y <= b) return; v.pop_back(); } while(si(v) >= 2 and check(v[si(v) - 2], v.back(), line)) v.pop_back(); v.emplace_back(line); } } } ll get_y(const pll& a, const ll& x) { return a.x * x + a.y; } ll query(ll x) { assert(!empty()); int l = -1, r = si(v) - 1; while(l + 1 < r) { int m = (l + r) >> 1; if(get_y(v[m], x) >= get_y(v[m + 1], x)) l = m; else r = m; } return get_y(v[r], x) * (isMin ? 1 : -1); } ll query_monotone_inc(ll x) { assert(!empty()); while(si(v) >= 2 and get_y(v[0], x) >= get_y(v[1], x)) v.pop_front(); return get_y(v[0], x) * (isMin ? 1 : -1); } ll query_monotone_dec(ll x) { assert(!empty()); while(si(v) >= 2 and get_y(v.back(), x) >= get_y(v.end()[-2], x)) v.pop_back(); return get_y(v.back(), x) * (isMin ? 1 : -1); } #undef x #undef y }; void solve() { int n;cin >> n; vector a(n);rep(i, n)cin >> a[i]; vector b(n+1); rep(i, n)b[i+1] = b[i] + a[i]; vector ans(n, linf); auto dfs = [&](auto self, int l, int r) -> void { if (r - l == 1) { chmin(ans[l], a[l] + 1); return; } // cout << l << " " << r << endl; int m = (l + r) / 2; CHT cht; rep(i, m, r) { cht.add(-2 * (i+1), b[i+1] + ((ll)(i+1)*(i+1))); } ll res = linf; rep(i, l, m) { chmin(res, cht.query_monotone_inc(i) + ((ll)i * i) - b[i]); chmin(ans[i], res); } cht.clear(); rep(i, l, m) { cht.add(-2 * i, -b[i] + ((ll)i * i)); } res = linf; rrep3(i, m, r) { chmin(res, cht.query_monotone_dec(i+1) + ((ll)(i+1)*(i+1)) + b[i+1]); chmin(ans[i], res); } // rep(i, l, r) { // if (i > l) cout << " "; // cout << ans[i]; // } // cout << endl; self(self, l, m); self(self, m, r); }; dfs(dfs, 0, n); rep(i, n) { cout << ans[i] << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // int T;cin >> T; while(T--) { solve(); } }