n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [(a[i], b[i]) for i in range(n)] c.sort() s = sum(b) idx = 0 t = 0 for i in range(n): t += c[i][0] if t >= s - t: idx = i break x = c[idx][0] ans = 0 for i in range(n): ans += c[i][1] * abs(x - c[i][0]) print(c[idx][0], ans)