Two players A and B have a list of $n$ integers each. They both want to maximize the subtraction between their score and their opponent's score. 

In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an element from his opponent's list (assuming his opponent's list is not empty).

Note, that in case there are equal elements in the list only one of them will be affected in the operations above. For example, if there are elements $\{1, 2, 2, 3\}$ in a list and you decided to choose $2$ for the next turn, only a single instance of $2$ will be deleted (and added to the score, if necessary). 

The player A starts the game and the game stops when both lists are empty. Find the difference between A's score and B's score at the end of the game, if both of the players are playing optimally.

Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves. In this problem, it means that each player, each time makes a move, which maximizes the final difference between his score and his opponent's score, knowing that the opponent is doing the same.


-----Input-----

The first line of input contains an integer $n$ ($1 \le n \le 100\,000$) — the sizes of the list.

The second line contains $n$ integers $a_i$ ($1 \le a_i \le 10^6$), describing the list of the player A, who starts the game.

The third line contains $n$ integers $b_i$ ($1 \le b_i \le 10^6$), describing the list of the player B.


-----Output-----

Output the difference between A's score and B's score ($A-B$) if both of them are playing optimally.


-----Examples-----
Input
2
1 4
5 1

Output
0
Input
3
100 100 100
100 100 100

Output
0
Input
2
2 1
5 6

Output
-3


-----Note-----

In the first example, the game could have gone as follows:   A removes $5$ from B's list.  B removes $4$ from A's list.  A takes his $1$.  B takes his $1$. 

Hence, A's score is $1$, B's score is $1$ and difference is $0$.

There is also another optimal way of playing:  A removes $5$ from B's list.  B removes $4$ from A's list.  A removes $1$ from B's list.  B removes $1$ from A's list. 

The difference in the scores is still $0$.

In the second example, irrespective of the moves the players make, they will end up with the same number of numbers added to their score, so the difference will be $0$.

Difficulty: EASY
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
from sys import stdin, stdout, setrecursionlimit
n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)
b = sorted([int(i) for i in input().split()], reverse=True)
cura = curb = curai = curbi = 0
for i in range(2 * n):
	if i % 2 == 0:
		if curbi == n or (curai < n and a[curai] >= b[curbi]):
			cura += a[curai]
			curai += 1
		else:
			curbi += 1
	elif curai == n or (curbi < n and b[curbi] >= a[curai]):
		curb += b[curbi]
		curbi += 1
	else:
		curai += 1
print(cura - curb)


n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
s1 = s2 = 0
for i in range(2 * n):
	if i % 2 == 0:
		if len(a) > 0 and len(b) > 0 and (a[-1] > b[-1]):
			s1 += a[-1]
			del a[-1]
		elif len(b) > 0:
			del b[-1]
		else:
			s1 += a[-1]
			del a[-1]
	elif len(a) > 0 and len(b) > 0 and (b[-1] > a[-1]):
		s2 += b[-1]
		del b[-1]
	elif len(a) > 0:
		del a[-1]
	else:
		s2 += b[-1]
		del b[-1]
print(s1 - s2)


def ii():
	return int(input())

def mi():
	return list(map(int, input().split()))

def li():
	return list(mi())
n = ii()
a = li()
b = li()
a.sort()
b.sort()
x = y = 0
for t in range(n):
	if not b:
		x += a.pop()
	elif not a:
		b.pop()
	elif a[-1] > b[-1]:
		x += a.pop()
	else:
		b.pop()
	if not a:
		y += b.pop()
	elif not b:
		a.pop()
	elif b[-1] > a[-1]:
		y += b.pop()
	else:
		a.pop()
print(x - y)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
p1 = n - 1
p2 = n - 1
sum1 = 0
sum2 = 0
while 1:
	if p1 != -1 and p2 != -1:
		if a[p1] < b[p2]:
			p2 -= 1
		else:
			sum1 += a[p1]
			p1 -= 1
	elif p1 == -1 and p2 != -1:
		p2 -= 1
	elif p2 == -1 and p1 != -1:
		sum1 += a[p1]
		p1 -= 1
	else:
		break
	if p1 != -1 and p2 != -1:
		if b[p2] < a[p1]:
			p1 -= 1
		else:
			sum2 += b[p2]
			p2 -= 1
	elif p2 == -1 and p1 != -1:
		p1 -= 1
	elif p2 != -1 and p1 == -1:
		sum2 += b[p2]
		p2 -= 1
	else:
		break
print(sum1 - sum2)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
for i in range(n):
	X.append([A[i], 1])
	X.append([B[i], 2])
X.sort(reverse=True)
ans = 0
for i in range(len(X)):
	if i % 2 == 0:
		if X[i][1] == 1:
			ans += X[i][0]
	elif X[i][1] == 2:
		ans -= X[i][0]
print(ans)


import sys
import bisect
from collections import Counter
read_int = lambda : int(sys.stdin.readline())
read_ints = lambda : map(int, sys.stdin.readline().split())
read_int_list = lambda : list(read_ints())
read = lambda : sys.stdin.readline().strip()
read_list = lambda : sys.stdin.readline().split()

def main():
	n = read_int()
	a = read_int_list()
	b = read_int_list()
	(sa, sb) = (0, 0)
	a.sort()
	b.sort()
	turn = True
	while a or b:
		if turn:
			if a:
				if b:
					if a[-1] > b[-1]:
						sa += a.pop()
					else:
						b.pop()
				else:
					sa += a.pop()
			else:
				b.pop()
		elif b:
			if a:
				if b[-1] > a[-1]:
					sb += b.pop()
				else:
					a.pop()
			else:
				sb += b.pop()
		else:
			a.pop()
		turn = not turn
	print(sa - sb)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
i = len(a) - 1
j = len(b) - 1
c = 1
scorea = 0
scoreb = 0
while i >= 0 or j >= 0:
	if c % 2 == 1:
		if j != -1:
			if i != -1:
				if b[j] > a[i]:
					j = j - 1
				else:
					scorea += a[i]
					i = i - 1
			else:
				j = j - 1
		else:
			scorea += a[i]
			i = i - 1
	elif i != -1:
		if j != -1:
			if a[i] > b[j]:
				i = i - 1
			else:
				scoreb += b[j]
				j = j - 1
		else:
			i = i - 1
	else:
		scoreb += b[j]
		j = j - 1
	c = c + 1
print(scorea - scoreb)


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr1.sort(reverse=True)
arr2.sort(reverse=True)
count1 = 0
count2 = 0
sum1 = 0
sum2 = 0
turn = 1
while count1 < n and count2 < n:
	if turn == 1:
		if arr1[count1] >= arr2[count2]:
			sum1 += arr1[count1]
			count1 += 1
		else:
			count2 += 1
		turn = 2
	else:
		if arr2[count2] >= arr1[count1]:
			sum2 += arr2[count2]
			count2 += 1
		else:
			count1 += 1
		turn = 1
while count1 < n:
	if turn == 1:
		sum1 += arr1[count1]
		count1 += 1
		turn = 2
	else:
		count1 += 1
		turn = 1
while count2 < n:
	if turn == 2:
		sum2 += arr2[count2]
		count2 += 1
		turn = 1
	else:
		count2 += 1
		turn = 2
print(sum1 - sum2)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
t = 1
for _ in range(t):
	n = ii()
	a = li()
	b = li()
	a.sort(reverse=True)
	b.sort(reverse=True)
	i = 0
	j = 0
	turn = 0
	A = 0
	B = 0
	while i < n and j < n:
		if turn == 0:
			turn = 1
			if a[i] > b[j]:
				A += a[i]
				i += 1
			else:
				j += 1
		else:
			turn = 0
			if a[i] >= b[j]:
				i += 1
			else:
				B += b[j]
				j += 1
	if i < n:
		while i < n:
			if turn == 0:
				A += a[i]
				i += 1
				turn = 1
			else:
				turn = 0
				i += 1
	if j < n:
		while j < n:
			if turn == 1:
				B += b[j]
				j += 1
				turn = 0
			else:
				turn = 1
				j += 1
	print(A - B)


import sys
input = sys.stdin.readline
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
p = 0
i = 0
j = 0
x = 0
y = 0
while i < n and j < n:
	if p % 2 == 0:
		if a[i] < b[j]:
			j += 1
		else:
			x += a[i]
			i += 1
	elif a[i] > b[j]:
		i += 1
	else:
		y += b[j]
		j += 1
	p += 1
if i < n and j >= n:
	while i < n:
		if p % 2 == 0:
			x += a[i]
		p += 1
		i += 1
elif j < n and i >= n:
	while j < n:
		if p % 2 != 0:
			y += b[j]
		p += 1
		j += 1
print(x - y)


n = int(input())
s = list(map(int, input().split()))
s1 = list(map(int, input().split()))
s.sort()
s1.sort()
a = 0
b = 0
t = True
while len(s1) > 0 or len(s) > 0:
	if t:
		if len(s) > 0 and len(s1) > 0:
			if s[-1] > s1[-1]:
				a += s.pop()
			else:
				s1.pop()
		elif len(s) > 0:
			a += s.pop()
		else:
			s1.pop()
	elif len(s) > 0 and len(s1) > 0:
		if s1[-1] > s[-1]:
			b += s1.pop()
		else:
			s.pop()
	elif len(s1) > 0:
		b += s1.pop()
	else:
		s.pop()
	t = not t
print(a - b)


from collections import deque
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
(sa, sb) = (0, 0)
while a or b:
	if a:
		try:
			if a[-1] > b[-1]:
				sa += a.pop()
			else:
				b.pop()
		except IndexError:
			sa += a.pop()
	else:
		b.pop()
	if b:
		try:
			if b[-1] > a[-1]:
				sb += b.pop()
			else:
				a.pop()
		except IndexError:
			sb += b.pop()
	else:
		a.pop()
print(sa - sb)


n = int(input())
a = input().split()
b = input().split()
for i in range(n):
	a[i] = int(a[i])
	b[i] = int(b[i])
goList = []
for i in range(n):
	cur = (a[i], 1)
	goList.append(cur)
for i in range(n):
	cur = (b[i], 2)
	goList.append(cur)
goList.sort(reverse=True)
ans = 0
for i in range(2 * n):
	cur = goList[i]
	pts = cur[0]
	owner = cur[1]
	if i % 2 == 0:
		if owner == 1:
			ans += pts
	elif owner == 2:
		ans -= pts
print(ans)


a = int(input())
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)
(a1, b1) = (0, 0)
k = 1
(la, lb) = (a, a)
for i in range(2 * a):
	if k:
		if la:
			if lb:
				if b[0] <= c[0]:
					c.pop(0)
					lb -= 1
				else:
					a1 += b.pop(0)
					la -= 1
			else:
				a1 += b.pop(0)
				la -= 1
		else:
			c.pop(0)
	elif lb:
		if la:
			if c[0] <= b[0]:
				b.pop(0)
				la -= 1
			else:
				b1 += c.pop(0)
				lb -= 1
		else:
			b1 += c.pop(0)
			lb -= 1
	else:
		b.pop(0)
	k ^= 1
print(a1 - b1)


from bisect import insort
n = int(input())
la = [int(i) for i in input().split()]
lb = [int(i) for i in input().split()]
la.sort()
lb.sort()
sa = 0
sb = 0
ap = True
for i in range(2 * n):
	if ap:
		if len(la) > 0 and len(lb) > 0:
			if la[-1] > lb[-1]:
				sa += la[-1]
				la.pop()
			else:
				lb.pop()
		elif len(lb) == 0:
			sa += la[-1]
			la.pop()
		else:
			lb.pop()
		ap = False
	else:
		if len(la) > 0 and len(lb) > 0:
			if lb[-1] > la[-1]:
				sb += lb[-1]
				lb.pop()
			else:
				la.pop()
		elif len(la) == 0:
			sb += lb[-1]
			lb.pop()
		else:
			la.pop()
		ap = True
print(sa - sb)


n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
pos1 = n - 1
pos2 = n - 1
sm1 = 0
sm2 = 0
st = True
while pos1 != -1 or pos2 != -1:
	if st:
		if pos2 == -1:
			if pos1 != -1:
				sm1 += a[pos1]
				pos1 -= 1
		elif pos1 == -1:
			pos2 -= 1
		elif a[pos1] > b[pos2]:
			sm1 += a[pos1]
			pos1 -= 1
		else:
			pos2 -= 1
		st = False
	else:
		if pos1 == -1:
			if pos2 != -1:
				sm2 += b[pos2]
				pos2 -= 1
		elif pos2 == -1:
			if pos1 != -1:
				pos1 -= 1
		elif a[pos1] < b[pos2]:
			sm2 += b[pos2]
			pos2 -= 1
		else:
			pos1 -= 1
		st = True
print(sm1 - sm2)


import sys, math, bisect
from heapq import *
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans
for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	arr.sort()
	brr.sort()
	ans1 = []
	ans2 = []
	flag = 1
	while arr or brr:
		if flag:
			if brr and arr:
				if brr[-1] > arr[-1]:
					brr.pop()
				else:
					ans1.append(arr[-1])
					arr.pop()
			elif brr:
				brr.pop()
			else:
				ans1.append(arr[-1])
				arr.pop()
			flag = 0
		else:
			if arr and brr:
				if arr[-1] > brr[-1]:
					arr.pop()
				else:
					ans2.append(brr[-1])
					brr.pop()
			elif brr:
				ans2.append(brr[-1])
				brr.pop()
			else:
				arr.pop()
			flag = 1
	print(sum(ans1) - sum(ans2))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
t = True
sca = 0
scb = 0
while a != [] or b != []:
	if t:
		if a == []:
			b.pop(-1)
		elif b == []:
			sca += a[-1]
			a.pop(-1)
		elif a[-1] > b[-1]:
			sca += a[-1]
			a.pop(-1)
		else:
			b.pop(-1)
		t = False
	else:
		if b == []:
			a.pop(-1)
		elif a == []:
			scb += b[-1]
			b.pop(-1)
		elif b[-1] > a[-1]:
			scb += b[-1]
			b.pop(-1)
		else:
			a.pop(-1)
		t = True
print(sca - scb)


def f(n, order, i):
	pass
n = int(input())
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
A.sort(reverse=True)
B.sort(reverse=True)
i = j = 0
sumA = sumB = 0
flag = 0
while i < n or j < n:
	if i < n and j < n:
		if A[i] >= B[j]:
			if flag == 0:
				sumA += A[i]
			i += 1
		else:
			if flag == 1:
				sumB += B[j]
			j += 1
	elif j >= n:
		if flag == 0:
			sumA += A[i]
		i += 1
	elif i >= n:
		if flag == 1:
			sumB += B[j]
		j += 1
	flag = 1 - flag
print(sumA - sumB)


n = int(input())
lis1 = list(map(int, input().split()))
lis2 = list(map(int, input().split()))
lis1.sort()
lis2.sort()
score1 = 0
score2 = 0
player_one = True
while len(lis1) > 0 and len(lis2) > 0:
	if player_one:
		if lis1[-1] >= lis2[-1]:
			score1 += lis1.pop()
		else:
			lis2.pop()
	elif lis1[-1] >= lis2[-1]:
		lis1.pop()
	else:
		score2 += lis2.pop()
	player_one = not player_one
while len(lis1) > 0:
	if player_one:
		score1 += lis1.pop()
	else:
		lis1.pop()
	player_one = not player_one
while len(lis2) > 0:
	if player_one:
		lis2.pop()
	else:
		score2 += lis2.pop()
	player_one = not player_one
print(score1 - score2)


n = int(input())
inp = lambda : sorted([*map(int, input().split())], reverse=True)
a = inp()
b = inp()
ans = 0
while len(a) > 0 or len(b) > 0:
	if len(b) <= 0 or (len(b) > 0 and len(a) > 0 and (a[0] >= b[0])):
		ans += a[0]
		a.remove(a[0])
	else:
		b.remove(b[0])
	if len(a) <= 0 and len(b) <= 0:
		break
	if len(a) <= 0 or (len(a) > 0 and len(b) > 0 and (b[0] >= a[0])):
		ans -= b[0]
		b.remove(b[0])
	else:
		a.remove(a[0])
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = sorted(a + b)
print(sum(ans[::-2]) - sum(b))


import sys
ls_siz = int(input())
ls_a = list(map(int, input().split()))
ls_b = list(map(int, input().split()))
ls_a.sort()
ls_b.sort()
n = 0
sc_a = 0
sc_b = 0
i = len(ls_a) - 1
j = len(ls_b) - 1
while i != -1 or j != -1:
	if i != -1 and j != -1:
		max_a = ls_a[i]
		max_b = ls_b[j]
		if n % 2 == 0:
			if max_a >= max_b:
				sc_a = sc_a + max_a
				i = i - 1
			else:
				j = j - 1
		elif max_a >= max_b:
			i = i - 1
		else:
			sc_b = sc_b + max_b
			j = j - 1
	elif i == -1 and j != -1:
		max_b = ls_b[j]
		if n % 2 == 0:
			j = j - 1
		else:
			sc_b = sc_b + max_b
			j = j - 1
	elif j == -1 and i != -1:
		max_a = ls_a[i]
		if n % 2 == 0:
			sc_a = sc_a + max_a
			i = i - 1
		else:
			i = i - 1
	n = n + 1
print(sc_a - sc_b)


n = int(input())
l1 = list(sorted(map(int, input().split())))
l2 = list(sorted(map(int, input().split())))
s1 = s2 = 0
while len(l1) > 0 or len(l2) > 0:
	k1 = k2 = 0
	if len(l1) > 0:
		k1 = l1[-1]
	if len(l2) > 0:
		k2 = l2[-1]
	if k1 >= k2:
		s1 += k1
		l1.pop()
	else:
		l2.pop()
	if len(l1) == 0 and len(l2) == 0:
		break
	k1 = k2 = 0
	if len(l1) > 0:
		k1 = l1[-1]
	if len(l2) > 0:
		k2 = l2[-1]
	if k2 >= k1:
		s2 += k2
		l2.pop()
	else:
		l1.pop()
print(s1 - s2)


n = int(input())
a = list(map(lambda x: (int(x), 'A'), input().split()))
b = list(map(lambda x: (int(x), 'B'), input().split()))
c = a + b
c.sort()
c.reverse()
ans = 0
for i in range(2 * n):
	if i % 2 == 0 and c[i][1] == 'A':
		ans += c[i][0]
	if i % 2 == 1 and c[i][1] == 'B':
		ans -= c[i][0]
print(ans)


def gambling():
	n = int(input())
	aa = list(map(int, input().split()))
	bb = list(map(int, input().split()))
	aa.sort()
	bb.sort()
	(sa, sb) = (0, 0)
	while aa or bb:
		if len(aa) == 0:
			bb.pop()
		elif len(bb) == 0:
			sa += aa.pop()
		elif aa[-1] >= bb[-1]:
			sa += aa.pop()
		else:
			bb.pop()
		if len(bb) == 0:
			aa.pop()
		elif len(aa) == 0:
			sb += bb.pop()
		elif bb[-1] >= aa[-1]:
			sb += bb.pop()
		else:
			aa.pop()
	print(sa - sb)
gambling()


n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
(i, j, p, s) = (n - 1, n - 1, True, 0)
while i >= 0 or j >= 0:
	if p:
		if i == -1:
			j -= 1
		elif j == -1:
			s += a[i]
			i -= 1
		elif a[i] <= b[j]:
			j -= 1
		else:
			s += a[i]
			i -= 1
	elif j == -1:
		i -= 1
	elif i == -1:
		s -= b[j]
		j -= 1
	elif a[i] >= b[j]:
		i -= 1
	else:
		s -= b[j]
		j -= 1
	p = not p
print(s)


n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
A = B = 0
while a != [] or b != []:
	if a:
		if b:
			if a[-1] > b[-1]:
				A += a.pop()
			else:
				b.pop()
		else:
			A += a.pop()
	else:
		b.pop()
	if b:
		if a:
			if b[-1] > a[-1]:
				B += b.pop()
			else:
				a.pop()
		else:
			B += b.pop()
	else:
		a.pop()
print(A - B)


n = int(input())
a = list(map(int, input().split()))
a = [(a[i], 0) for i in range(n)]
b = list(map(int, input().split()))
b = [(b[i], 1) for i in range(n)]
ab = sorted(a + b, key=lambda x: x[0], reverse=True)
ans = 0
for i in range(2 * n):
	if i % 2 == 0:
		if ab[i][1] == 0:
			ans += ab[i][0]
	elif ab[i][1] == 1:
		ans -= ab[i][0]
print(ans)


from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a = sorted(a)
b = sorted(b)
a = deque(a)
b = deque(b)
la = len(a)
lb = len(b)
score_a = 0
score_b = 0
for i in range(la + lb):
	if i % 2 == 0:
		if la > 0:
			current = a[-1]
		else:
			current = 0
		if lb > 0:
			compare = b[-1]
		else:
			compare = 0
		if compare > current and lb > 0:
			ele = b.pop()
			lb -= 1
		elif la > 0:
			ele = a.pop()
			la -= 1
			score_a += ele
	else:
		if lb > 0:
			current = b[-1]
		else:
			current = 0
		if la > 0:
			compare = a[-1]
		else:
			compare = 0
		if compare > current:
			ele = a.pop()
			la -= 1
		elif lb > 0:
			ele = b.pop()
			lb -= 1
			score_b += ele
print(score_a - score_b)


_ = input()
a = list(map(int, input().split())) + [0]
b = list(map(int, input().split())) + [0]
a.sort()
b.sort()
sa = 0
sb = 0
while len(a) > 1 or len(b) > 1:
	if a[-1] > b[-1]:
		sa += a.pop()
	else:
		b.pop()
	if a[-1] > b[-1]:
		a.pop()
	else:
		sb += b.pop()
print(sa - sb)


a = input()
bb = input().split()
cc = input().split()
b = list()
c = list()
for i in bb:
	b.append(int(i))
for i in cc:
	c.append(int(i))
b.sort()
c.sort()
q = 0
w = 0
for i in range(int(a)):
	if len(c) == 0:
		c.append(0)
	if len(b) == 0:
		b.append(0)
	if b[len(b) - 1] > c[len(c) - 1]:
		q += b[len(b) - 1]
		del b[len(b) - 1]
	else:
		del c[len(c) - 1]
	if len(c) == 0:
		c.append(0)
	if len(b) == 0:
		b.append(0)
	if c[len(c) - 1] > b[len(b) - 1]:
		w += c[len(c) - 1]
		del c[len(c) - 1]
	else:
		del b[len(b) - 1]
print(q - w)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = a + b
c.sort(reverse=True)
sum1 = sum(a)
sum2 = sum(b)
for i in range(len(c)):
	if i % 2 == 0:
		sum1 += c[i]
	else:
		sum2 += c[i]
print((sum1 - sum2) // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
(A, B) = (0, 0)
for i in range(2 * n):
	if i % 2:
		if len(a) == 0:
			B += b.pop()
			continue
		if len(b) == 0:
			a.pop()
			continue
		if a[-1] >= b[-1]:
			a.pop()
		else:
			B += b.pop()
	else:
		if len(a) == 0:
			b.pop()
			continue
		if len(b) == 0:
			A += a.pop()
			continue
		if a[-1] >= b[-1]:
			A += a.pop()
		else:
			b.pop()
print(A - B)


import heapq
n = int(input())
line_a = list(map(lambda x: -int(x), input().split()))
line_b = list(map(lambda x: -int(x), input().split()))
heapq.heapify(line_a)
heapq.heapify(line_b)
score_a = 0
score_b = 0
hod = 0
while len(line_a) != 0 or len(line_b) != 0:
	if len(line_a) != 0 and len(line_b) != 0:
		if line_a[0] < line_b[0]:
			if hod % 2 == 0:
				score_a += line_a[0]
			heapq.heappop(line_a)
		else:
			if hod % 2 == 1:
				score_b += line_b[0]
			heapq.heappop(line_b)
	elif len(line_a) != 0:
		if hod % 2 == 0:
			score_a += line_a[0]
		heapq.heappop(line_a)
	elif len(line_b) != 0:
		if hod % 2 == 1:
			score_b += line_b[0]
		heapq.heappop(line_b)
	hod = (hod + 1) % 2
print(score_b - score_a)


n = int(input())
a = input().split()
b = input().split()
ara = []
arb = []
for i in a:
	ara.append(int(i))
for i in b:
	arb.append(int(i))
ara.sort()
arb.sort()
i = 0
sumsa = 0
sumsb = 0
while i < n:
	if len(arb) == 0:
		sumsa += ara[-1]
		ara.pop()
	elif len(ara) == 0:
		arb.pop()
	elif arb[-1] > ara[-1]:
		arb.pop()
	else:
		sumsa += ara[-1]
		ara.pop()
	if len(ara) == 0:
		sumsb += arb[-1]
		arb.pop()
	elif len(arb) == 0:
		ara.pop()
	elif ara[-1] > arb[-1]:
		ara.pop()
	else:
		sumsb += arb[-1]
		arb.pop()
	i += 1
print(sumsa - sumsb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
sa = 0
sb = 0
xa = 0
xb = 0
c = 0
for i in range(n):
	sa += a[i]
	sb += b[i]
la = n
lb = n
ia = n - 1
ib = n - 1
while ia >= 0 or ib >= 0:
	if ia == -1 or ib == -1:
		if c % 2 == 0:
			if ia == -1:
				ib = ib - 1
			else:
				xa = xa + a[ia]
				ia = ia - 1
		elif ia == -1:
			xb = xb + b[ib]
			ib = ib - 1
		else:
			ia = ia - 1
	elif c % 2 == 0:
		if a[ia] >= b[ib]:
			xa = xa + a[ia]
			ia = ia - 1
		else:
			ib = ib - 1
	elif b[ib] >= a[ia]:
		xb = xb + b[ib]
		ib = ib - 1
	else:
		ia = ia - 1
	c = c + 1
print(xa - xb)


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

def nninp():
	return map(int, input().split())

def llinp():
	return list(map(int, input().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
n = iinp()
a = llinp()
b = llinp()
a.sort(reverse=True)
b.sort(reverse=True)
a.append(0)
b.append(0)
ind1 = ind2 = tot = sa = sb = f = 0
while tot < 2 * n:
	tot += 1
	if f == 0:
		if a[ind1] > b[ind2]:
			sa += a[ind1]
			ind1 += 1
		else:
			ind2 += 1
		f = 1
	elif f == 1:
		if b[ind2] > a[ind1]:
			sb += b[ind2]
			ind2 += 1
		else:
			ind1 += 1
		f = 0
p(sa - sb)


n = int(input())
ch = input()
ch1 = input()
l = list(map(int, ch.split()))
l1 = list(map(int, ch1.split()))
l.sort()
l1.sort()
i = n - 1
j = n - 1
s1 = 0
s2 = 0
b = False
while i >= 0 and j >= 0:
	if l[i] < l1[j]:
		j -= 1
	else:
		s1 += l[i]
		i -= 1
	if j < 0:
		b = True
		break
	if i < 0:
		b = True
		break
	if l1[j] < l[i]:
		i -= 1
	else:
		s2 += l1[j]
		j -= 1
if b and j < 0:
	i -= 1
	while i >= 0:
		s1 += l[i]
		i -= 2
if b and i < 0:
	while j >= 0:
		s2 += l1[j]
		j -= 2
if j < 0 and (not b) and (i > 0):
	while i >= 0:
		s1 += l[i]
		i -= 2
if i < 0 and (not b) and (j > 0):
	j -= 1
	while j >= 0:
		s2 += l1[j]
		j -= 2
print(s1 - s2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
(a_points, b_points) = (0, 0)
while a or b:
	if not b:
		a_points += a.pop()
	elif not a:
		b.pop()
	elif a[-1] < b[-1]:
		b.pop()
	else:
		a_points += a.pop()
	if not a:
		if b:
			b_points += b.pop()
	elif not b:
		a.pop()
	elif b[-1] < a[-1]:
		a.pop()
	else:
		b_points += b.pop()
print(a_points - b_points)


def sol():
	N = int(input())
	A = [int(x) for x in input().split(' ')]
	B = [int(x) for x in input().split(' ')]
	A = list(sorted(A))
	B = list(sorted(B))
	a_score = 0
	b_score = 0
	a_turn = True
	while len(A) > 0 or len(B) > 0:
		if a_turn:
			if len(B) == 0:
				a_score += A.pop()
			elif len(A) == 0:
				B.pop()
			elif A[-1] >= B[-1]:
				a_score += A.pop()
			else:
				B.pop()
		elif len(B) == 0:
			A.pop()
		elif len(A) == 0:
			b_score += B.pop()
		elif B[-1] >= A[-1]:
			b_score += B.pop()
		else:
			A.pop()
		a_turn = not a_turn
	print(a_score - b_score)
sol()


n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
Ascore = 0
Bscore = 0
a = 0
b = 0
for i in range(n):
	if a == n:
		b += 1
	elif b == n:
		Ascore += A[a]
		a += 1
	elif A[a] > B[b]:
		Ascore += A[a]
		a += 1
	else:
		b += 1
	if b == n:
		a += 1
	elif a == n:
		Bscore += B[b]
		b += 1
	elif B[b] > A[a]:
		Bscore += B[b]
		b += 1
	else:
		a += 1
print(Ascore - Bscore)


from collections import deque
l = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
a_score = 0
b_score = 0
is_a_turn = True
while len(a) > 0 or len(b) > 0:
	if is_a_turn:
		if len(a) == 0:
			b.pop()
		elif len(b) == 0:
			a_score += a.pop()
		elif b[-1] > a[-1]:
			b.pop()
		else:
			a_score += a.pop()
	elif len(b) == 0:
		a.pop()
	elif len(a) == 0:
		b_score += b.pop()
	elif b[-1] < a[-1]:
		a.pop()
	else:
		b_score += b.pop()
	is_a_turn = not is_a_turn
print(a_score - b_score)


n = int(input())
ar = list(map(int, input().split()))
br = list(map(int, input().split()))
ar.sort()
br.sort()
a = 0
b = 0
x = 0
while len(ar) != 0 or len(br) != 0:
	if x == 0:
		if len(br) != 0 and len(ar) != 0 and (br[-1] > ar[-1]):
			br.pop(-1)
		elif len(ar) == 0 and len(br) != 0:
			br.pop(-1)
		elif len(ar) != 0:
			a += ar[-1]
			ar.pop(-1)
		x = 1
	else:
		if len(br) != 0 and len(ar) != 0 and (ar[-1] > br[-1]):
			ar.pop(-1)
		elif len(br) == 0 and len(ar) != 0:
			ar.pop(-1)
		elif len(br) != 0:
			b += br[-1]
			br.pop(-1)
		x = 0
print(a - b)


n = int(input())
l1 = [int(i) for i in input().split()[:n]]
l2 = [int(i) for i in input().split()[:n]]
l1 = sorted(l1)
l2 = sorted(l2)
(s1, s2) = (0, 0)
(i1, i2) = (n - 1, n - 1)
for _ in range(n):
	if (l1[i1] > l2[i2] or i2 < 0) and i1 >= 0:
		s1 += l1[i1]
		i1 -= 1
	else:
		i2 -= 1
	if (l2[i2] > l1[i1] or i1 < 0) and i2 >= 0:
		s2 += l2[i2]
		i2 -= 1
	else:
		i1 -= 1
print(s1 - s2)


size = int(input())
player1_list = list(map(int, input().split()))
player2_list = list(map(int, input().split()))
player1_list.sort(reverse=True)
player2_list.sort(reverse=True)
score = 0
pos1 = 0
pos2 = 0
turn1 = True
while pos1 < size or pos2 < size:
	if pos1 < size:
		if pos2 < size:
			if turn1:
				turn1 = False
				if player1_list[pos1] > player2_list[pos2]:
					score += player1_list[pos1]
					pos1 += 1
				else:
					pos2 += 1
			else:
				turn1 = True
				if player1_list[pos1] <= player2_list[pos2]:
					score -= player2_list[pos2]
					pos2 += 1
				else:
					pos1 += 1
		elif turn1:
			turn1 = False
			score += player1_list[pos1]
			pos1 += 1
		else:
			turn1 = True
			pos1 += 1
	elif turn1:
		turn1 = False
		pos2 += 1
	else:
		turn1 = True
		score -= player2_list[pos2]
		pos2 += 1
print(score)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
countA = 0
countB = 0
f = 0
while a != [] and b != []:
	if f % 2 == 0:
		if a[-1] > b[-1]:
			countA += a.pop()
		else:
			b.pop()
		f += 1
	else:
		if b[-1] > a[-1]:
			countB += b.pop()
		else:
			a.pop()
		f += 1
if a != []:
	for i in range(len(a) - 1, -1, -1):
		if f % 2 == 0:
			countA += a[i]
		f += 1
if b != []:
	for i in range(len(b) - 1, -1, -1):
		if f % 2 != 0:
			countB += b[i]
		f += 1
print(countA - countB)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
sa = 0
sb = 0
for i in range(n):
	la = len(a)
	lb = len(b)
	if la == 0 or (lb != 0 and a[-1] < b[-1]):
		b.pop()
		lb -= 1
	else:
		sa += a[-1]
		a.pop()
		la -= 1
	if la == 0 or (lb != 0 and a[-1] < b[-1]):
		sb += b[-1]
		b.pop()
	else:
		a.pop()
print(sa - sb)


n = int(input())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
print(sum(sorted(a + b)[::-2]) - sum(b))


sc1 = 0
sc2 = 0
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
n1 = len(a)
n2 = len(b)
fl = 0
while n1 > 0 and n2 > 0:
	if fl == 0:
		if a[n1 - 1] < b[n2 - 1]:
			b.pop(n2 - 1)
			n2 -= 1
		else:
			x = a.pop(n1 - 1)
			n1 -= 1
			sc1 += x
		fl = 1
	elif fl == 1:
		if b[n2 - 1] < a[n1 - 1]:
			a.pop(n1 - 1)
			n1 -= 1
		else:
			x = b.pop(n2 - 1)
			n2 -= 1
			sc2 += x
		fl = 0
while n1 > 0:
	if fl == 0:
		x = a.pop(n1 - 1)
		n1 -= 1
		sc1 += x
		fl = 1
	else:
		a.pop(n1 - 1)
		n1 -= 1
		fl = 0
while n2 > 0:
	if fl == 1:
		x = b.pop(n2 - 1)
		n2 -= 1
		sc2 += x
		fl = 0
	else:
		b.pop(n2 - 1)
		n2 -= 1
		fl = 1
print(sc1 - sc2)


import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
n = nu()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
x = n - 1
y = n - 1
pp = 1
sa = 0
sb = 0
while x >= 0 or y >= 0:
	if pp == 1:
		if y >= 0:
			if x >= 0:
				if a[x] < b[y]:
					y -= 1
				else:
					sa += a[x]
					x -= 1
			else:
				y -= 1
		elif x >= 0:
			sa += a[x]
			x -= 1
	elif x >= 0:
		if y >= 0:
			if a[x] > b[y]:
				x -= 1
			else:
				sb += b[y]
				y -= 1
		else:
			x -= 1
	elif y >= 0:
		sb += b[y]
		y -= 1
	pp = pp * -1
print(sa - sb)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
x = 0
y = 0
k = 1
i = n - 1
j = n - 1
while i >= 0 or j >= 0:
	if k == 1:
		if j >= 0:
			if B[j] >= A[i] or i < 0:
				j -= 1
			else:
				x += A[i]
				i -= 1
		else:
			x += A[i]
			i -= 1
		k = 2
	else:
		if i >= 0:
			if A[i] >= B[j] or j < 0:
				i -= 1
			else:
				y += B[j]
				j -= 1
		else:
			y += B[j]
			j -= 1
		k = 1
print(x - y)


n = int(input())
arrayA = list(map(int, input().split()))
arrayB = list(map(int, input().split()))
arrayA.sort()
arrayB.sort()
a = n - 1
b = n - 1
result = 0
while arrayA or arrayB:
	if arrayA and (not arrayB) or (arrayA and arrayB and (arrayA[a] >= arrayB[b])):
		result += arrayA[a]
		arrayA.pop()
		a -= 1
	elif arrayB:
		arrayB.pop()
		b -= 1
	if not arrayA and arrayB or (arrayA and arrayB and (arrayA[a] <= arrayB[b])):
		result -= arrayB[b]
		arrayB.pop()
		b -= 1
	elif arrayA:
		arrayA.pop()
		a -= 1
print(result)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort()
a.sort()
(i, j, A, B) = (n - 1, n - 1, 0, 0)
flag = True
while i >= 0 or j >= 0:
	if flag == True:
		if i < 0:
			j -= 1
		elif j < 0:
			A += a[i]
			i -= 1
		elif j >= 0 and a[i] >= b[j]:
			A += a[i]
			i -= 1
		elif j >= 0 and a[i] < b[j]:
			j -= 1
		flag = False
	else:
		if j < 0:
			i -= 1
		elif i < 0:
			B += b[j]
			j -= 1
		elif i >= 0 and b[j] >= a[i]:
			B += b[j]
			j -= 1
		elif j >= 0 and a[i] > b[j]:
			i -= 1
		flag = True
print(A - B)


def solve(n, arrA, arrB):
	arrA.sort()
	arrB.sort()
	scoreA = 0
	scoreB = 0
	turn = 0
	indexA = n - 1
	indexB = n - 1
	while indexA >= 0 and indexB >= 0:
		if turn == 0:
			if arrA[indexA] >= arrB[indexB]:
				scoreA += arrA[indexA]
				indexA -= 1
			else:
				indexB -= 1
			turn = 1
		else:
			if arrA[indexA] > arrB[indexB]:
				indexA -= 1
			else:
				scoreB += arrB[indexB]
				indexB -= 1
			turn = 0
	while indexA >= 0:
		if turn == 0:
			scoreA += arrA[indexA]
			turn = 1
		else:
			turn = 0
		indexA -= 1
	while indexB >= 0:
		if turn == 1:
			scoreB += arrB[indexB]
			turn = 0
		else:
			turn = 1
		indexB -= 1
	return scoreA - scoreB
n = int(input())
arrA = list(map(int, input().split()))
arrB = list(map(int, input().split()))
print(solve(n, arrA, arrB))


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
(sA, sB) = (0, 0)
(i, j) = (0, 0)
turn = 1
while True:
	turn += 1
	turn %= 2
	if i >= n and j >= n:
		break
	if i == n:
		if turn == 1:
			sB += B[j]
		j += 1
		continue
	if j == n:
		if turn == 0:
			sA += A[i]
		i += 1
		continue
	if turn == 0:
		if A[i] > B[j]:
			sA += A[i]
			i += 1
		elif A[i] < B[j]:
			j += 1
		else:
			j += 1
	elif A[i] > B[j]:
		i += 1
	elif A[i] < B[j]:
		sB += B[j]
		j += 1
	else:
		i += 1
print(sA - sB)


import sys, heapq
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
qa = []
qb = []
for i in a:
	heapq.heappush(qa, -1 * i)
for i in b:
	heapq.heappush(qb, -1 * i)
sa = 0
sb = 0
for i in range(2 * n):
	if i % 2 == 0:
		if not qa:
			heapq.heappop(qb)
		elif not qb:
			sa += -1 * heapq.heappop(qa)
		elif -1 * qa[0] >= -1 * qb[0]:
			sa += -1 * heapq.heappop(qa)
		else:
			heapq.heappop(qb)
	elif not qb:
		heapq.heappop(qa)
	elif not qa:
		sb += -1 * heapq.heappop(qb)
	elif -1 * qb[0] >= -1 * qa[0]:
		sb += -1 * heapq.heappop(qb)
	else:
		heapq.heappop(qa)
print(sa - sb)


n = int(input())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
l.sort()
m.sort()
a = 0
b = 0
f = 0
while len(l) > 0 and len(m) > 0:
	if f % 2 == 0:
		if l[-1] > m[-1]:
			a += l[-1]
			l.pop()
		else:
			m.pop()
	elif m[-1] > l[-1]:
		b += m[-1]
		m.pop()
	else:
		l.pop()
	f += 1
if len(l) != 0:
	for i in range(len(l) - 1, -1, -1):
		if f % 2 == 0:
			a += l[i]
		f += 1
if len(m) != 0:
	for i in range(len(m) - 1, -1, -1):
		if f % 2 != 0:
			b += m[i]
		f += 1
print(a - b)


from __future__ import division, print_function
import os
import sys
from io import IOBase, BytesIO

def main():
	n = int(input())
	pa = 0
	pb = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort(reverse=True)
	cf = 1
	ac = 0
	bc = 0
	while ac < n and bc < n:
		if cf == 1:
			if a[ac] >= b[bc]:
				pa += a[ac]
				ac += 1
				cf = 0
			else:
				bc += 1
				cf = 0
		else:
			cf = 1
			if b[bc] >= a[ac]:
				pb += b[bc]
				bc += 1
			else:
				ac += 1
	while ac < n:
		if cf == 1:
			pa += a[ac]
			ac += 1
			cf = 0
		else:
			cf = 1
			ac += 1
	while bc < n:
		if cf == 0:
			pb += b[bc]
			bc += 1
			cf = 1
		else:
			cf = 0
			bc += 1
	print(pa - pb)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a = sorted(a)
b = sorted(b)
(f, s) = (0, 0)
while len(a) + len(b) > 0:
	if len(a) > 0:
		if len(b) > 0 and a[-1] < b[-1]:
			b.pop()
		else:
			f += a.pop()
	elif len(b) > 0:
		b.pop()
	if len(b) > 0:
		if len(a) > 0 and a[-1] > b[-1]:
			a.pop()
		else:
			s += b.pop()
	elif len(a) > 0:
		a.pop()
print(f - s)


t = int(input())
k = list(map(int, input().split()))
l = list(map(int, input().split()))
k.sort()
l.sort()
x = 0
y = 0
for i in range(t):
	if k == []:
		l.pop()
	elif l == []:
		x = x + k.pop()
	elif k[-1] <= l[-1]:
		l.pop()
	else:
		x = x + k.pop()
	if l == []:
		k.pop()
	elif k == []:
		y = y + l.pop()
	elif l[-1] <= k[-1]:
		k.pop()
	else:
		y = y + l.pop()
print(x - y)


i = lambda : [*map(int, input().split())]
i()
a = i()
b = i()
print(sum(a) - sum(sorted(a + b)[::2]))


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
while t > 0:
	t -= 1
	n = fi()
	a = li()
	b = li()
	p1 = p2 = 0
	a.sort()
	b.sort()
	for i in range(n):
		if len(a) == 0 or len(b) == 0:
			if len(a) == 0:
				b.pop()
			else:
				p1 += a[-1]
				a.pop()
		elif a[-1] < b[-1]:
			b.pop()
		else:
			p1 += a[-1]
			a.pop()
		if len(a) == 0 or len(b) == 0:
			if len(a) == 0:
				p2 += b[-1]
				b.pop()
			else:
				a.pop()
		elif a[-1] < b[-1]:
			p2 += b[-1]
			b.pop()
		else:
			a.pop()
	print(p1 - p2)


n = int(input())
alst = [int(z) for z in input().split()]
blst = [int(z) for z in input().split()]
alst.sort(reverse=True)
blst.sort(reverse=True)
a = 0
b = 0
remA = 0
remB = 0
for x in range(2 * n):
	if x % 2 == 0:
		if remA == n:
			remB += 1
		elif remB == n:
			a += alst[remA]
			remA += 1
		elif alst[remA] > blst[remB]:
			a += alst[remA]
			remA += 1
		else:
			remB += 1
	elif x % 2 == 1:
		if remA == n:
			b += blst[remB]
			remB += 1
		elif remB == n:
			remA += 1
		elif blst[remB] > alst[remA]:
			b += blst[remB]
			remB += 1
		else:
			remA += 1
print(a - b)


from functools import *
n = int(input())
[a, b] = (list(map(int, input().split())) for _ in range(2))
v = list((sum(l) for l in [a, b]))
a += b
a.sort(reverse=True)
for i in range(2 * n):
	v[i & 1] += a[i]
print((v[0] - v[1]) // 2)


n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
s_a = s_b = 0
a_j = b_j = n - 1
for i in range(2 * n):
	if i % 2 == 0:
		if a_j == -1:
			b_j -= 1
		elif b_j == -1:
			s_a += a[a_j]
			a_j -= 1
		elif a[a_j] < b[b_j]:
			b_j -= 1
		else:
			s_a += a[a_j]
			a_j -= 1
	elif b_j == -1:
		a_j -= 1
	elif a_j == -1:
		s_b += b[b_j]
		b_j -= 1
	elif b[b_j] < a[a_j]:
		a_j -= 1
	else:
		s_b += b[b_j]
		b_j -= 1
print(s_a - s_b)


n = int(input())
As = [int(x) for x in input().split()]
Bs = [int(x) for x in input().split()]
scores = [0, 0]
As.sort()
Bs.sort()
for i in range(n * 2):
	is_a = i % 2 == 0
	if len(As) == 0:
		if is_a:
			Bs.pop()
		else:
			scores[1] += Bs.pop()
	elif len(Bs) == 0:
		if is_a:
			scores[0] += As.pop()
		else:
			As.pop()
	elif As[-1] > Bs[-1]:
		if is_a:
			scores[i % 2] += As.pop()
		else:
			As.pop()
	elif is_a:
		Bs.pop()
	else:
		scores[1] += Bs.pop()
print(scores[0] - scores[1])


from math import *
n = int(input())
first = [(i, 'A') for i in list(map(int, input().split()))]
second = [(i, 'B') for i in list(map(int, input().split()))]
gm = sorted(first + second, key=lambda x: x[0], reverse=True)
turn = 'A'
result = 0
for i in gm:
	if i[1] == turn == 'A':
		result += i[0]
	elif i[1] == turn == 'B':
		result -= i[0]
	if turn == 'A':
		turn = 'B'
	else:
		turn = 'A'
print(result)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for i in range(n)]
a += c
b += c
sa = 0
sb = 0
a.sort(reverse=True)
b.sort(reverse=True)
d = 0
i = 0
j = 0
for p in range(2 * n):
	if p % 2 == 0:
		if a[i] > b[j]:
			sa += a[i]
			i += 1
		else:
			j += 1
	elif p % 2 == 1:
		if b[j] > a[i]:
			sb += b[j]
			j += 1
		else:
			i += 1
print(sa - sb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
i = 0
fa = 0
fb = 0
sa = 0
sb = 0
while i < 2 * n:
	if i % 2 == 0:
		if fa != n and fb != n:
			if a[fa] >= b[fb]:
				sa += a[fa]
				fa += 1
			else:
				fb += 1
		elif fb == n:
			sa += a[fa]
			fa += 1
		elif fa == n:
			fb += 1
	elif fa != n and fb != n:
		if b[fb] >= a[fa]:
			sb += b[fb]
			fb += 1
		else:
			fa += 1
	elif fa == n:
		sb += b[fb]
		fb += 1
	elif fb == n:
		fa += 1
	i += 1
print(sa - sb)


def sortBySecond(x):
	return x[1]
n = int(input())
a = [(1, int(el)) for el in input().split()]
b = [(2, int(el)) for el in input().split()]
a.extend(b)
a.sort(key=sortBySecond)
out = 0
for i in range(2 * n - 1, 0, -2):
	if a[i][0] == 1:
		out = out + a[i][1]
	if a[i - 1][0] == 2:
		out = out - a[i - 1][1]
print(out)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
Max = 0
pos = 0
flag = True
a.sort(reverse=True)
b.sort(reverse=True)
a_score = 0
b_score = 0
a_pos = 0
b_pos = 0
while a_pos < n and b_pos < n:
	if flag:
		if a[a_pos] < b[b_pos]:
			b_pos += 1
		else:
			a_score += a[a_pos]
			a_pos += 1
		flag = False
	else:
		if a[a_pos] > b[b_pos]:
			a_pos += 1
		else:
			b_score += b[b_pos]
			b_pos += 1
		flag = True
while a_pos < n:
	if flag:
		a_score += a[a_pos]
		a_pos += 1
		flag = False
	else:
		a_pos += 1
		flag = True
while b_pos < n:
	if not flag:
		b_score += b[b_pos]
		b_pos += 1
		flag = True
	else:
		b_pos += 1
		flag = False
print(a_score - b_score)


n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
a = [0] + a
b = [0] + b
(i, j) = (n, n)
(A, B) = (0, 0)
while i > 0 or j > 0:
	if a[i] >= b[j]:
		A += a[i]
		i -= 1
		if i == 0:
			a[i] = 0
	else:
		j -= 1
		if j < 0:
			j = 0
			b[j] = 0
	if b[j] >= a[i]:
		B += b[j]
		j -= 1
		if j == 0:
			b[j] = 0
	else:
		i -= 1
		if i < 0:
			i = 0
			a[i] = 0
print(A - B)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
s1 = 0
s2 = 0
for i in range(n):
	x = len(a)
	y = len(b)
	if x > 0 and y > 0:
		if a[0] <= b[0]:
			del b[0]
		else:
			s1 += a[0]
			del a[0]
	elif x > 0:
		s1 += a[0]
		del a[0]
	elif y > 0:
		del b[0]
	x = len(a)
	y = len(b)
	if x > 0 and y > 0:
		if b[0] <= a[0]:
			del a[0]
		else:
			s2 += b[0]
			del b[0]
	elif x > 0:
		del a[0]
	elif y > 0:
		s2 += b[0]
		del b[0]
print(s1 - s2)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a = sorted(a)
b = sorted(b)
i = n - 1
j = n - 1
score = 0
player = 1
moves = 1
while moves <= 2 * n:
	if player % 2 != 0:
		if a[i] >= b[j] and i >= 0 or j < 0:
			score += a[i]
			i -= 1
		else:
			j -= 1
	elif b[j] >= a[i] and j >= 0 or i < 0:
		score -= b[j]
		j -= 1
	else:
		i -= 1
	player += 1
	moves += 1
print(score)


def main():
	n = int(input())
	a = 0
	arr = sorted(map(int, input().split()), reverse=1)
	kek = sorted(map(int, input().split()), reverse=1)
	i = 0
	j = 0
	while i + j != n << 1:
		if i & 1 ^ j & 1:
			if i == n:
				a -= kek[j]
				j += 1
			elif j == n:
				i += 1
			elif arr[i] > kek[j]:
				i += 1
			else:
				a -= kek[j]
				j += 1
		elif j == n:
			a += arr[i]
			i += 1
		elif i == n:
			j += 1
		elif kek[j] > arr[i]:
			j += 1
		else:
			a += arr[i]
			i += 1
	print(a)
main()


n = int(input())
a_vec = list(map(int, input().split()))
b_vec = list(map(int, input().split()))
a_vec.sort(reverse=True)
b_vec.sort(reverse=True)
a_sum = 0
b_sum = 0
i = 0
j = 0
while i + j < 2 * n:
	if i == n:
		j += 1
	elif j == n:
		a_sum += a_vec[i]
		i += 1
	elif a_vec[i] >= b_vec[j]:
		a_sum += a_vec[i]
		i += 1
	else:
		j += 1
	if j == n:
		i += 1
	elif i == n:
		b_sum += b_vec[j]
		j += 1
	elif b_vec[j] >= a_vec[i]:
		b_sum += b_vec[j]
		j += 1
	else:
		i += 1
print(a_sum - b_sum)


import math
from decimal import *
getcontext().prec = 30
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
A = 0
B = 0
for i in range(2 * n):
	if i % 2 == 0:
		if len(a) == 0:
			b.pop()
			continue
		if len(b) == 0:
			A += a[-1]
			a.pop()
			continue
		if a[-1] < b[-1]:
			b.pop()
		else:
			A += a[-1]
			a.pop()
	else:
		if len(b) == 0:
			a.pop()
			continue
		if len(a) == 0:
			B += b[-1]
			b.pop()
			continue
		if a[-1] > b[-1]:
			a.pop()
		else:
			B += b[-1]
			b.pop()
print(A - B)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
j = 0
k = 0
ans = 0
for i in range(2 * n):
	if i % 2 == 0:
		if len(a) > 0 and len(b) > 0 and (a[-1] > b[-1]):
			ans += a[-1]
			del a[-1]
		elif len(b) > 0:
			del b[-1]
		else:
			ans += a[-1]
			del a[-1]
	elif len(a) > 0 and len(b) > 0 and (b[-1] > a[-1]):
		ans -= b[-1]
		del b[-1]
	elif len(a) > 0:
		del a[-1]
	else:
		ans -= b[-1]
		del b[-1]
print(ans)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
na = n
nb = n
asum = 0
bsum = 0
for i in range(n):
	if nb == 0:
		asum += a[-1]
		a.pop()
		na -= 1
	elif na >= 1 and a[-1] > b[-1]:
		asum += a[-1]
		a.pop()
		na -= 1
	else:
		b.pop()
		nb -= 1
	if na == 0:
		bsum += b[-1]
		b.pop()
		nb -= 1
	elif nb >= 1 and a[-1] < b[-1]:
		bsum += b[-1]
		b.pop()
		nb -= 1
	else:
		a.pop()
		na -= 1
print(asum - bsum)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
k = n - 1
j = n - 1
turn = 0
score = 0
for i in range(0, 2 * n):
	if k >= 0 and j >= 0:
		if turn == 0:
			if l1[k] >= l2[j]:
				score = score + l1[k]
				k = k - 1
				turn = 1
				continue
			else:
				j = j - 1
				turn = 1
				continue
		if turn == 1:
			if l2[j] >= l1[k]:
				score = score - l2[j]
				j = j - 1
				turn = 0
				continue
			else:
				k = k - 1
				turn = 0
				continue
	elif turn == 0:
		if k == -1:
			j = j - 1
			turn = 1
			continue
		else:
			score += l1[k]
			turn = 1
			k = k - 1
			continue
	elif j == -1:
		k = k - 1
		turn = 0
		continue
	else:
		score -= l2[j]
		j = j - 1
		turn = 0
		continue
print(score)


a = int(input())
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
b.sort()
c.sort()
score1 = 0
score2 = 0
while b != [] or c != []:
	if b == []:
		c.pop(-1)
	elif c == []:
		score1 += b.pop(-1)
	elif b[-1] >= c[-1]:
		score1 += b.pop(-1)
	elif b[-1] < c[-1]:
		c.pop(-1)
	if b == [] and c == []:
		break
	elif b == []:
		score2 += c.pop(-1)
	elif c == []:
		b.pop(-1)
	elif b[-1] >= c[-1]:
		b.pop(-1)
	elif b[-1] < c[-1]:
		score2 += c.pop(-1)
print(score1 - score2)


def mi():
	return map(int, input().split())
n = int(input())
a = list(mi())
b = list(mi())
a.sort(reverse=True)
b.sort(reverse=True)
(i, j) = (0, 0)
(sa, sb) = (0, 0)
for k in range(2 * n):
	if k & 1:
		if j == n:
			a[i] = 0
			i += 1
			continue
		if i == n:
			sb += b[j]
			j += 1
			continue
		if b[j] < a[i]:
			a[i] = 0
			i += 1
		else:
			sb += b[j]
			b[j] = 0
			j += 1
	else:
		if i == n:
			b[j] = 0
			j += 1
			continue
		if j == n:
			sa += a[i]
			i += 1
			continue
		if a[i] < b[j]:
			b[j] = 0
			j += 1
		else:
			sa += a[i]
			a[i] = 0
			i += 1
print(sa - sb)


n = int(input())
a = sorted(list(map(int, input().split(' '))), reverse=True)
b = sorted(list(map(int, input().split(' '))), reverse=True)
A = 0
B = 0
while a != [] or b != []:
	if b == []:
		A += a[0]
		del a[0]
		if a != []:
			del a[0]
	elif a == []:
		del b[0]
		if b != []:
			B += b[0]
			del b[0]
	elif a[0] >= b[0]:
		A += a[0]
		del a[0]
		if a == []:
			B += b[0]
			del b[0]
		elif b[0] >= a[0]:
			B += b[0]
			del b[0]
		else:
			del a[0]
	elif b[0] > a[0]:
		del b[0]
		if b == []:
			del a[0]
		elif b[0] >= a[0]:
			B += b[0]
			del b[0]
		else:
			del a[0]
print(A - B)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(sa, sb) = (0, 0)
a.sort()
b.sort()
(la, lb) = (n, n)
f = 0
while la > 0 and lb > 0:
	if not f:
		if a[-1] >= b[-1]:
			sa += a[-1]
			a.pop()
			la -= 1
			f = 1
		else:
			b.pop()
			lb -= 1
			f = 1
	elif b[-1] >= a[-1]:
		sb += b[-1]
		b.pop()
		lb -= 1
		f = 0
	else:
		a.pop()
		la -= 1
		f = 0
if not f:
	if la > 0:
		for i in range(la - 1, -1, -2):
			sa += a[i]
	else:
		for i in range(lb - 2, -1, -2):
			sb += b[i]
elif la > 0:
	for i in range(la - 2, -1, -2):
		sa += a[i]
else:
	for i in range(lb - 1, -1, -2):
		sb += b[i]
print(sa - sb)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
score1 = 0
score2 = 0
i = 1
j = 0
k = 0
while j < n and k < n:
	if i % 2 == 1 and a[j] > b[k]:
		score1 += a[j]
		j = j + 1
	elif i % 2 == 1 and a[j] <= b[k]:
		k = k + 1
	elif i % 2 == 0 and a[j] < b[k]:
		score2 += b[k]
		k = k + 1
	elif i % 2 == 0 and a[j] >= b[k]:
		j = j + 1
	i = i + 1
if i % 2 == 1 and j < n:
	for i in range(j, n, 2):
		score1 += a[i]
elif i % 2 == 0 and j < n:
	for i in range(j + 1, n, 2):
		score1 += a[i]
elif i % 2 == 0 and k < n:
	for i in range(k, n, 2):
		score2 += b[i]
elif i % 2 == 1 and k < n:
	for i in range(k + 1, n, 2):
		score2 += b[i]
print(score1 - score2)


import sys
import math
import bisect

def solve(A, B):
	n = len(A)
	A.sort(reverse=True)
	B.sort(reverse=True)
	i = 0
	j = 0
	ans = [0] * 2
	while i < n or j < n:
		if (i + j) % 2 == 0:
			if i < n and j == n:
				ans[0] += A[i]
				i += 1
			elif i == n and j < n:
				j += 1
			elif A[i] >= B[j]:
				ans[0] += A[i]
				i += 1
			else:
				j += 1
		elif i < n and j == n:
			i += 1
		elif i == n and j < n:
			ans[1] += B[j]
			j += 1
		elif A[i] >= B[j]:
			i += 1
		else:
			ans[1] += B[j]
			j += 1
	return ans[0] - ans[1]

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B)
	print(ans)
main()


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
d_sc = 0
while len(l1) or len(l2):
	if len(l1):
		if len(l2):
			if l1[-1] > l2[-1]:
				d_sc += l1[-1]
				l1.pop()
			else:
				l2.pop()
		else:
			d_sc += l1[-1]
			l1.pop()
	else:
		l2.pop()
	if len(l1):
		if len(l2):
			if l1[-1] > l2[-1]:
				l1.pop()
			else:
				d_sc -= l2[-1]
				l2.pop()
		else:
			l1.pop()
	else:
		d_sc -= l2[-1]
		l2.pop()
print(d_sc)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort(reverse=True)
	(ua, ub) = ([0] * n, [0] * n)
	idx1 = idx2 = 0
	for i in range(n):
		if idx2 == n or (idx1 < n and b[idx2] <= a[idx1]):
			ua[idx1] = 1
			idx1 += 1
		else:
			idx2 += 1
		if idx1 == n or (idx2 < n and a[idx1] <= b[idx2]):
			ub[idx2] = 1
			idx2 += 1
		else:
			idx1 += 1
	sa = sb = 0
	for i in range(n):
		if ua[i]:
			sa += a[i]
		if ub[i]:
			sb += b[i]
	print(sa - sb)
main()


from math import inf as inf
from math import *
from collections import *
import sys
input = sys.stdin.readline
t = 1
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split())) + [0]
	b = list(map(int, input().split())) + [0]
	a.sort(reverse=True)
	b.sort(reverse=True)
	(i, j) = (0, 0)
	s = 0
	while i < n or j < n:
		if a[i] > b[j]:
			s += a[i]
			i += 1
		else:
			j += 1
		if a[i] > b[j]:
			i += 1
		else:
			s -= b[j]
			j += 1
	print(s)


n = int(input())
a = [int(num) for num in input().split()]
b = [int(num) for num in input().split()]
(sa, sb) = (0, 0)
a.sort()
b.sort()
turn = 0
while a and b:
	if turn == 0:
		if a[-1] >= b[-1]:
			sa += a.pop()
		else:
			b.pop()
	elif b[-1] >= a[-1]:
		sb += b.pop()
	else:
		a.pop()
	turn = (turn + 1) % 2
while a:
	if turn == 0:
		sa += a.pop()
	else:
		a.pop()
	turn = (turn + 1) % 2
while b:
	if turn == 0:
		b.pop()
	else:
		sb += b.pop()
	turn = (turn + 1) % 2
print(sa - sb)


(n, a, b, s) = (int(input()), sorted(map(int, input().split())), sorted(map(int, input().split())), 0)
for i in range(2 * n):
	if i & 1:
		if not a:
			s -= b.pop()
		elif not b:
			a.pop()
		elif b[-1] > a[-1]:
			s -= b.pop()
		else:
			a.pop()
	elif not a:
		b.pop()
	elif not b:
		s += a.pop()
	elif b[-1] > a[-1]:
		b.pop()
	else:
		s += a.pop()
print(s)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
B.insert(0, 0)
A.insert(0, 0)
a = 0
b = 0
for i in range(n):
	if A[-1] < B[-1]:
		B.pop()
	else:
		a += A[-1]
		A.pop()
	if A[-1] > B[-1]:
		A.pop()
	else:
		b += B[-1]
		B.pop()
print(a - b)


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import *
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = I()
(a, b) = (sorted(lint()), sorted(lint()))
(A, B) = (0, 0)
for i in range(2 * n):
	if i % 2 == 0:
		if not b or (a and a[-1] >= b[-1]):
			A += a[-1]
			a.pop()
		else:
			b.pop()
	elif not a or (b and b[-1] >= a[-1]):
		B += b[-1]
		b.pop()
	else:
		a.pop()
print(A - B)
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


n = int(input())
aa = sorted(list(map(int, input().split(' '))))
bb = sorted(list(map(int, input().split(' '))))
res = 0
ai = n - 1
bi = n - 1
while ai >= 0 or bi >= 0:
	an = -1 if ai < 0 else aa[ai]
	bn = -1 if bi < 0 else bb[bi]
	if an >= bn:
		res += an
		ai -= 1
	else:
		bi -= 1
	an = -1 if ai < 0 else aa[ai]
	bn = -1 if bi < 0 else bb[bi]
	if an <= bn:
		res -= bn
		bi -= 1
	else:
		ai -= 1
print(res)


def main():
	(_, r) = (input(), 0)
	(aa, bb) = (sorted(map(int, input().split()), reverse=True) for _ in 'ab')
	aa.append(0)
	bb.append(0)
	i = j = 0
	while True:
		if aa[i] > bb[j]:
			r += aa[i]
			i += 1
		elif aa[i]:
			j += 1
		else:
			r -= sum(bb[j + 1::2])
			break
		if aa[i] < bb[j]:
			r -= bb[j]
			j += 1
		elif bb[j]:
			i += 1
		else:
			r += sum(aa[i + 1::2])
			break
	print(r)
main()


n = int(input())
a = [int(x) for x in input().split()]
a += [0] * n
b = [int(x) for x in input().split()]
b += [0] * n
(a1, a2) = (0, 0)
a.sort()
b.sort()
a.reverse()
b.reverse()
(i, j, k) = (0, 0, 0)
f = 0
while k < 2 * n:
	k += 1
	if not f:
		if a[i] >= b[j]:
			a1 += a[i]
			i += 1
		else:
			j += 1
	elif b[j] >= a[i]:
		a2 += b[j]
		j += 1
	else:
		i += 1
	f ^= 1
print(a1 - a2)


n = int(input())
aa = [0] + sorted(map(int, input().split()))
bb = [0] + sorted(map(int, input().split()))
a = b = n
sa = sb = c = 0
for i in range(2 * n - 1, -1, -1):
	if c % 2 == 0:
		if aa[a] >= bb[b]:
			sa += aa[a]
			a -= 1
		else:
			b -= 1
	elif bb[b] >= aa[a]:
		sb += bb[b]
		b -= 1
	else:
		a -= 1
	c += 1
print(sa - sb)


def solv(al, bl):
	al.sort()
	bl.sort()
	asco = 0
	bsco = 0
	turn = 0
	while len(al) > 0 and len(bl) > 0:
		if al[-1] < bl[-1]:
			del bl[-1]
		else:
			asco += al[-1]
			del al[-1]
		turn = 1
		if len(al) > 0 and len(bl) > 0:
			if bl[-1] < al[-1]:
				del al[-1]
			else:
				bsco += bl[-1]
				del bl[-1]
			turn = 0
	if len(al) > 0:
		if turn == 0:
			for i in range(len(al) - 1, -1, -2):
				asco += al[i]
		else:
			for i in range(len(al) - 2, -1, -2):
				asco += al[i]
	if len(bl) > 0:
		if turn == 1:
			for i in range(len(bl) - 1, -1, -2):
				bsco += bl[i]
		else:
			for i in range(len(bl) - 2, -1, -2):
				bsco += bl[i]
	return asco - bsco
ttl = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
print(solv(al, bl))


from collections import Counter, defaultdict, deque
get = lambda : int(input())
read = lambda : list(map(int, input().split()))
mod = 10 ** 9 + 7
inf = float('inf')
n = get()
a = read()
b = read()
a.sort()
b.sort()
ra = rb = 0
for turn in range(2 * n):
	if turn % 2 == 0:
		if not b or (a and a[-1] > b[-1]):
			ra += a.pop()
		else:
			b.pop()
	if turn % 2 == 1:
		if not a or (b and b[-1] > a[-1]):
			rb += b.pop()
		else:
			a.pop()
print(ra - rb)


n = int(input())
coins = []
coins.append(sorted([int(x) for x in input().split()]))
coins.append(sorted([int(x) for x in input().split()]))
score = [0, 0]
turn = 0
while len(coins[0]) or len(coins[1]):
	curr_player = coins[turn]
	next_player = coins[(turn + 1) % 2]
	if len(curr_player) == 0:
		next_player.pop()
	elif len(next_player) == 0:
		score[turn] += curr_player[-1]
		curr_player.pop()
	elif curr_player[-1] > next_player[-1]:
		score[turn] += curr_player[-1]
		curr_player.pop()
	else:
		next_player.pop()
	turn = (turn + 1) % 2
print(score[0] - score[1])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
(an, bn) = (0, 0)
(i, j) = (0, 0)
flag = True
while i < n and j < n:
	if flag == True:
		flag = False
		if a[i] < b[j]:
			j += 1
		else:
			an += a[i]
			i += 1
	elif flag == False:
		flag = True
		if a[i] > b[j]:
			i += 1
		else:
			bn += b[j]
			j += 1
while i < n:
	if flag == True:
		an += a[i]
	i += 1
	flag = not flag
while j < n:
	if flag == False:
		bn += b[j]
	j += 1
	flag = not flag
print(an - bn)


n = int(input())
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
(x, y) = (0, 0)
while len(a) > 0 or len(b) > 0:
	if len(a) > 0 and len(b) > 0:
		if a[-1] > b[-1]:
			x += a.pop()
		else:
			b.pop()
	elif len(a) > 0 and len(b) == 0:
		x += a.pop()
	elif len(a) == 0 and len(b) > 0:
		b.pop()
	if len(a) > 0 and len(b) > 0:
		if b[-1] > a[-1]:
			y += b.pop()
		else:
			a.pop()
	elif len(a) > 0 and len(b) == 0:
		a.pop()
	elif len(a) == 0 and len(b) > 0:
		y += b.pop()
print(x - y)


t = int(input())
nums1 = [int(i) for i in input().split()]
nums2 = [int(i) for i in input().split()]
nums1.append(0)
nums2.append(0)
trev1 = trev2 = sum1 = sum2 = 0
nums1 = sorted(nums1)
nums2 = sorted(nums2)
nums1 = nums1[::-1]
nums2 = nums2[::-1]
for i in range(t):
	if nums1[trev1] > nums2[trev2]:
		sum1 += nums1[trev1]
		trev1 += 1
	elif trev2 < t:
		trev2 += 1
	if nums2[trev2] > nums1[trev1]:
		sum2 += nums2[trev2]
		trev2 += 1
	elif trev1 < t:
		trev1 += 1
print(sum1 - sum2)


I = lambda : map(int, input().split())
n = int(input())
a = sorted(list(I()))
b = sorted(list(I()))
sa = sb = 0
for i in range(2 * n):
	if i % 2 == 0:
		if len(a) > 0 and len(b) > 0 and (a[-1] > b[-1]):
			sa += a[-1]
			del a[-1]
		elif len(b) > 0:
			del b[-1]
		else:
			sa += a[-1]
			del a[-1]
	elif len(a) > 0 and len(b) > 0 and (b[-1] > a[-1]):
		sb += b[-1]
		del b[-1]
	elif len(a) > 0:
		del a[-1]
	else:
		sb += b[-1]
		del b[-1]
print(sa - sb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
(sa, sb, h) = (0, 0, 1)
while len(a) + len(b) != 0:
	if h == 1:
		if len(a) != 0 and len(b) != 0:
			if a[len(a) - 1] > b[len(b) - 1]:
				sa += a[len(a) - 1]
				del a[len(a) - 1]
			else:
				del b[len(b) - 1]
		elif len(a) == 0:
			del b[len(b) - 1]
		else:
			sa += a[len(a) - 1]
			del a[len(a) - 1]
		h = (h + 1) % 2
	else:
		if len(a) != 0 and len(b) != 0:
			if b[len(b) - 1] > a[len(a) - 1]:
				sb += b[len(b) - 1]
				del b[len(b) - 1]
			else:
				del a[len(a) - 1]
		elif len(b) == 0:
			del a[len(a) - 1]
		else:
			sb += b[len(b) - 1]
			del b[len(b) - 1]
		h = (h + 1) % 2
print(sa - sb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
a = a[::-1]
b = b[::-1]
(ptra, ptrb) = (0, 0)
(ptsa, ptsb) = (0, 0)
while ptra < n or ptrb < n:
	if ptra == n:
		if (ptra + ptrb) % 2 == 0:
			ptrb += 1
		else:
			ptsb += b[ptrb]
			ptrb += 1
	elif ptrb == n:
		if (ptra + ptrb) % 2 == 0:
			ptsa += a[ptra]
			ptra += 1
		else:
			ptra += 1
	elif a[ptra] > b[ptrb]:
		if (ptra + ptrb) % 2 == 0:
			ptsa += a[ptra]
			ptra += 1
		else:
			ptra += 1
	elif (ptra + ptrb) % 2 == 0:
		ptrb += 1
	else:
		ptsb += b[ptrb]
		ptrb += 1
print(ptsa - ptsb)


from sys import stdin
n = int(input())
a = [int(x) for x in stdin.readline().split()]
b = [int(x) for x in stdin.readline().split()]
li1 = sorted(a)
li2 = sorted(b)
(s1, s2) = (0, 0)
for k in range(2 * n):
	(i, j) = (len(li1) - 1, len(li2) - 1)
	if k % 2 == 0:
		if i >= 0 and j >= 0 and (li1[i] > li2[j]):
			s1 += li1[i]
			li1.pop()
		elif j < 0:
			s1 += li1[i]
			li1.pop()
		else:
			li2.pop()
	elif j >= 0 and i >= 0 and (li2[j] > li1[i]):
		s2 += li2[j]
		li2.pop()
	elif i < 0:
		s2 += li2[j]
		li2.pop()
	else:
		li1.pop()
print(s1 - s2)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
(i, j) = (0, 0)
(sumA, sumB) = (0, 0)
turn = 0
while i < n and j < n:
	if turn == 0:
		if A[i] > B[j]:
			sumA += A[i]
			i += 1
		else:
			j += 1
		turn = 1
	else:
		if B[j] > A[i]:
			sumB += B[j]
			j += 1
		else:
			i += 1
		turn = 0
if i < n:
	if turn == 0:
		sumA += sum(A[i::2])
	else:
		sumA += sum(A[i + 1::2])
elif j < n:
	if turn == 0:
		sumB += sum(B[j + 1::2])
	else:
		sumB += sum(B[j::2])
print(sumA - sumB)


n = int(input())
my_arr = list(map(int, input().split()))
opp_arr = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append([my_arr[i], 1])
for i in range(n):
	arr.append([opp_arr[i], 0])
arr = sorted(arr, key=lambda x: x[0])
my_score = 0
opp_score = 0
c = 0
while len(arr) != 0:
	if c == 0:
		if arr[-1][1] == 1:
			my_score += arr[-1][0]
		arr.pop()
	else:
		if arr[-1][1] == 0:
			opp_score += arr[-1][0]
		arr.pop()
	c = c ^ 1
print(my_score - opp_score)


import sys
from collections import deque
import bisect
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	p = 0
	som1 = 0
	som2 = 0
	while len(a) > 0 or len(b) > 0:
		if p == 0:
			if len(a) > 0 and len(b) > 0:
				if a[-1] >= b[-1]:
					som1 += a.pop()
				else:
					b.pop()
				p = p ^ 1
				continue
			if len(a) > 0:
				som1 += a.pop()
				p = p ^ 1
				continue
			b.pop()
			p = p ^ 1
			continue
		if len(a) > 0 and len(b) > 0:
			if b[-1] >= a[-1]:
				som2 += b.pop()
			else:
				a.pop()
			p = p ^ 1
			continue
		if len(b) > 0:
			som2 += b.pop()
			p = p ^ 1
			continue
		a.pop()
		p = p ^ 1
		continue
	print(som1 - som2)


n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
al.sort()
bl.sort()
sm = 0
while len(al) > 0 or len(bl) > 0:
	if len(al) > 0:
		a = al[-1]
	if len(bl) > 0:
		b = bl[-1]
	if a >= b and len(al) > 0:
		sm += a
		al.pop()
	elif len(bl) > 0:
		bl.pop()
	elif len(al) > 0:
		sm += a
		al.pop()
	else:
		break
	if len(al) > 0:
		a = al[-1]
	if len(bl) > 0:
		b = bl[-1]
	if b >= a and len(bl) > 0:
		sm -= b
		bl.pop()
	elif len(al) > 0:
		al.pop()
	elif len(bl) > 0:
		sm -= b
		bl.pop()
	else:
		break
print(sm)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
l = 0
r = 0
i = 0
while len(a) != 0 and len(b) != 0:
	if i % 2 == 0:
		if a[-1] > b[-1]:
			l += a[-1]
			del a[-1]
		else:
			del b[-1]
		i += 1
	else:
		if b[-1] > a[-1]:
			r += b[-1]
			del b[-1]
		else:
			del a[-1]
		i += 1
if len(a) == 0:
	while len(b) != 0:
		if i % 2 == 0:
			del b[-1]
			i += 1
		else:
			r += b[-1]
			del b[-1]
			i += 1
elif len(b) == 0:
	while len(a) != 0:
		if i % 2 == 0:
			l += a[-1]
			del a[-1]
			i += 1
		else:
			del a[-1]
			i += 1
print(l - r)


import sys
import math
lines = sys.stdin.read().splitlines()
n = [int(x) for x in lines[0].split()][0]
spisok1 = [int(x) for x in lines[1].split()]
spisok2 = [int(x) for x in lines[2].split()]
spisok1 = sorted(spisok1)
spisok2 = sorted(spisok2)
i = len(spisok1) - 1
j = len(spisok2) - 1
diff = 0
turn = 1
while i >= 0 or j >= 0:
	if turn == 1:
		if i < 0:
			j -= 1
		elif j < 0 or spisok1[i] > spisok2[j]:
			diff += spisok1[i]
			i -= 1
		else:
			j -= 1
		turn = 0
	else:
		turn = 1
		if j < 0:
			i -= 1
		elif i < 0 or spisok2[j] > spisok1[i]:
			diff -= spisok2[j]
			j -= 1
		else:
			i -= 1
print(diff)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
ac = 0
bc = 0
turn = 1
while len(a) > 0 or len(b) > 0:
	if turn == 1:
		if len(a) == 0 and len(b) > 0:
			b.pop()
		elif len(a) > 0 and len(b) == 0:
			ac += a[-1]
			a.pop()
		elif a[-1] >= b[-1]:
			ac += a[-1]
			a.pop()
		else:
			b.pop()
		turn = 2
	else:
		if len(b) == 0 and len(a) > 0:
			a.pop()
		elif len(b) > 0 and len(a) == 0:
			bc += b[-1]
			b.pop()
		elif b[-1] >= a[-1]:
			bc += b[-1]
			b.pop()
		else:
			a.pop()
		turn = 1
print(ac - bc)


n = int(input())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
aa = bb = 0
oe = 1
cnta = cntb = 0
while aa < len(a) or bb < len(b):
	if oe & 1:
		if aa < len(a) and bb < len(b) and (a[aa] > b[bb]):
			cnta += a[aa]
			aa += 1
		elif aa < len(a) and bb < len(b) and (a[aa] <= b[bb]):
			bb += 1
		elif aa < len(a):
			cnta += a[aa]
			aa += 1
		elif bb < len(b):
			bb += 1
	elif aa < len(a) and bb < len(b) and (a[aa] < b[bb]):
		cntb += b[bb]
		bb += 1
	elif aa < len(a) and bb < len(b) and (a[aa] >= b[bb]):
		aa += 1
	elif bb < len(b):
		cntb += b[bb]
		bb += 1
	elif aa < len(a):
		aa += 1
	oe = 1 - oe
print(cnta - cntb)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l1 = sorted(il(), reverse=True) + [0]
l2 = sorted(il(), reverse=True) + [0]
(i, j, sa, sb) = (0, 0, 0, 0)
while i != n or j != n:
	if l1[i] > l2[j]:
		sa += l1[i]
		i += 1
	else:
		j += 1
	if l2[j] > l1[i]:
		sb += l2[j]
		j += 1
	else:
		i += 1
print(sa - sb)


import sys
import string

def ria():
	return [int(i) for i in input().split()]
n = ria()[0]
ar1 = ria()
ar2 = ria()
p1 = 0
p2 = 0
ar1.sort()
ar2.sort()
ar1 = [i for i in reversed(ar1)]
ar2 = [i for i in reversed(ar2)]
pp1 = 0
pp2 = 0
for i in range(n):
	if pp1 < n:
		if pp2 >= n or ar1[pp1] >= ar2[pp2]:
			p1 += ar1[pp1]
			pp1 += 1
		else:
			pp2 += 1
	elif pp2 < n:
		pp2 += 1
	if pp2 < n:
		if pp1 >= n or ar1[pp1] <= ar2[pp2]:
			p2 += ar2[pp2]
			pp2 += 1
		else:
			pp1 += 1
	elif pp1 < n:
		pp1 += 1
print(p1 - p2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
a1 = 0
b1 = 0
t = 0
for i in range(2 * n):
	if t == 0:
		if len(a) > 0 and len(b) > 0:
			if a[-1] > b[-1]:
				a1 += a[-1]
				a.pop()
			else:
				b.pop()
		elif len(a) > 0:
			a1 += a[-1]
			a.pop()
		else:
			b.pop()
		t = 1
	else:
		if len(a) > 0 and len(b) > 0:
			if b[-1] > a[-1]:
				b1 += b[-1]
				b.pop()
			else:
				a.pop()
		elif len(a) > 0:
			a.pop()
		else:
			b1 += b[-1]
			b.pop()
		t = 0
print(a1 - b1)


n = int(input())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
first.sort(reverse=True)
second.sort(reverse=True)
i = 0
j = 0
sum_a = 0
sum_b = 0
while i < n or j < n:
	if i >= n:
		j += 1
	if j >= n:
		sum_a += first[i]
		i += 1
	if i < n and j < n:
		other = second[j]
		cur = first[i]
		if cur > other:
			i += 1
			sum_a += cur
		else:
			j += 1
	if i < n or j < n:
		if i >= n:
			sum_b += second[j]
			j += 1
			continue
		if j >= n:
			i += 1
			continue
		other = first[i]
		cur = second[j]
		if cur > other:
			j += 1
			sum_b += cur
		else:
			i += 1
print(sum_a - sum_b)


n = int(input())
listA = [int(i) for i in input().split()]
listB = [int(i) for i in input().split()]
listA = sorted(listA)
listB = sorted(listB)
accountA = 0
accountB = 0
hod = 0
index = 0
while len(listA) != 0 or len(listB) != 0:
	hod = index % 2
	if len(listA) != 0:
		maxA = listA[-1]
	else:
		maxA = -1000
	if len(listB) != 0:
		maxB = listB[-1]
	else:
		maxB = -1000
	if hod == 0:
		if maxA > maxB:
			accountA += maxA
			listA.pop()
		else:
			listB.pop()
	if hod == 1:
		if maxB > maxA:
			accountB += maxB
			listB.pop()
		else:
			listA.pop()
	index += 1
print(accountA - accountB)


n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
i = n - 1
j = n - 1
true = 0
A = B = 0
while i >= 0 and j >= 0:
	if true == 0:
		if a[i] < b[j]:
			j -= 1
		else:
			A += a[i]
			i -= 1
	elif b[j] < a[i]:
		i -= 1
	else:
		B += b[j]
		j -= 1
	true ^= 1
if i != -1:
	if true == 0:
		while i >= 0:
			A += a[i]
			i -= 2
	else:
		i -= 1
		while i >= 0:
			A += a[i]
			i -= 2
elif j != -1:
	if true == 0:
		j -= 1
		while j >= 0:
			B += b[j]
			j -= 2
	else:
		while j >= 0:
			B += b[j]
			j -= 2
print(A - B)


n = int(input())
lst1 = [int(x) for x in input().split()] + [0]
lst2 = [int(x) for x in input().split()] + [0]
a = 0
b = 0
i = 0
lst1.sort()
lst2.sort()
while len(lst1) > 1 or len(lst2) > 1:
	if i % 2 == 0:
		if lst1[-1] > lst2[-1]:
			a += lst1[-1]
			del lst1[-1]
		else:
			del lst2[-1]
	elif lst1[-1] < lst2[-1]:
		b += lst2[-1]
		del lst2[-1]
	else:
		del lst1[-1]
	i += 1
print(a - b)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
(asc, bsc) = (0, 0)
(i, j) = (n - 1, n - 1)
while i >= 0 or j >= 0:
	if i >= 0:
		if j >= 0:
			if a[i] > b[j]:
				asc += a[i]
				i -= 1
			else:
				j -= 1
		else:
			asc += a[i]
			i -= 1
	else:
		j -= 1
	if j >= 0:
		if i >= 0:
			if b[j] > a[i]:
				bsc += b[j]
				j -= 1
			else:
				i -= 1
		else:
			bsc += b[j]
			j -= 1
	else:
		i -= 1
print(asc - bsc)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
turn = 0
a = 0
b = 0
while len(l1) != 0 or len(l2) != 0:
	max1 = 0
	max2 = 0
	if len(l1) != 0:
		max1 = l1[-1]
	if len(l2) != 0:
		max2 = l2[-1]
	if max1 > max2:
		if turn == 0:
			a += max1
		del l1[-1]
	else:
		if turn == 1:
			b += max2
		del l2[-1]
	turn = 1 - turn
print(a - b)


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
arr.sort(reverse=True)
brr.sort(reverse=True)
(i, j, a, b, count) = (0, 0, 0, 0, 0)
while i < n and j < n:
	if arr[i] == brr[j]:
		if count % 2 == 0:
			a += arr[i]
			i += 1
		else:
			b += brr[j]
			j += 1
	elif arr[i] < brr[j]:
		j += 1
		if count % 2 == 1:
			b += brr[j - 1]
	else:
		i += 1
		if count % 2 == 0:
			a += arr[i - 1]
	count += 1
if j == n:
	for k in range(i, n):
		if count % 2 == 0:
			a += arr[k]
		count += 1
elif i == n:
	for k in range(j, n):
		if count % 2 == 1:
			b += brr[k]
		count += 1
print(a - b)


n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
(A, B) = (0, 0)
for i in range(2 * n):
	if i % 2 == 0:
		if not b or (a and a[-1] >= b[-1]):
			A += a[-1]
			del a[-1]
		else:
			del b[-1]
	elif not a or (b and b[-1] >= a[-1]):
		B += b[-1]
		del b[-1]
	else:
		del a[-1]
print(A - B)


n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
(A_cnt, B_cnt) = (0, 0)
for i in range(2 * n):
	if i % 2 == 0:
		if len(A) == 0:
			del B[-1]
			continue
		elif len(B) == 0 or A[-1] >= B[-1]:
			A_cnt += A[-1]
			del A[-1]
		else:
			del B[-1]
	elif len(B) == 0:
		del A[-1]
		continue
	elif len(A) == 0 or B[-1] >= A[-1]:
		B_cnt += B[-1]
		del B[-1]
	else:
		del A[-1]
print(A_cnt - B_cnt)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
(i, j) = (n - 1, n - 1)
(sa, sb, t) = (0, 0, 0)
while i >= 0 and j >= 0:
	if a[i] >= b[j]:
		sa += a[i]
		i -= 1
		t = 1
	else:
		j -= 1
		t = 1
	if i < 0 or j < 0:
		break
	if b[j] >= a[i]:
		sb += b[j]
		j -= 1
		t = 0
	else:
		i -= 1
		t = 0
while i >= 0:
	if t == 0:
		sa += a[i]
		t = 1
	else:
		t = 0
	i -= 1
while j >= 0:
	if t == 1:
		sb += b[j]
		t = 0
	else:
		t = 1
	j -= 1
print(sa - sb)


n = int(input())
a = [int(_) for _ in input().split(' ')]
b = [int(_) for _ in input().split(' ')]
a.sort(reverse=True)
b.sort(reverse=True)
diff = 0
i_a = 0
i_b = 0
turn_A = True
while i_a < n and i_b < n:
	if turn_A:
		if a[i_a] > b[i_b]:
			diff += a[i_a]
			i_a += 1
		else:
			i_b += 1
	elif b[i_b] > a[i_a]:
		diff -= b[i_b]
		i_b += 1
	else:
		i_a += 1
	turn_A = not turn_A
if not turn_A:
	i_a += 1
else:
	i_b += 1
while i_a < n:
	diff += a[i_a]
	i_a += 2
while i_b < n:
	diff -= b[i_b]
	i_b += 2
print(diff)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
mod = 10 ** 9 + 7
import heapq
n = int(input())
a = [-int(i) for i in input().split()] + [0] * 100000
b = [-int(i) for i in input().split()] + [0] * 100000
heapq.heapify(a)
heapq.heapify(b)
ans1 = 0
ans2 = 0
for i in range(2 * n):
	if i % 2 == 0:
		temp1 = -heapq.heappop(a)
		temp2 = -heapq.heappop(b)
		if temp2 > temp1:
			heapq.heappush(a, -temp1)
		else:
			ans1 += temp1
			heapq.heappush(b, -temp2)
	else:
		temp1 = -heapq.heappop(a)
		temp2 = -heapq.heappop(b)
		if temp2 < temp1:
			heapq.heappush(b, -temp2)
		else:
			ans2 += temp2
			heapq.heappush(a, -temp1)
print(ans1 - ans2)


n = int(input())
a = []
b = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
sum1 = 0
sum2 = 0
l1 = len(a)
l2 = len(b)
while l1 > 0 or l2 > 0:
	if l1 == 0:
		a1 = 0
	else:
		a1 = a[l1 - 1]
	if l2 == 0:
		b1 = 0
	else:
		b1 = b[l2 - 1]
	if a1 <= b1:
		del b[l2 - 1]
		l2 = l2 - 1
	else:
		sum1 = sum1 + a1
		del a[l1 - 1]
		l1 = l1 - 1
	if l1 == 0:
		a1 = 0
	else:
		a1 = a[l1 - 1]
	if l2 == 0:
		b1 = 0
	else:
		b1 = b[l2 - 1]
	if b1 <= a1:
		del a[l1 - 1]
		l1 = l1 - 1
	else:
		sum2 = sum2 + b1
		del b[l2 - 1]
		l2 = l2 - 1
print(sum1 - sum2)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	a = sorted(list(map(int, input().split())), reverse=True)
	b = sorted(list(map(int, input().split())), reverse=True)
	i = 0
	j = 0
	sa = 0
	sb = 0
	turn = 0
	while i < len(a) or j < len(b):
		if turn == 0:
			if i < len(a):
				if j < len(b) and a[i] < b[j]:
					j += 1
				else:
					sa += a[i]
					i += 1
			else:
				j += 1
			turn ^= 1
		else:
			if j < len(b):
				if i < len(a) and b[j] < a[i]:
					i += 1
				else:
					sb += b[j]
					j += 1
			else:
				i += 1
			turn ^= 1
	print(sa - sb)
t = 1
for _ in range(t):
	main()


n = int(input().strip())
aa = sorted([int(_) for _ in input().strip().split()])
ba = sorted([int(_) for _ in input().strip().split()])
sa = 0
sb = 0
aa.insert(0, 0)
ba.insert(0, 0)
for i in range(n):
	if aa[-1] > ba[-1]:
		sa += aa.pop(-1)
	else:
		ba.pop(-1)
	if ba[-1] > aa[-1]:
		sb += ba.pop(-1)
	else:
		aa.pop(-1)
print(sa - sb)


n = int(input())
mas = [sorted(list(map(int, input().split())), reverse=True), sorted(list(map(int, input().split())), reverse=True)]
hod = 0
count = [0, 0]
hod_idx = 0
versus_hod = 1
versushod_idx = 0
while versushod_idx < len(mas[versus_hod]) or hod_idx < len(mas[hod]):
	versus_hod = (hod + 1) % 2
	if versushod_idx >= len(mas[versus_hod]):
		count[hod] += mas[hod][hod_idx]
		hod_idx += 1
	elif hod_idx >= len(mas[hod]):
		versushod_idx += 1
	elif mas[hod][hod_idx] <= mas[versus_hod][versushod_idx]:
		versushod_idx += 1
	elif mas[hod][hod_idx] > mas[versus_hod][versushod_idx]:
		count[hod] += mas[hod][hod_idx]
		hod_idx += 1
	hod = versus_hod
	(hod_idx, versushod_idx) = (versushod_idx, hod_idx)
print(count[0] - count[1])


from collections import defaultdict as dd
import heapq as hq
n = int(input())
l1 = [int(i) for i in input().split(' ')]
l = [-i for i in l1] + [0] * 100000
m1 = [int(i) for i in input().split(' ')]
m = [-i for i in m1] + [0] * 100000
if 1:
	hq.heapify(l)
	hq.heapify(m)
	(a, b) = (0, 0)
	for i in range(2 * n):
		if i % 2 == 0:
			x = hq.heappop(l)
			y = hq.heappop(m)
			if -x > -y:
				a += -x
				hq.heappush(m, y)
			else:
				hq.heappush(l, x)
		else:
			x = hq.heappop(l)
			y = hq.heappop(m)
			if -y > -x:
				b += -y
				hq.heappush(l, x)
			else:
				hq.heappush(m, y)
	print(a - b)


def sort_(A, B):
	A.sort()
	B.sort()

def game(A, B):
	aScore = 0
	bScore = 0
	while A or B:
		aScore = bigger(A, B, aScore)
		bScore = bigger(B, A, bScore)
	return aScore - bScore

def bigger(player, opponent, score):
	if player:
		if opponent and player[-1] >= opponent[-1]:
			score += player[-1]
			del player[-1]
		else:
			score = take_opp(opponent, player, score)
	else:
		score = take_opp(opponent, player, score)
	return score

def take_opp(opp, p1, score):
	if opp:
		del opp[-1]
	elif p1:
		score += p1[-1]
		del p1[-1]
	return score
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
sort_(A, B)
print(game(A, B))


n = int(input())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s1.sort()
s2.sort()
s1.reverse()
s2.reverse()
q = w = t = 0
p = False
while q < n and w < n:
	p = not p
	if p:
		if s1[q] > s2[w]:
			t += s1[q]
			q += 1
		else:
			w += 1
	elif s2[w] > s1[q]:
		t -= s2[w]
		w += 1
	else:
		q += 1
if q == n:
	for i in range(w, n):
		p = not p
		if not p:
			t -= s2[i]
else:
	for i in range(q, n):
		p = not p
		if p:
			t += s1[i]
print(t)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
b = list(map(int, input().split(' ')))
b.sort()
chk = 1
ans = 0
ans1 = 0
while len(a) != 0 or len(b) != 0:
	if chk == 1:
		if len(a) == 0:
			b.pop()
		elif len(b) > 0:
			if a[len(a) - 1] < b[len(b) - 1]:
				b.pop()
			else:
				ans += a[len(a) - 1]
				a.pop()
		else:
			ans += a[len(a) - 1]
			a.pop()
	elif len(b) == 0:
		a.pop()
	elif len(a) > 0:
		if b[len(b) - 1] < a[len(a) - 1]:
			a.pop()
		else:
			ans1 += b[len(b) - 1]
			b.pop()
	else:
		ans1 += b[len(b) - 1]
		b.pop()
	chk = chk ^ 1
print(ans - ans1)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
print(sum(sorted(a + b)[::-2]) - sum(b))


from sys import stdin, exit
from os import getenv
if getenv('ACM_ENV') == 'local':
	stdin = open('input.txt', 'r')
n = int(stdin.readline())
a = sorted([int(x) for x in stdin.readline().split(' ')])
b = sorted([int(x) for x in stdin.readline().split(' ')])
ascore = 0
bscore = 0
while len(a) + len(b) > 0:
	ap = 0
	bp = 0
	if len(a) > 0:
		ap = a.pop()
	if len(b) > 0:
		bp = b.pop()
	if ap >= bp:
		ascore += ap
		if bp > 0:
			b.append(bp)
	elif ap > 0:
		a.append(ap)
	ap = 0
	bp = 0
	if len(a) > 0:
		ap = a.pop()
	if len(b) > 0:
		bp = b.pop()
	if ap > bp:
		if bp > 0:
			b.append(bp)
	else:
		bscore += bp
		if ap > 0:
			a.append(ap)
print(ascore - bscore)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s1 = s2 = 0
a.sort(reverse=True)
b.sort(reverse=True)
a.append(0)
b.append(0)
flag = 0
i = j = 0
while a[i] != 0 or b[j] != 0:
	if flag == 0:
		if a[i] > b[j]:
			s1 += a[i]
			i += 1
		else:
			j += 1
		flag = 1
	else:
		if b[j] > a[i]:
			s2 += b[j]
			j += 1
		else:
			i += 1
		flag = 0
print(s1 - s2)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.sort()
b.sort()
A = 0
B = 0
ca = n
cb = n
i = 1
while ca != 0 or cb != 0:
	if i % 2 != 0:
		if ca == 0:
			del b[-1]
			cb -= 1
		elif cb > 0 and b[-1] > a[-1]:
			del b[-1]
			cb -= 1
		else:
			A += a[-1]
			del a[-1]
			ca -= 1
	elif cb == 0:
		del a[-1]
		ca -= 1
	elif ca > 0 and a[-1] > b[-1]:
		del a[-1]
		ca -= 1
	else:
		B += b[-1]
		del b[-1]
		cb -= 1
	i += 1
print(A - B)


import math
n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
a.sort(reverse=True)
b.sort(reverse=True)
k = 0
sa = 0
sb = 0
while len(a) > 0 or len(b) > 0:
	if k % 2 == 0:
		if len(a) > 0 and len(b) > 0:
			if a[0] >= b[0]:
				sa += a[0]
				del a[0]
			else:
				del b[0]
		elif len(a) > 0:
			sa += a[0]
			del a[0]
		else:
			del b[0]
	elif len(b) > 0 and len(a) > 0:
		if b[0] >= a[0]:
			sb += b[0]
			del b[0]
		else:
			del a[0]
	elif len(b) > 0:
		sb += b[0]
		del b[0]
	else:
		del a[0]
	k += 1
print(sa - sb)


import math

def mi():
	return map(int, input().split(' '))
n = int(input())
a = list(mi())
b = list(mi())
a.sort(reverse=True)
b.sort(reverse=True)
suma = 0
sumb = 0
ai = 0
bi = 0
for i in range(n):
	if b[bi] > a[ai]:
		bi += 1
	else:
		suma += a[ai]
		ai += 1
	if a[ai] > b[bi]:
		ai += 1
	else:
		sumb += b[bi]
		bi += 1
	a.append(0)
	b.append(0)
print(suma - sumb)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
n = INT()
arr1 = LIST()
arr2 = LIST()
arr1.sort(reverse=True)
arr2.sort(reverse=True)
c = [0 for i in range(n)]
arr1 += c
arr2 += c
sma = 0
smb = 0
(i, j) = (0, 0)
for k in range(2 * n):
	if k % 2 == 0:
		if arr1[i] > arr2[j]:
			sma += arr1[i]
			i += 1
		else:
			j += 1
	elif arr2[j] > arr1[i]:
		smb += arr2[j]
		j += 1
	else:
		i += 1
print(sma - smb)


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
a.sort()
b.sort()
s1 = 0
s2 = 0
a = [0] * n + a
b = [0] * n + b
for i in range(n):
	if a[-1] >= b[-1]:
		s1 = s1 + a[-1]
		a.pop()
	else:
		b.pop()
	if b[-1] >= a[-1]:
		s2 = s2 + b[-1]
		b.pop()
	else:
		a.pop()
print(s1 - s2)


from sys import stdin
n = int(stdin.readline())
a = [(int(x), 1) for x in stdin.readline().split()]
a.extend([(int(x), 2) for x in stdin.readline().split()])
a.sort(reverse=True)
asum = bsum = 0
al = 0
for i in range(n):
	if a[al][1] == 1:
		asum += a[al][0]
	al += 1
	if a[al][1] == 2:
		bsum += a[al][0]
	al += 1
print(asum - bsum)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
(s1, s2) = (0, 0)
turn = 0
for i in range(2 * n):
	if turn == 0:
		if len(a) > 0 and len(b) > 0:
			if a[-1] > b[-1]:
				s1 += a[-1]
				a.pop()
			else:
				b.pop()
		elif len(a) > 0:
			s1 += a[-1]
			a.pop()
		else:
			b.pop()
		turn = 1
	else:
		if len(a) > 0 and len(b) > 0:
			if b[-1] > a[-1]:
				s2 += b[-1]
				b.pop()
			else:
				a.pop()
		elif len(a) > 0:
			a.pop()
		else:
			s2 += b[-1]
			b.pop()
		turn = 0
print(s1 - s2)


n = int(input().strip())
a1 = [int(__) for __ in input().strip().split()]
a2 = [int(__) for __ in input().strip().split()]
a1.sort(reverse=True)
a2.sort(reverse=True)
(i, j) = (0, 0)
ct = 0
(s1, s2) = (0, 0)
while True:
	if i == n and j == n:
		break
	elif ct % 2 == 0:
		if i == n:
			j += 1
		elif j == n:
			s1 += a1[i]
			i += 1
		elif a1[i] > a2[j]:
			s1 += a1[i]
			i += 1
		elif a1[i] == a2[j]:
			s1 += a1[i]
			i += 1
		else:
			j += 1
	elif j == n:
		i += 1
	elif i == n:
		s2 += a2[j]
		j += 1
	elif a2[j] > a1[i]:
		s2 += a2[j]
		j += 1
	elif a2[j] == a1[i]:
		s2 += a2[j]
		j += 1
	else:
		i += 1
	ct += 1
print(s1 - s2)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.sort()
b.sort()
i = n - 1
j = n - 1
sum1 = 0
sum2 = 0
while not (i < 0 and j < 0):
	if i >= 0 and a[i] > b[j] or j < 0:
		sum1 += a[i]
		i -= 1
	else:
		j -= 1
	if i < 0 and j < 0:
		break
	if j >= 0 and a[i] < b[j] or i < 0:
		sum2 += b[j]
		j -= 1
	else:
		i -= 1
print(sum1 - sum2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
diff = 0
turn = 0
i = 0
j = 0
while i < n or j < n:
	if turn == 0:
		if i < n and j < n:
			if a[i] >= b[j]:
				diff += a[i]
				i += 1
			else:
				j += 1
		elif i >= n:
			j += 1
		else:
			diff += a[i]
			i += 1
	if turn == 1:
		if i < n and j < n:
			if b[j] >= a[i]:
				diff -= b[j]
				j += 1
			else:
				i += 1
		elif i >= n:
			diff -= b[j]
			j += 1
		else:
			i += 1
	turn = turn ^ 1
print(diff)


n = int(input())
arra = list(map(int, input().split()))
arrb = list(map(int, input().split()))
arra.sort()
arrb.sort()
a = 0
b = 0
for i in range(2 * n):
	if i % 2 == 0:
		if len(arra) == 0:
			arrb.pop()
		elif len(arrb) == 0 or arra[-1] >= arrb[-1]:
			a += arra[-1]
			arra.pop()
		else:
			arrb.pop()
	elif len(arrb) == 0:
		arra.pop()
	elif len(arra) == 0 or arrb[-1] >= arra[-1]:
		b += arrb[-1]
		arrb.pop()
	else:
		arra.pop()
print(a - b)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(0)
b.append(0)
a.sort()
b.sort()
s1 = 0
s2 = 0
while len(a) > 1 or len(b) > 1:
	if a[-1] > b[-1]:
		s1 = s1 + a[-1]
		a.pop()
	else:
		b.pop()
	if a[-1] > b[-1]:
		a.pop()
	else:
		s2 = s2 + b[-1]
		b.pop()
print(s1 - s2)


from sys import stdin, stdout, setrecursionlimit
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm, accumulate
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
setrecursionlimit(10 ** 9)
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return input()

def num():
	return int(input())

def L():
	return list(sp())

def LF():
	return list(spf())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def spf():
	return map(int, input.readline().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def pmat2(A):
	for ele in A:
		for j in ele:
			print(j, end='')
		print()

def iseven(n):
	return n % 2 == 0

def seive(r):
	prime = [1 for i in range(r + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(r + 1):
		if prime[i]:
			for j in range(2 * i, r + 1, i):
				prime[j] = 0
	return prime
n = int(input())
a = sorted(L())
b = sorted(L())
(s1, s2) = (0, 0)
(i, j) = (n - 1, n - 1)
for _ in range(n):
	if (a[i] > b[j] or j < 0) and i >= 0:
		s1 += a[i]
		i -= 1
	else:
		j -= 1
	if (b[j] > a[i] or i < 0) and j >= 0:
		s2 += b[j]
		j -= 1
	else:
		i -= 1
print(s1 - s2)
endtime = time.time()


n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
score_a = 0
score_b = 0
step = 'a'
empty = False
while not empty:
	if a != [] and b != []:
		if step == 'a' and a[0] > b[0]:
			score_a += a[0]
			a.pop(0)
			step = 'b'
		elif step == 'a' and a[0] <= b[0]:
			b.pop(0)
			step = 'b'
		elif step == 'b' and a[0] >= b[0]:
			a.pop(0)
			step = 'a'
		elif step == 'b' and b[0] > a[0]:
			score_b += b[0]
			b.pop(0)
			step = 'a'
	elif step == 'b' and b == []:
		a.pop(0)
		step = 'a'
	elif step == 'a' and a == []:
		b.pop(0)
		step = 'b'
	elif step == 'a' and b == []:
		score_a += a[0]
		a.pop(0)
		step = 'b'
	elif step == 'b' and a == []:
		score_b += b[0]
		b.pop(0)
		step = 'a'
	if a == [] and b == []:
		empty = True
print(score_a - score_b)


n = int(input())
arrA = list(map(int, input().split()))
arrB = list(map(int, input().split()))
arrA.sort()
arrB.sort()
scoreDiff = 0
aPlaying = True
while len(arrA) != 0 or len(arrB) != 0:
	if len(arrA) == 0:
		if aPlaying:
			arrB.pop()
		else:
			scoreDiff -= arrB[-1]
			arrB.pop()
	elif len(arrB) == 0:
		if aPlaying:
			scoreDiff += arrA[-1]
			arrA.pop()
		else:
			arrA.pop()
	else:
		maxA = arrA[-1]
		maxB = arrB[-1]
		if aPlaying:
			if maxA > maxB:
				scoreDiff += maxA
				arrA.pop()
			else:
				arrB.pop()
		elif maxA > maxB:
			arrA.pop()
		else:
			scoreDiff -= maxB
			arrB.pop()
	aPlaying = not aPlaying
print(scoreDiff)


n = int(input())
a = list(map(int, input().split()))
a = a + list(map(int, input().split()))
p = [1] * n + [2] * n
z = sorted(zip(a, p), reverse=True)
s = 0
s2 = 0
for i in range(0, 2 * n, 2):
	if z[i][1] == 1:
		s = s + z[i][0]
	if z[i + 1][1] == 2:
		s2 = s2 + z[i + 1][0]
print(s - s2)


n = int(input())
s = input().split()
la = [int(s[i]) for i in range(n)]
s = input().split()
lb = [int(s[i]) for i in range(n)]
la.sort()
lb.sort()
sa = 0
sb = 0
for i in range(n):
	if len(la) == 0:
		if len(lb) > 0:
			del lb[-1]
		else:
			break
	elif len(lb) == 0:
		sa += la[-1]
		del la[-1]
	elif la[-1] > lb[-1]:
		sa += la[-1]
		del la[-1]
	else:
		del lb[-1]
	if len(lb) == 0:
		if len(la) > 0:
			del la[-1]
		else:
			break
	elif len(la) == 0:
		sb += lb[-1]
		del lb[-1]
	elif lb[-1] > la[-1]:
		sb += lb[-1]
		del lb[-1]
	else:
		del la[-1]
print(sa - sb)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, **kwargs, file=sys.stderr)
	dprint('debug mode')
except ModuleNotFoundError:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
z1 = getIntList()
z2 = getIntList()
z1.sort()
z2.sort()
t1 = N - 1
t2 = N - 1
s1 = 0
s2 = 0

def bigone():
	if t1 >= 0 and t2 >= 0:
		if z1[t1] > z2[t2]:
			return 1
		else:
			return 2
	if t1 >= 0:
		return 1
	return 2
while t1 >= 0 or t2 >= 0:
	t = bigone()
	if t == 1:
		s1 += z1[t1]
		t1 -= 1
	else:
		t2 -= 1
	t = bigone()
	if t == 1:
		t1 -= 1
	else:
		s2 += z2[t2]
		t2 -= 1
print(s1 - s2)


n = int(input())
a = map(int, input().split())
b = map(int, input().split())
a = sorted(a)
b = sorted(b)
q = n
z = 1
aa = n - 1
bb = n - 1
A = 0
B = 0
while aa > -1 or bb > -1:
	if aa > -1:
		if bb > -1 and a[aa] < b[bb]:
			bb -= 1
		else:
			A += a[aa]
			aa -= 1
	else:
		bb -= 1
	if bb > -1:
		if aa > -1 and a[aa] > b[bb]:
			aa -= 1
		else:
			B += b[bb]
			bb -= 1
	else:
		aa -= 1
print(A - B)


n = int(input())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
sa = sb = 0
i = j = 0
c = 1
while i < n and j < n:
	if c:
		if a[i] >= b[j]:
			sa += a[i]
			i += 1
		else:
			j += 1
	elif b[j] >= a[i]:
		sb += b[j]
		j += 1
	else:
		i += 1
	c ^= 1
while i < n:
	if c:
		sa += a[i]
	c ^= 1
	i += 1
while j < n:
	if c == 0:
		sb += b[j]
	j += 1
	c ^= 1
print(sa - sb)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
ascore = 0
bscore = 0
turn = 0
while a or b:
	if turn == 0:
		if not a:
			b.pop()
		elif not b:
			ascore += a.pop()
		elif a[-1] < b[-1]:
			b.pop()
		else:
			ascore += a.pop()
	elif not a:
		bscore += b.pop()
	elif not b:
		a.pop()
	elif a[-1] < b[-1]:
		bscore += b.pop()
	else:
		a.pop()
	turn = 1 - turn
print(ascore - bscore)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
a.insert(0, -1)
b.insert(0, -1)
x = n
y = n
k = 0
l = 0
while x + y > 0:
	if a[x] >= b[y]:
		k = k + a[x]
		x = x - 1
	else:
		y = y - 1
	if x == -1:
		x = 0
	if y == -1:
		y = 0
	if b[y] >= a[x]:
		l = l + b[y]
		y = y - 1
	else:
		x = x - 1
	if x == -1:
		x = 0
	if y == -1:
		y = 0
print(k - l)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
rez_A = 0
rez_B = 0
i = 0
j = 0
while i < n or j < n:
	max_A = 0
	max_B = 0
	if i < n:
		max_A = A[i]
	if j < n:
		max_B = B[j]
	if max_A < max_B and j < n:
		j += 1
		if j < n:
			max_B = B[j]
	elif i < n:
		rez_A += max_A
		i += 1
		if i < n:
			max_A = A[i]
	elif j < n:
		j += 1
	if max_A > max_B and i < n:
		i += 1
	elif j < n:
		rez_B += max_B
		j += 1
	elif i < n:
		i += 1
print(rez_A - rez_B)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(ascore, bscore) = (sum(a), sum(b))
a.extend(b)
a.sort(reverse=True)
for i in range(n * 2):
	if i & 1:
		bscore += a[i]
	else:
		ascore += a[i]
print((ascore - bscore) // 2)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sa = 0
sb = 0
a.sort(reverse=1)
b.sort(reverse=1)
i = 0
j = 0
turn = 0
while i < n and j < n:
	if turn % 2 == 0:
		if a[i] >= b[j]:
			sa += a[i]
			i += 1
		else:
			j += 1
	elif b[j] >= a[i]:
		sb += b[j]
		j += 1
	else:
		i += 1
	turn += 1
while i < n:
	if turn % 2 == 0:
		sa += a[i]
	i += 1
	turn += 1
while j < n:
	if turn % 2:
		sb += b[j]
	j += 1
	turn += 1
print(sa - sb)


n = int(input())
a = [int(i) for i in input().split()] + [0] * 1000
b = [int(i) for i in input().split()] + [0] * 1000
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
i = 0
j = 0
asum = 0
bsum = 0
mauka = 1
moves = 0
while moves < 2 * n:
	moves += 1
	if mauka:
		if a[i] >= b[j]:
			asum += a[i]
			i += 1
		else:
			j += 1
	elif b[j] >= a[i]:
		bsum += b[j]
		j += 1
	else:
		i += 1
	mauka = 1 - mauka
print(asum - bsum)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
sum = 0
ind1 = 0
ind2 = 0
for i in range(2 * n):
	if i % 2 == 0:
		if ind1 == n:
			ind2 += 1
		elif ind2 == n:
			sum += a[ind1]
			ind1 += 1
		elif b[ind2] > a[ind1]:
			ind2 += 1
		else:
			sum += a[ind1]
			ind1 += 1
	elif ind1 == n:
		sum -= b[ind2]
		ind2 += 1
	elif ind2 == n:
		ind1 += 1
	elif b[ind2] >= a[ind1]:
		sum -= b[ind2]
		ind2 += 1
	else:
		ind1 += 1
print(sum)


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr1.sort(reverse=True)
arr2.sort(reverse=True)
i = 0
j = 0
f = 0
scoreA = 0
scoreB = 0
while 1:
	if i == n and j == n:
		break
	if f == 0:
		if i < n and j < n:
			if arr1[i] > arr2[j]:
				scoreA += arr1[i]
				i += 1
			else:
				j += 1
		elif i < n and j >= n:
			scoreA += arr1[i]
			i += 1
		elif i >= n and j < n:
			j += 1
		f = 1
	else:
		if i < n and j < n:
			if arr1[i] < arr2[j]:
				scoreB += arr2[j]
				j += 1
			else:
				i += 1
		elif j < n and i >= n:
			scoreB += arr2[j]
			j += 1
		elif j >= n and i < n:
			i += 1
		f = 0
print(scoreA - scoreB)


n = int(input())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
(a.sort(), b.sort())
(s1, s2, i) = (0, 0, 0)
while i < 2 * n:
	if len(a) == 0:
		if i & 1:
			s2 += b[-1]
		del b[-1]
	elif len(b) == 0:
		if not i & 1:
			s1 += a[-1]
		del a[-1]
	elif not i & 1:
		if a[-1] > b[-1]:
			s1 += a[-1]
			del a[-1]
		else:
			del b[-1]
	elif a[-1] < b[-1]:
		s2 += b[-1]
		del b[-1]
	else:
		del a[-1]
	i += 1
print(s1 - s2)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for a in A:
	C.append((a, 0))
for b in B:
	C.append((b, 1))
C.sort(reverse=True)
ans = 0
for i in range(len(C)):
	(c, j) = C[i]
	if i % 2 == j:
		if i % 2 == 0:
			ans += c
		else:
			ans -= c
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def play(p1, p2):
	if not len(p1):
		p2.pop()
		return 0
	elif not len(p2):
		return p1.pop()
	elif p1[-1] >= p2[-1]:
		return p1.pop()
	else:
		p2.pop()
		return 0
a.sort()
b.sort()
p1 = p2 = 0
while len(a) or len(b):
	p1 += play(a, b)
	p2 += play(b, a)
print(p1 - p2)


import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
start_time = time.time()

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def get_ints():
	return map(int, sys.stdin.readline().split())
n = int(input())
my_arr = list(get_ints())
opp_arr = list(get_ints())
arr = []
for i in range(n):
	arr.append([my_arr[i], 1])
for i in range(n):
	arr.append([opp_arr[i], 0])
arr = sorted(arr, key=lambda x: x[0])
my_score = 0
opp_score = 0
c = 0
while len(arr) != 0:
	if c == 0:
		if arr[-1][1] == 1:
			my_score += arr[-1][0]
		arr.pop()
	else:
		if arr[-1][1] == 0:
			opp_score += arr[-1][0]
		arr.pop()
	c = c ^ 1
print(my_score - opp_score)


import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def nninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
n = iinp()
a = llinp()
b = llinp()
a.sort(reverse=True)
b.sort(reverse=True)
a.append(0)
b.append(0)
ind1 = ind2 = tot = sa = sb = f = 0
while tot < 2 * n:
	tot += 1
	if f == 0:
		if a[ind1] > b[ind2]:
			sa += a[ind1]
			ind1 += 1
		else:
			ind2 += 1
		f = 1
	elif f == 1:
		if b[ind2] > a[ind1]:
			sb += b[ind2]
			ind2 += 1
		else:
			ind1 += 1
		f = 0
p(sa - sb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = j = 0
ans = 0
a.sort(reverse=True)
b.sort(reverse=True)
while i < n and j < n:
	if a[i] >= b[j]:
		if (i + j) % 2 == 0:
			ans += a[i]
			i += 1
		else:
			i += 1
	elif (i + j) % 2 != 0:
		ans -= b[j]
		j += 1
	else:
		j += 1
while i < n:
	if (i + j) % 2 == 0:
		ans += a[i]
	i += 1
while j < n:
	if (i + j) % 2 != 0:
		ans -= b[j]
	j += 1
print(ans)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
sumA = 0
sumB = 0
while len(A) > 0 or len(B) > 0:
	if len(A) > 0:
		if len(B) < 1 or A[len(A) - 1] >= B[len(B) - 1]:
			sumA += A[len(A) - 1]
			A.pop()
		else:
			B.pop()
	elif len(B) > 0:
		B.pop()
	if len(B) > 0:
		if len(A) < 1 or B[len(B) - 1] >= A[len(A) - 1]:
			sumB += B[len(B) - 1]
			B.pop()
		else:
			A.pop()
	elif len(A) > 0:
		A.pop()
print(sumA - sumB)


n = int(input())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
A.sort()
B.sort()
Ascore = 0
Bscore = 0
i = 0
while len(A) > 0 or len(B) > 0:
	if i % 2 == 0:
		if len(A) == 0:
			B.pop()
		elif len(B) == 0 or A[-1] >= B[-1]:
			Ascore += A.pop()
		else:
			B.pop()
	elif len(B) == 0:
		A.pop()
	elif len(A) == 0 or B[-1] >= A[-1]:
		Bscore += B.pop()
	else:
		A.pop()
	i += 1
print(Ascore - Bscore)


sa = []
sb = []
a = 0
b = 0
turn = 1
n = int(input())
sa = [int(i) for i in input().split()]
sb = [int(i) for i in input().split()]
sa.sort()
sb.sort()
sa.reverse()
sb.reverse()
while sa or sb:
	if turn % 2:
		if sa and sb:
			if sa[0] <= sb[0]:
				del sb[0]
			else:
				a += sa[0]
				del sa[0]
		elif sa:
			a += sa[0]
			del sa[0]
		else:
			del sb[0]
		turn += 1
	else:
		if sa and sb:
			if sb[0] <= sa[0]:
				del sa[0]
			else:
				b += sb[0]
				del sb[0]
		elif sb:
			b += sb[0]
			del sb[0]
		else:
			del sa[0]
		turn += 1
print(a - b)


n = int(input())
ls1 = list(map(int, input().split()))
ls2 = list(map(int, input().split()))
ls1 = sorted(ls1)[::-1]
ls2 = sorted(ls2)[::-1]
idx1 = 0
idx2 = 0
ans = 0
out = 1
while idx1 < n and idx2 < n:
	if ls1[idx1] > ls2[idx2]:
		if out > 0:
			ans += ls1[idx1]
		idx1 += 1
	else:
		if out < 0:
			ans -= ls2[idx2]
		idx2 += 1
	out *= -1
while idx1 < n:
	if out > 0:
		ans += ls1[idx1]
	idx1 += 1
	out *= -1
while idx2 < n:
	if out < 0:
		ans -= ls2[idx2]
	idx2 += 1
	out *= -1
print(ans)


N = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr1.sort()
arr2.sort()
max1 = N - 1
max2 = N - 1
A = 0
B = 0
turn = 0
while max1 >= 0 or max2 >= 0:
	if turn == 0:
		if arr1[max1] >= arr2[max2]:
			if max1 >= 0:
				A += arr1[max1]
				max1 -= 1
			else:
				max2 -= 1
		elif max2 >= 0:
			max2 -= 1
		else:
			A += arr1[max1]
			max1 -= 1
	elif arr1[max1] <= arr2[max2]:
		if max2 >= 0:
			B += arr2[max2]
			max2 -= 1
		else:
			max1 -= 1
	elif max1 >= 0:
		max1 -= 1
	else:
		B += arr2[max2]
		max2 -= 1
	if turn == 0:
		turn = 1
	else:
		turn = 0
print(A - B)


n = int(input())
l1 = sorted(list(map(int, input().split())))
l2 = sorted(list(map(int, input().split())))
(a, b) = (0, 0)
while l1 != [] or l2 != []:
	if l1 != []:
		if l2 != [] and l1[-1] >= l2[-1]:
			a += l1[-1]
			l1.pop()
		elif l2 != [] and l1[-1] < l2[-1]:
			l2.pop()
		else:
			a += l1[-1]
			l1.pop()
	else:
		l2.pop()
	if l2 != []:
		if l1 != [] and l1[-1] > l2[-1]:
			l1.pop()
		elif l1 != [] and l1[-1] <= l2[-1]:
			b += l2[-1]
			l2.pop()
		else:
			b += l2.pop()
	else:
		l1.pop()
print(a - b)


from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	n = ii()
	a = li()
	b = li()
	a.sort()
	b.sort()
	i = n - 1
	j = n - 1
	s1 = 0
	s2 = 0
	while i >= 0 or j >= 0:
		if i >= 0 and j >= 0 and (a[i] > b[j]):
			s1 += a[i]
			i -= 1
		elif j >= 0:
			j -= 1
		elif i >= 0:
			s1 += a[i]
			i -= 1
		if j >= 0 and b[j] > a[i] and (i >= 0):
			s2 += b[j]
			j -= 1
		elif i >= 0:
			i -= 1
		elif j >= 0:
			s2 += b[j]
			j -= 1
	print(s1 - s2)
main()


n = int(input())
x = [sorted([int(x) for x in input().split()]), sorted([int(x) for x in input().split()])]
(cur, k, ans) = (1, -1, 0)
for i in range(2 * n):
	cur = cur ^ 1
	k = -k
	if len(x[cur]) == 0:
		x[cur ^ 1].pop()
	elif len(x[cur ^ 1]) == 0 or x[cur][-1] - x[cur ^ 1][-1] > 0:
		ans = ans + k * x[cur].pop()
	else:
		x[cur ^ 1].pop()
print(ans)


def last(array):
	return array[li(array)]

def li(array):
	return len(array) - 1
n = int(input())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
first.sort()
second.sort()
res = 0
turn = True
while len(first) != 0 or len(second) != 0:
	if turn:
		if len(first) == 0:
			second.pop(len(second) - 1)
		elif len(second) == 0:
			res += first[len(first) - 1]
			first.pop(len(first) - 1)
		elif second[len(second) - 1] >= first[len(first) - 1]:
			second.pop(len(second) - 1)
		else:
			res += first[len(first) - 1]
			first.pop(len(first) - 1)
	elif len(second) == 0:
		first.pop(len(first) - 1)
	elif len(first) == 0:
		res -= second[len(second) - 1]
		second.pop(len(second) - 1)
	elif second[len(second) - 1] <= first[len(first) - 1]:
		first.pop(len(first) - 1)
	else:
		res -= second[len(second) - 1]
		second.pop(len(second) - 1)
	turn = not turn
print(res)


length = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
A.sort()
B.sort()
a = length - 1
b = length - 1
ares = 0
bres = 0
while not (a == -1 and b == -1):
	if b >= 0 and (B[b] > A[a] or a < 0):
		b += -1
	else:
		ares += A[a]
		a += -1
	if a >= 0 and (A[a] > B[b] or b < 0):
		a += -1
	else:
		bres += B[b]
		b += -1
print(ares - bres)


import functools
import time
from collections import Counter

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):
		n = int(input())
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		a.sort(reverse=True)
		b.sort(reverse=True)
		turn = 0
		(ai, bi) = (0, 0)
		(sa, sb) = (0, 0)
		while ai < n or bi < n:
			if turn == 0:
				if ai == n:
					bi += 1
				elif bi == n or (bi < n and a[ai] >= b[bi]):
					sa += a[ai]
					ai += 1
				elif bi < n and a[ai] < b[bi]:
					bi += 1
			elif bi == n:
				ai += 1
			elif ai == n or (ai < n and a[ai] <= b[bi]):
				sb += b[bi]
				bi += 1
			elif ai < n and a[ai] > b[bi]:
				ai += 1
			turn = 1 - turn
		print(sa - sb)
solver()()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = sb = 0
la = len(a)
lb = len(b)
t = 1
a.sort()
b.sort()
while la != 0 and lb != 0:
	if t == 1:
		c = a[la - 1]
		d = b[lb - 1]
		if c >= d:
			sa += c
			a.pop()
			la -= 1
		else:
			b.pop()
			lb -= 1
		t = 0
		continue
	if t == 0:
		c = a[la - 1]
		d = b[lb - 1]
		if c <= d:
			sb += d
			b.pop()
			lb -= 1
		else:
			a.pop()
			la -= 1
		t = 1
if la == 0 and lb != 0:
	if t == 1:
		for i in range(lb - 2, -1, -2):
			sb += b[i]
	if t == 0:
		for i in range(lb - 1, -1, -2):
			sb += b[i]
elif lb == 0 and la != 0:
	if t == 1:
		for i in range(la - 1, -1, -2):
			sa += a[i]
	if t == 0:
		for i in range(la - 2, -1, -2):
			sa += a[i]
print(sa - sb)


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	a = sorted(map(int, stdin.readline().split()))
	b = sorted(map(int, stdin.readline().split()))
	(x, y) = (0, 0)
	turn = 1
	while a or b:
		if turn:
			if a:
				if b:
					if a[-1] >= b[-1]:
						x += a.pop()
					else:
						b.pop()
				else:
					x += a.pop()
			elif b:
				b.pop()
		elif b:
			if a:
				if b[-1] >= a[-1]:
					y += b.pop()
				else:
					a.pop()
			else:
				y += b.pop()
		elif a:
			a.pop()
		turn ^= 1
	stdout.write('%d' % (x - y))
main()


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
a.append(0)
b.append(0)
i = 0
j = 0
m = 0
k = 0
As = 0
Bs = 0
while m < 2 * n:
	m += 1
	if k % 2 == 0:
		if a[i] >= b[j]:
			As += a[i]
			i += 1
		else:
			j += 1
	elif b[j] >= a[i]:
		Bs += b[j]
		j += 1
	else:
		i += 1
	k += 1
print(As - Bs)


n = int(input())
s1 = [int(x) for x in input().split()]
s2 = [int(x) for x in input().split()]
S1 = sorted(s1)
S2 = sorted(s2)
S1 = [0] + S1
S2 = [0] + S2
S1 = S1[::-1]
S2 = S2[::-1]
pta = 0
ptb = 0
sm1 = 0
sm2 = 0
for j in range(0, 2 * n + 1):
	if j % 2 == 0:
		if S2[ptb] > S1[pta]:
			ptb = ptb + 1
		else:
			sm1 = sm1 + S1[pta]
			pta = pta + 1
	elif S1[pta] > S2[ptb]:
		pta = pta + 1
	else:
		sm2 = sm2 + S2[ptb]
		ptb = ptb + 1
	if pta == n + 1 and ptb == n + 1:
		break
print(sm1 - sm2)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
i = 0
ac = 1
bc = 0
sa = 0
sb = 0
while True:
	if len(a) != 0 and a[0] == 0:
		a.clear()
	elif len(b) != 0 and b[0] == 0:
		b.clear()
	if len(a) > 0 and len(b) == 0 and (a[0] != 0):
		b.append(0)
	elif len(b) > 0 and len(a) == 0 and (b[0] != 0):
		a.append(0)
	if len(a) == 0 and len(b) == 0:
		break
	elif ac == 1:
		if a[i] >= b[i]:
			sa = sa + a[i]
			a.remove(a[i])
		else:
			b.remove(b[i])
		ac = 0
		bc = 1
	elif bc == 1:
		if b[i] >= a[i]:
			sb = sb + b[i]
			b.remove(b[i])
		else:
			a.remove(a[i])
		bc = 0
		ac = 1
print(sa - sb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
a = a + [-999999]
b = b + [-999999]
i = 0
j = 0
moves = 0
asum = 0
bsum = 0
player = 0
while moves < 2 * n:
	moves += 1
	if not player:
		if a[i] >= b[j]:
			asum += a[i]
			i += 1
		else:
			j += 1
	elif b[j] >= a[i]:
		bsum += b[j]
		j += 1
	else:
		i += 1
	player ^= 1
print(asum - bsum)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_right
n = int(input())
arr = list(map(int, input().split()))
ls = list(map(int, input().split()))
arr.sort(reverse=True)
ls.sort(reverse=True)
a = b = 0
f = 0
i = 0
j = 0
while i < n or j < n:
	if f == 0:
		if i < n and j < n and (arr[i] > ls[j]) or (i < n and j >= n):
			a += arr[i]
			i += 1
		else:
			j += 1
		f = 1
	else:
		if i < n and j < n and (arr[i] < ls[j]) or (j < n and i >= n):
			b += ls[j]
			j += 1
		else:
			i += 1
		f = 0
print(a - b)