fn read_line<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim_end().parse().ok().unwrap()
}

fn read_line_to_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let iter = input.split_whitespace();
    iter.map(|x| x.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let n = read_line::<usize>();
    let a = read_line_to_vec::<i64>();
    let b = read_line_to_vec::<i64>();

    let mut order = (0..n).collect::<Vec<_>>();
    order.sort_by_key(|&i| a[i]);

    let mut left = vec![0; n];
    let mut sum = b[order[0]];
    for i in 1..n {
        let now = order[i];
        let prev = order[i - 1];
        left[i] = left[i - 1] + (a[now] - a[prev]) * sum;
        sum += b[now];
    }

    let mut right = vec![0; n];
    let mut sum = b[order[n - 1]];
    for i in (0..(n - 1)).rev() {
        let now = order[i];
        let prev = order[i + 1];
        right[i] = right[i + 1] + (a[prev] - a[now]) * sum;
        sum += b[now];
    }

    let (mut x, mut fx) = (0, std::i64::MAX);
    for i in 0..n {
        if left[i] + right[i] < fx {
            x = a[order[i]];
            fx = left[i] + right[i];
        }
    }
    println!("{} {}", x, fx);
}