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![0; n + 1]; let mut dp = vec![3000 * 3000 * 100_000i64 + 1; n + 2]; let mut next = dp.clone(); let mut deq = std::collections::VecDeque::<(i64, i64)>::new(); dp[0] = 0; for k in 1..=n { deq.clear(); 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) as f64 * (e - a) as f64 <= (b - f) as f64 * (c - a) as f64 { deq.pop_back(); } else { break; } } deq.push_back((a, b)); } dp.clone_from(&next); ans[n + 1 - k] = dp[n + 1]; } for i in 1..=n { writeln!(out, "{}", ans[i]).ok(); } } fn main() { run(); }