inf = open("wires.in", "r")
ouf = open("wires.out", "w")

n = int(inf.readline())
a = sorted(
	map(lambda s: [int(s), 1], inf.readline().split()) +
	map(lambda s: [int(s), -1], inf.readline().split())
)

cnt = 0
s = 0
prev = 0
for t in a:
	s += cnt * (t[0] - prev)
	cnt += t[1]
	prev = t[0]

ouf.write(str(s))

inf.close()
ouf.close()
		
		