import sys import numpy as np input = sys.stdin.readline N = int(input()) AB = np.array([tuple(map(int, input().split())) for _ in range(2)]) AB = AB[:, AB[0].argsort()] acc_ab_left = np.cumsum(AB[0] * AB[1]) acc_ab_right = np.cumsum((AB[0] * AB[1])[::-1])[::-1] acc_b_left = np.cumsum(AB[1]) acc_b_right = np.cumsum(AB[1][::-1])[::-1] y = np.zeros(N, dtype=int) y[1:] += -acc_ab_left[:-1] + acc_b_left[:-1] * AB[0, 1:] y[:-1] += acc_ab_right[1:] - acc_b_right[1:] * AB[0, :-1] x = y.argmin() print(AB[0, x], y[x])