class Compress: def __init__(self,A): """ A=[(a,degeneracy),...] """ S=[0] self.A=[] for a, cnt in A: S.append(S[-1]+cnt) self.A.append(a) self.S=S[1:] def __getitem__(self, i): j=bisect_left(self.S,i+1) return self.A[j] def sum(self, i): """ sum in [0,i) """ j=bisect_left(self.S,i) res=0 q=0 for k in range(j): res+=self.A[k]*(self.S[k]-q) q=self.S[k] print(j, res) if j>0: res+=self.A[j]*(i-self.S[j-1]) else: res+=self.A[j]*(i) return res def __iter__(self): l=0 for i in range(self.S[-1]): if i==self.S[l]: l+=1 yield self.A[l] def __str__(self): return " ".join(list(map(str, self))) def deg(A): """ 連続して続く文字を圧縮する(※Counterではない) [1,1,1,2,2,2,3] -> [(1,3),(2,3),(3,1)] """ res=[] a0, cnt=A[0], 1 for a in A[1:]: if a!=a0: res.append((a0,cnt)); cnt=1 else: cnt+=1 a0=a res.append((a0,cnt)) return res def median(array): L = len(array) if L%2==0: return (array[L//2-1]+array[L//2])/2 else: return array[L//2] ############################################################### import sys from bisect import * input = sys.stdin.readline N=int(input()) A=list(map(int, input().split())) B=list(map(int, input().split())) data=[] for a,b in zip(A,B): data.append((a,b)) C=Compress(data) L=sum(B) if L%2==0: X=(C[L//2-1]+C[L//2])/2 res=0 for i in range(N): res+=B[i]*abs(A[i]-X) else: X=C[L//2] res=0 for i in range(N): res+=B[i]*abs(A[i]-X) print(X,int(res))