N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) S=sum(B) S//=2 for a,b in zip(A,B): if b<=S: S-=b else: x=a break print(x,sum(abs(x-a)*b for a,b in zip(A,B)))