n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum(b)
l = [(a[i], b[i]) for i in range(n)]
l.sort()
cnt = 0
ind = float("inf")
for i in range(n):
    cnt += l[i][1]
    if cnt >= s - cnt:
        ind = i
        break
ans = 0
for i in range(n):
    ans += l[i][1] * abs(l[ind][0] - l[i][0])
print(l[ind][0], ans)