n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) f=[(a[i],b[i]) for i in range(n)] f.sort() B=sum(b) c=0 for i in range(n): c+=f[i][1] if c>B//2: x=f[i][0] break print(x,sum(b[i]*abs(x-a[i]) for i in range(n)))