N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) AB = sorted(zip(A, B)) sumB = sum(B) half = sumB // 2 c = 0 ans2 = 0 for a, b in AB: c += b if c > half: ans1 = a break for a, b in AB: ans2 += abs(ans1 - a) * b print(ans1, ans2)