N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) for i in range(N): A[i]+=10**6 C=[0]*(2*10**6+1) for i in range(N): C[A[i]]+=B[i] D=0 E=sum(B) X=0 for i in range(len(C)): D+=C[i] if D>=(E+1)//2: X=i break P=0 for i in range(N): P+=B[i]*abs(X-A[i]) print(X-10**6,P)