N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) l = [] for i in range(N): l.append((A[i],B[i])) l.sort() a = 0 for i in range(N): a += B[i] a //= 2 now = 0 o = 0 for i in range(N): p,q = l[i] now += q if now >= a: o = p break sum = 0 for i in range(N): sum += B[i] * abs(o-A[i]) print(o,sum)