n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) tot = sum(B) ab = [(a, b) for a, b in zip(A, B)] ab.sort() cnt = 0 for a, b in ab: cnt += b if cnt * 2 >= tot: x = a break ans = 0 for a, b in zip(A, B): ans += b * abs(x - a) print(x, ans)