def main(): from sys import stdin 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 range(n): k, v = L[i] now += v if now >= su//2-1: x0 = k if now >= su//2: x1 = k break else: x1 = L[i+1][0] if n % 2 == 0: x = (x0 + x1) / 2 else: x = x0 f = 0 for i in range(n): f += B[i] * abs(x-A[i]) print(x, int(f)) main()