
n=int(input())
x=list(map(int,input().split()))
v=list(map(int,input().split()))
arr=[]
for i in range(n):
	arr.append([x[i],v[i]])
arr.sort()
ans1 = 0
ans2 = 0
d = 0
s=0
prev=0
for i in range(n): 
	ans1 += (arr[i][0] * i - d) 
	ans2 += (arr[i][1] * i - s)
	d += arr[i][0]
	s += arr[i][1]
	if prev>ans2:
		ans1-=(prev-ans2)
	prev = ans2
	#print (max(ans1,0),ans2)
print (max(ans1,0))