n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) s = sum(B) ab = [] for i in range(n): ab.append((A[i], B[i])) ab.sort() # med番目が中央値 med = (s + 1) // 2 now = 0 for i in range(n): now += ab[i][1] if now >= med: x = ab[i][0] y = sum(b * abs(a - x) for a, b in ab) print(x, y) exit()