use std::io::Read; use std::io::Write; fn run() { let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let mut s: Vec = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect(); s.push(0); s.reverse(); s.push(0); for i in 1..=(n + 1) { s[i] += s[i - 1]; } let mut ans = vec![std::i128::MAX; n + 1]; let mut dp = vec![std::i64::MAX as i128 ; n + 2]; dp[0] = 0; for k in 1..=n { let mut next = dp.clone(); let mut deq = std::collections::VecDeque::<(i128, i128)>::new(); deq.push_back((-2 * s[k - 1], dp[k - 1] + s[k - 1] * s[k - 1])); for i in k..=(n + 1) { let x = s[i - 1]; while deq.len() > 1 { let (a, b) = *deq.get(0).unwrap(); let (c, d) = *deq.get(1).unwrap(); if a * x + b >= c * x + d { deq.pop_front(); } else { break; } } let (a, b) = *deq.front().unwrap(); next[i] = a * x + b + x * x; let (a, b) = (-2 * s[i], dp[i] + s[i] * s[i]); while deq.len() > 1 { let len = deq.len(); let (c, d) = *deq.get(len - 1).unwrap(); let (e, f) = *deq.get(len - 2).unwrap(); if (b - d) * (e - a) <= (b - f) * (c - a) { deq.pop_back(); } else { break; } } deq.push_back((a, b)); } dp = next; ans[n + 1 - k] = dp[n + 1]; } for i in 1..=n { writeln!(out, "{}", ans[i]).ok(); } } fn main() { run(); }