import sys;input=sys.stdin.readline N, = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) Z = sorted(list(zip(A,B)), key=lambda x:x[0]) C = [0]*(N+1) D = [0]*(N+1) E = [0]*(N+1) F = [0]*(N+1) for i in range(N): a, b = Z[i] C[i+1] += C[i] + b D[i+1] += D[i] - a*b for i in range(N-1, -1, -1): a, b = Z[i] E[i] += E[i+1] + b F[i] += F[i+1] - a*b m = 10**18 for i in range(N): a, b = Z[i] r = (-E[i+1]+C[i])*a +(-F[i+1]+D[i]) if r < m: m = r mx = A[i] print(mx, m)