#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define rep2(i, l, r) for (int i = (l); i < (r); i++) #define repr2(i, l, r) for (int i = (r) - 1; i >= (l); i--) #define range(a) a.begin(), a.end() using namespace std; using ll = long long; struct point { ll x, y; point(ll x_ = 0, ll y_ = 0) : x(x_), y(y_) {} friend point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y); } friend bool operator<(point a, point b) { return a.x != b.x ? a.x < b.x : a.y < b.y; } }; ll cross(point a, point b) { return a.x * b.y - a.y * b.x; } vector lower_hull(vector ps) { const int n = ps.size(); sort(ps.begin(), ps.end()); vector a; rep(i, ps.size()) { while (a.size() >= 2 && cross(a.back() - a.rbegin()[1], ps[i] - a.back()) <= 0) a.pop_back(); a.push_back(ps[i]); } return a; } ll eval(point a, ll x) { return a.x * x + a.y; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); // ----- i ----- // l r // (r-l)^2 + s[r] - s[l] // r^2 + l^2 - 2*l*r + s[r] - s[l] // (r^2+s[r]) + (l^2 - s[l]) - 2*l*r // int N; cin >> N; vector A(N); rep(i, N) cin >> A[i]; vector S(N + 1); rep(i, N) S[i + 1] = S[i] + A[i]; vector ans(N, 1e18); auto dfs = [&](auto dfs, int l, int r) -> void { if (r - l == 1) { ans[l] = min(ans[l], A[l] + 1); return; } int m = (l + r) / 2; dfs(dfs, l, m); dfs(dfs, m, r); vector L, R; rep2(i, l, m + 1) L.emplace_back(i, (ll)i*i - S[i]); rep2(i, m, r + 1) R.emplace_back(i, (ll)i*i + S[i]); L = lower_hull(L); R = lower_hull(R); ll mn = 1e18; int k = 0; rep2(i, l, m) { while (k + 1 < R.size() && eval(R[k], -2*i) >= eval(R[k + 1], -2*i)) k++; mn = min(mn, eval(R[k], -2*i) + ((ll)i*i - S[i])); ans[i] = min(ans[i], mn); } k = L.size() - 1; mn = 1e18; repr2(i, m+1, r+1) { while (k - 1 >= 0 && eval(L[k], -2*i) >= eval(L[k - 1], -2*i)) k--; mn = min(mn, eval(L[k], -2*i) + ((ll)i*i + S[i])); ans[i - 1] = min(ans[i - 1], mn); } }; dfs(dfs, 0, N); rep(i, N) cout << ans[i] << '\n'; }