use std::io::{Read, stdin}; use std::cmp::min; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); macro_rules! get { ($t:ty) => (get().parse::<$t>().unwrap()); () => (get!(i64)); } let n = get!(usize); let mut hito = vec![]; for _ in 0..n { hito.push(get!()); } let mut gomi_x = vec![]; for _ in 0..n { gomi_x.push(get!()); } let mut gomi_y = vec![]; for _ in 0..n { gomi_y.push(get!()); } let mut h = 0; let mut ans = 0; for i in 0..n { let x = gomi_x[i]; let y = gomi_y[i]; while h < i && h < n-1 && hito[h] < x { h += 1; } if h == 0 { if n == 1 || h+1>i { let dx = hito[h]-x; ans += dx*dx+y*y; } else { let dx = min((hito[h]-x).abs(),(hito[h+1]-x).abs()); ans += dx*dx+y*y; } } else { let dx = min((hito[h]-x).abs(),(hito[h-1]-x).abs()); ans += dx*dx+y*y; } } println!("{}", ans); }