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 bsum = b.iter().sum::(); let mut summary = (0..n).map(|i| (pairs[i].0 - pairs[0].0).abs() * pairs[i].1).sum::(); let mut result = summary; let mut currentb = 0isize; let mut resultb = pairs[0].0; for i in 1..n { let (pa, pb) = pairs[i-1]; let (ca, cb) = pairs[i]; let diff = ca - pa; currentb += pb; summary += diff * currentb; summary -= diff * (bsum - currentb); if summary < result { result = summary; resultb = ca; } } println!("{} {}", resultb, result); }