#yuki1251 n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) s=sum(b) c=[(a[i],b[i]) for i in range(n)] c.sort() mid=(s+1)//2 t=0 for i in range(n): t+=c[i][1] if t>=mid: x=c[i][0] y=sum(b*abs(a-x) for a,b in c) print(x,y) exit()