from operator import itemgetter from itertools import * from bisect import * from collections import * from heapq import * import sys # input=sys.stdin.buffer.readline input=sys.stdin.readline sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return input()[:-1] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] n=II() aa=LI() bb=LI() ab=[(a,b) for a,b in zip(aa,bb)] ab.sort() a0=ab[0][0] s=sum((a-a0)*b for a,b in ab) mn=s ans=a0 l=0 r=sum(bb[1:]) for i in range(n-1): a0,b0=ab[i] a1,b1=ab[i+1] l+=b0 s+=(l-r)*(a1-a0) r-=b1 if s