
# _____  _      _  _                           _      _   __                   _                         _      _  _         
# /  ___|| |    (_)| |                         (_)    | | / /                  (_)                       | |    (_)| |        
# \ `--. | |__   _ | |_  ___  _   _  _ __  ___  _     | |/ /   __ _  _ __ ___   _  _ __ ___    __ _  ___ | |__   _ | |_  __ _ 
#  `--. \| '_ \ | || __|/ __|| | | || '__|/ _ \| |    |    \  / _` || '_ ` _ \ | || '_ ` _ \  / _` |/ __|| '_ \ | || __|/ _` |
# /\__/ /| | | || || |_ \__ \| |_| || |  |  __/| | _  | |\  \| (_| || | | | | || || | | | | || (_| |\__ \| | | || || |_| (_| |
# \____/ |_| |_||_| \__||___/ \__,_||_|   \___||_|( ) \_| \_/ \__,_||_| |_| |_||_||_| |_| |_| \__,_||___/|_| |_||_| \__|\__,_|
#                                                |/                                                                          

import math, bisect
# def SieveOfEratosthenes(n): 
# 	prime = [True for i in range(n + 1)] 
# 	p = 2
# 	while (p * p <= n): 
# 		# If prime[p] is not changed, then it is a prime 
# 		if (prime[p] == True): 
# 			# Update all multiples of p 
# 			for i in range(p * 2, n + 1, p): 
# 				prime[i] = False
# 		p += 1
# 	prime[0]= False
# 	prime[1]= False
# 	return prime


# A O(sqrt(n)) java program that prints 
# all divisors in sorted order 
# import math 

# # Method to print the divisors 
# def printDivisors(n) : 
# 	list = [] 
# 	for i in range(1, int(math.sqrt(n) + 1)) : 
# 		if (n % i == 0) : 
# 			if (n / i == i):
# 				list.append(i)
# 			else : 
# 				list.append(int(n / i)) 
# 				list.append(i)
# 	return list

# file = open("input", "r")
def getIn():
	# return file.readline().strip()
	return input().strip()


n = int(getIn())
pos = list(map(int, getIn().split(" ")))
speed = list(map(int, getIn().split(" ")))

ahead = []
behind = []
stable = []

for i in range(len(speed)):
	if speed[i] > 0:
		ahead.append(i)
	elif speed[i] < 0:
		behind.append(i)
	else:
		stable.append(i)


cnt = 0

for i in behind:
	for j in ahead:
		if i < j:
			if pos[i] >= pos[j]:
				cnt += 0
			else:
				cnt += abs(pos[i] - pos[j])

for aa in range(len(behind) - 1):
	for bb in range(aa, len(behind)):
		i = behind[aa]
		j = behind[bb]
		a = pos[i]
		c = pos[j]
		b = speed[i]
		d = speed[j]
		diff1 = a - c
		diff2 = d - b
		if diff2 != 0:
			div = diff1 / diff2
			if div >= 0:
				cnt += 0
			else:
				cnt += abs(a - c)
		else:
			cnt += abs(a - c)


for aa in range(0, len(ahead) - 1):
	for bb in range(aa, len(ahead)):
		i = ahead[aa]
		j = ahead[bb]
		a = pos[i]
		c = pos[j]
		b = speed[i]
		d = speed[j]
		diff1 = a - c
		diff2 = d - b
		if diff2 != 0:
			div = diff1 / diff2
			if div >= 0:
				cnt += 0
			else:
				cnt += abs(a - c)
		else:
			cnt += abs(a - c)

for i in behind:
	for j in stable:
		if i < j:
			if pos[i] > pos[j]:
				cnt += 0
			else:
				cnt += abs(pos[i] - pos[j])

for i in ahead:
	for j in stable:
		if i < j:
			if pos[i] < pos[j]:
				cnt += 0
			else:
				cnt += abs(pos[i] - pos[j])
print(cnt)
