n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) AB = [] for a, b in zip(A, B): AB.append((a, b)) AB.sort() B_ = [] for _, b in AB: B_.append(b) mab = [] for a, b in AB: mab.append(a*b) from itertools import accumulate cumb = [0]+B_ cumb = list(accumulate(cumb)) cumab = [0]+mab cumab = list(accumulate(cumab)) m = 10**19 ans = -10**18 for i in range(n): x = AB[i][0] #temp1 = 0 #for a, b in AB: #temp1 += b*abs(x-a) temp = 0 temp = (cumb[i]-cumb[0]-cumb[n]+cumb[i])*x temp += -cumab[i]+cumab[0]+(cumab[n]-cumab[i]) #print(x, temp1, temp) if temp <= m: ans = x m = temp print(ans, m)