use std::io::Read; fn run() { 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 a: Vec = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect(); let x: Vec = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect(); let y: Vec = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect(); let mut dp = vec![0; n]; let mut deq = std::collections::VecDeque::<(i64, i64)>::new(); dp[0] = y[0] * y[0] + (a[0] - x[0]) * (a[0] - x[0]); deq.push_back((-2 * x[0], y[0] * y[0] + x[0] * x[0])); for i in 1..n { let (a, x, y) = (a[i], x[i], y[i]); let (p, q) = (-2 * x, dp[i - 1] + y * y + x * x); let (c, d) = *deq.back().unwrap(); if p < c || (p == c && q < d ) { if p == c { deq.pop_back(); } while deq.len() >= 2 { let len = deq.len(); let (c, d) = *deq.get(len - 1).unwrap(); let (e, f) = *deq.get(len - 2).unwrap(); if (e - p) * (q - d) <= (c - p) * (q - f) { deq.pop_back(); } else { break; } } deq.push_back((p, q)); } while deq.len() >= 2 { let (c, d) = *deq.get(0).unwrap(); let (e, f) = *deq.get(1).unwrap(); if c * a + d >= e * a + f { deq.pop_front(); } else { break; } } let (c, d) = *deq.front().unwrap(); dp[i] = c * a + d + a * a; } let ans = dp[n - 1]; println!("{}", ans); } fn main() { run(); }