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: interview

Starter code:

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

#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    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())     #idle 中不会执行 atexit
    
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)











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())
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)

#Problem C: Gambling

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): #First Player
        if(owner==1):
            ans += pts
    else:
        if(owner==2):
            ans -= pts

print(ans)

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)]
# print(ar1, 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()))
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]
	else:
		if ab[i][1] == 1:
			ans -= ab[i][0]

print(ans)

n = int(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)

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()
    else:
        if 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())
if n == 1 or n == 2:
    print('No')
else: #if n % 2 == 1:
    print('Yes')
    print((n + 1) // 2, end = ' ')
    for i in range(1, n + 1, 2):
        print(i, end = ' ')
    print()
    print(n // 2, end = ' ')
    for i in range(2, n + 1, 2):
        print(i, end = ' ')
'''
'''
n, k = map(int, input().split())
s = input()
d = [0 for _ in range(k)]
for i in s:
    d[ord(i) - ord('A')] += 1
#al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#for i in 
print(min(d) * k)
'''

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()
		#scores[i%2] += Bs.pop()
	elif len(Bs) == 0:
		if is_a:
			scores[0] += As.pop()
		else:
			As.pop()
		#scores[i%2] += As.pop()
	else:
		if As[-1] > Bs[-1]:
			if is_a:
				scores[i%2] += As.pop()
			else:
				As.pop()
		else:
			if is_a:
				Bs.pop()
			else:
				scores[1] += Bs.pop()
#			scores[i%2] += Bs.pop()
print(scores[0]-scores[1])



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]
    else:
        if 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())
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)



'''input
2
2 1
5 6
'''
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:
		#a-turn
		temp1=-heapq.heappop(a)
		temp2=-heapq.heappop(b)
		if temp2>temp1:
			heapq.heappush(a,-temp1)
		else:
			ans1+=temp1
			heapq.heappush(b,-temp2)
	else:
		#b-turn
		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)
print(ans1-ans2)



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)
        


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
#print(a,b)
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())
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     # A
    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  # B
    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())
n,k=map(int,input().split())
s=input()
L=[0]*26
#s=[int(x) for x in input().split()]
for j in range(0,len(s)):
    L[ord(s[j])-65]=L[ord(s[j])-65]+1
ans=1000000007
for j in range(0,k):
    ans=min(ans,L[j])
ans=k*ans
print(ans)"""
"""import math
pre=[]
for i in range(0,45010):
    pre.append(((i*(i+1))//2))
#print(pre[:100])
n=int(input())
if(n==0 or n==1 or n==2):
    print('No')
else:
    temp=0
    t=pre[n]
    pos=-1
    for j in range(1,n+1):
        if(math.gcd(pre[j],t-pre[j])>1):
            temp=1
            pos=j
            break
    if(temp==0):
        print('No')
    else:
        print('Yes')
        print(pos,end=" ")
        for j in range(1,pos+1):
            print(j,end=" ")
        print(" ")
        print(n-j,end=" ")
        for j in range(pos+1,n+1):
            print(j,end=" ")
        print(" ")"""



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
    else:
        if(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)


#!/usr/bin/env python3
#-*- encoding: utf-8 -*-

import sys
import bisect
from collections import Counter

read_int = lambda : int(sys.stdin.readline())
read_ints = lambda : list(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()
        else:
            if 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=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]
    else:
        if 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)

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)

I=lambda:map(int,input().split())
#C
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]
    else:
        if 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)

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:
        # turn a
        if len(aa) == 0:
            bb.pop()
        elif len(bb) == 0:
            sa += aa.pop()
        elif aa[-1] >= bb[-1]:
            sa += aa.pop()
        else:
            bb.pop()

        # turn b
        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)

def __starting_point():
    gambling()
__starting_point()

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
    else:
        if 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)


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
#sa+=sum(a)
#sb+=sum(b)
print (sa-sb)

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()
    else:
        if(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()
    else:
        if(ara[-1]>arb[-1]):
            ara.pop()
        else:
            sumsb+=arb[-1]
            arb.pop()
    i+=1
print(sumsa-sumsb)