import sys
input=sys.stdin.readline
t=int(input())

import math
def build(arr,cur_pos,start,end,seg,pre):
	if(start==end):
		seg[cur_pos]=([arr[start]],[arr[start][0]])
	else:
		mid=(start+end)//2
		build(arr,2*cur_pos+1,start,mid,seg,pre)
		build(arr,2*cur_pos+2,mid+1,end,seg,pre)
		seg[cur_pos]=merge(seg[2*cur_pos+1],seg[2*cur_pos+2],arr,start,mid,end)
def merge(L1,R1,arr,low,mid,high):
	# #print(L,R,len(L),len(R))
	L=L1[0]
	R=R1[0]
	i=0
	j=0
	k=low
	while(i<len(L) and j<len(R)):

		if(L[i][1]<R[j][1]):
			if(k!=low):
				pre[k]=pre[k-1]+L[i][0]
			else:
				pre[k]=L[i][0]
			arr[k]=(L[i])
			i+=1
		else:
			if(k!=low):
				pre[k]=pre[k-1]+R[j][0]
			else:
				pre[k]=R[j][0]
			arr[k]=(R[j])
			j+=1
		k+=1
	while(i<len(L)):
		if(k!=low):
			pre[k]=pre[k-1]+L[i][0]
		else:
			pre[k]=L[i][0]
		arr[k]=(L[i])
		i+=1
		k+=1
		
	while(j<len(R)):
		if(k!=low):
			pre[k]=pre[k-1]+R[j][0]
		else:
			pre[k]=R[j][0]
	
		arr[k]=(R[j])
		j+=1
		k+=1
	return (arr[low:high+1],pre[low:high+1])
def bs(arr,k,start,end,n):
	if(start<=end):
		mid=(start+end)//2
		if(arr[mid][1]>=k):
			if(mid==0):
				return -1
			return	bs(arr,k,start,mid-1,n)
		else:
			z=bs(arr,k,mid+1,end,n)
			if(z==-1):
				return mid
			else:
				return z
	return -1

def query(seg,l,r,k,val,cur_pos,start,end,ans):
	# print("elfcled",l,r,start,end)
	if(l<=start and r>=end):
		# print(";dkewl,dc")
		# #print(seg[cur_pos])
		t=bs(seg[cur_pos][0],k,0,len(seg[cur_pos][0])-1,len(seg[cur_pos][0])-1)
		# print(t)
		if(t!=-1):
			# print(t,"   ",seg[cur_pos][0],"    ",val)
			return (seg[cur_pos][1][len(seg[cur_pos][1])-1]-seg[cur_pos][1][t])-(t+1)*(val)
		else:
			return seg[cur_pos][1][len(seg[cur_pos][1])-1]-(len(seg[cur_pos][1]))*(val)

			
		return 0
			#print(ans)
	elif(l>end or r<start):
		return 0
	else:
		mid=(start+end)//2
		
		return query(seg,l,r,k,val,2*cur_pos+1,start,mid,ans)+query(seg,l,r,k,val,2*cur_pos+2,mid+1,end,ans)




x=list(map(int,input().split(" ")))
v=list(map(int,input().split(" ")))
# t=100000
# u=[[0,0]]*(t)
u=[]
for i in range(t):
	u.append((x[i],v[i]))
u=sorted(u,key=lambda  y:(y[0]))
arr=[]
for j in range(t):
	arr.append((u[j][0],u[j][1]))

seg=[[(),()]]*(4*t)
pre=[0]*t
build(arr,0,0,t-1,seg,pre)
#print(seg)
res=0
for i in range(t):
	ans=0
	ans=query(seg,i+1,t-1,u[i][1],u[i][0],0,0,t-1,ans)
	# print(ans)
	if(ans>0):
		res+=ans
	# break
	# res+=(ans-
	# print(res)
print(res)







	