def main(): from sys import stdin import math readline=stdin.readline n = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) L = list() for i in range(n): L.append((A[i], B[i])) L.sort() now = 0 su = sum(B) for i in L: k, v = i now += v if now >= math.floor((su+1) / 2): x = k break f = 0 for i in range(n): f += B[i] * abs(x-A[i]) print(x, f) main()