import java.util.ArrayDeque; import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int add=1; long[] A = new long[N + add]; long[] S = new long[N + add]; long[] a = new long[N + add]; long[][] b = new long[N + add][N + add]; for (int i = 0; i < N; ++i) { A[i] = sc.nextLong(); } for(int i=0;i 0 ? S[i - 1] : 0); a[i] = -2 * S[i]; } for(int i=0;i 0 ? S[i - 1] * S[i - 1] : 0); } long[][] dp = new long[N][N]; for (int i = 0; i < dp.length; ++i) { for (int j = 0; j < dp[i].length; ++j) { if (j == 0) { dp[i][j] = (i > 0 ? S[i - 1] * S[i - 1] : 0); } else { dp[i][j] = Long.MAX_VALUE / 3; } } } for (int D = 0; D < N; ++D) { long[] dq_a = new long[N]; long[] dq_b = new long[N]; Arrays.fill(dq_a, Long.MAX_VALUE / 3); Arrays.fill(dq_b, Long.MAX_VALUE / 3); int s = 0, t = 0; for (int i = 0; i < N; ++i) { int j = (i + 1) - (D + 1); if (j < 0 || j > i) continue; long dq_a0 = a[i]; long dq_b0 = b[i][D]; // -(b0-b1)/(a0-a1)<-(b2-b1)/(a2-a1) // (b0-b1)(a2-a1)<(b2-b1)(a0-a1) while (t - s >= 2 && (double)(dq_b0 - dq_b[t - 1]) * (dq_a[t - 2] - dq_a[t - 1]) <= (double)(dq_b[t - 2] - dq_b[t - 1])* (dq_a0 - dq_a[t - 1])) { --t; } dq_a[t] = dq_a0; dq_b[t] = dq_b0; ++t; while (t - s >= 2 && (double)dq_a[s] * S[i] + dq_b[s] >= (double)dq_a[s + 1] * S[i] + dq_b[s + 1]) { ++s; } if (i + 1 < N) { dp[i + 1][D + 1] = S[i] * S[i] + dq_a[s] * S[i] + dq_b[s]; if (D + 1 < N) { b[i + 1][D + 1] = S[i + 1] * S[i + 1] + dp[i + 1][D + 1]; } } } } long[] ans = new long[N + 1]; Arrays.fill(ans, Long.MAX_VALUE / 3); for (int j = 1; j <=N-add; ++j) { int D = N - 1 - j; ans[j] = Math.min(ans[j], dp[N - 1][D]); System.out.println(ans[j]); } } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }