6
12 8 12 17 20 5
17 4 8 8 8 4
 6
4 1 12 9 3 11
12 20 19 12 19 11
 1
1
1
 2
1 2
1 1
 1
7
5
 6
16 20 18 7 14 2
17 12 4 10 7 4

705
 917
 1
 9
 5
 741

n = int(raw_input())
a = map(long, raw_input().split())
b = map(long, raw_input().split())

result = []
for i in a:
	result.append(i)
for i in b:
	result.append(i)

result.sort()

maxx = 0
for i in xrange(2*n):
	maxx += long(i * result[i])
print maxx
