fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); let b: Vec = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut pairs = (0..n).map(|i| (a[i], b[i])).collect::>(); pairs.sort(); let mut resx = pairs[0].0; let bsum = b.iter().sum::(); let mut bleft = pairs[0].1; let mut result = pairs.iter().skip(1).map(|&(l, r)| (l - resx).abs() * r).sum::(); let mut summary = result; for i in 1..n { let (px, _) = pairs[i-1]; let (x, bval) = pairs[i]; summary += (x - px) * bleft; summary -= (x - px) * (bsum - bleft); if result > summary { result = summary; resx = x; } bleft += bval; } println!("{} {}", resx, result); }