import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum INF = 10L^^18; enum W = 100; int N; long[] A; long[] ASum; long[] ans; /* ((j - i)^2 + (ASum[j] - ASum[i])) = (i^2 - ASum[i]) + min_j ((j^2 + ASum[j]) + (-2 j) i) = (j^2 + ASum[j]) + min_i ((i^2 - ASum[i]) + (2 i) (-j)) */ void solve(int l, int r) { if (l >= r) { return; } // l <= i <= mid, mid + 1 <= j <= r const mid = (l + r) / 2; solve(l, mid); solve(mid + 1, r); // [1]: decreasing auto q = new Tuple!(long, long)[mid - l + 1]; int qb, qe; long mn; qb = qe = 0; foreach (j; mid + 1 .. r + 1) { const t = tuple(1L * j * j + ASum[j], -2L * j); for (; qe - qb >= 2 && (q[qe - 1][0] - q[qe - 2][0]) * -(t[1] - q[qe - 2][1]) >= (t[0] - q[qe - 2][0]) * -(q[qe - 1][1] - q[qe - 0][1]); --qe) {} q[qe++] = t; } mn = INF; foreach (i; l .. mid + 1) { for (; qe - qb >= 2 && (q[qb][0] + q[qb][1] * i >= q[qb + 1][0] + q[qb + 1][1] * i); ++qb) {} const tmp = 1L * i * i - ASum[i] + (q[qb][0] + q[qb][1] * i); debug { writefln("i = %s, mid = %s, r = %s: %s", i, mid, r, tmp); } chmin(mn, tmp); chmin(ans[i], mn); } qb = qe = 0; foreach (i; l .. mid + 1) { const t = tuple(1L * i * i - ASum[i], 2L * i); for (; qe - qb >= 2 && (q[qe - 1][0] - q[qe - 2][0]) * -(t[1] - q[qe - 2][1]) >= (t[0] - q[qe - 2][0]) * -(q[qe - 1][1] - q[qe - 0][1]); --qe) {} q[qe++] = t; } mn = INF; foreach_reverse (j; mid + 1 .. r + 1) { for (; qe - qb >= 2 && (q[qb][0] + q[qb][1] * (-j) >= q[qb + 1][0] + q[qb + 1][1] * (-j)); ++qb) {} const tmp = 1L * j * j + ASum[j] + (q[qb][0] + q[qb][1] * (-j)); chmin(mn, tmp); chmin(ans[j - 1], mn); } } void main() { try { for (; ; ) { N = readInt(); A = new long[N]; foreach (i; 0 .. N) { A[i] = readLong(); } ASum = new long[N + 1]; foreach (i; 0 .. N) { ASum[i + 1] = ASum[i] + A[i]; } ans = new long[N]; ans[] = INF; solve(0, N); foreach (i; 0 .. N) { writeln(ans[i]); } } } catch (EOFException e) { } }