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