Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
import math

n = int(input())
#a = int(input())
#a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]
#ls1 = [input() for i in range(n)]
#m = int(input())
#ls2 = [input() for i in range(m)]

ls.sort(reverse=True)
print(sum(ls[0::2]) - sum(ls[1::2]))

# Example run
# Input:
-221907
-154
# Output:
-154
N = int(input())
a = list(map(int,input().split()))

b = sorted(a,reverse=True)
ans = sum([b[x] for x in range(N) if x % 2 ==0]) - sum([b[x] for x in range(N) if x % 2 ==1])

print(ans)

# Example run
# Input:
-1057486868
10366
# Output:
0
N = input()
num_list= list(map(int, input().split(" ")))
num_list.sort(reverse = True)
print(sum(num_list[::2]) - sum(num_list[1::2]))

# Example run
# Input:
7;cq=rx
-30
# Output:
-30
N=int(input())
A=list(map(int,input().split()))+[0]
A=sorted(A,reverse=True)
al=sum(A[::2])
bo=sum(A[1::2])
print(al-bo)

# Example run
# Input:
4
4
# Output:
4
n = int(input())
a = list(map(int, input().split())) 

a.sort()

even = sum(a[0::2])
odd = sum(a[1::2])

print(abs(even-odd))

# Example run
# Input:
-14665841
-235202
# Output:
235202
n = int(input())
a = list(map(int,input().split()))
sum_ = sum(a)
a.sort()
#print(a)
alice = 0
for i in range(len(a)):
    if i % 2 == 0:
        #print(a[-i-1],alice)
        alice += a[-i-1]
print(2*alice - sum_)
#print(alice)

# Example run
# Input:
-56661351
981571
# Output:
981571
# a = int(input())
# b,c = map(int, input().split())
# s = input()
# print('{} {}'.format(a+b+c,s))
#
# a,b = map(int, input().split())
# if a*b%2 == 0:
#     print("Even")
# else :
#     print("Odd")
# l = list(input())
# l_new = [int(n) for n in l]
# count = 0
# for i in l_new:
#     if i == 1:
#         count += 1
# print(count)
# #Maxの答えを先に宣言して上限を設けておく
# ans = 10 **9
# N = int(input())
# A = list(map(int,input().split()))
# for i in A:
#     p = 0
#     while i % 2 ==0:
#         i //=2
#         p += 1
#     if p < ans:
#         ans = p
#         #一度ansに格納して大小の比較を行っている
# print(ans)

#切り捨て除算


# a = int(input())
# b = int(input())
# c = int(input())
# X = int(input())
# count = 0
# for i in range(a+1):
#     x = 500 * i
#     for j in range(b+1):
#         y = 100 * j
#         for k in range(c+1):
#             z = 50 * k
#             if x+y+z == X :

N = int(input())
l = list(map(int,input().split()))
l_r = sorted(l,reverse=True)
Alice = l_r[::2]
Bob = l_r[1::2]

m =0
n = 0
for i in Alice:
    m += i
for j in Bob:
    n += j
print(m-n)





# Example run
# Input:
-18579092
21643
# Output:
21643
# -*- coding:utf-8 -*-
N = int(input())
a_list = list(map(int,input().split()))

Alice = 0
Bob = 0

a_list.sort(reverse=True)

for i in range(N):
    if i % 2 == 0:
        Alice += a_list[i]
    else:
        Bob += a_list[i]

print(Alice-Bob)


# Example run
# Input:
-29588
-5
# Output:
0
loopCnt = int(input())
cards = list(map(int, input().split()))

alice = 0
bob = 0

cards.sort(reverse=True)

for i in range(loopCnt):
  if i == 0 or i%2 == 0:
    alice += cards[i]
  elif i%2 == 1:
    bob += cards[i]

print(alice-bob)

# Example run
# Input:
-21
31499
# Output:
0
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    n = int(input())
    a = input().split()

    bob = 0
    alice = 0
    sort_a = sorted(a, reverse=True)
    count = 0
    for m in range(len(sort_a)):
        if m % 2 == 0:
            alice += int(sort_a[m])
        else:
            bob += int(sort_a[m])

    print(alice - bob)


# Example run
# Input:
-2147483648
450137
# Output:
450137
n = int(input())
A = sorted(list(map(int, input().split())))[::-1]
print(sum(A[::2]) - sum(A[1::2]))

# Example run
# Input:
377
-10
# Output:
-10
while True:
    N = int(input())
    b = input().split()
    a = [int(i) for i in b]
    if (N >= 1 and N <= 100):
        for i in a:
            if (i < 1 or i > 100):
                continue
    else:
        continue
    break
a.sort(reverse=True)

s = [0,0]
for i in range(len(a)):
    s[i%2] = a[i] + s[i%2]
print(s[0] - s[1])

# Example run
# Input:
1
-11909
# Output:
-11909
N = int(input())
A = list(map(int, input().split()))

A.sort()
A.reverse()

print(sum(A[0::2])-sum(A[1::2]))

# Example run
# Input:
-18229
-16112
# Output:
-16112
n = int(input())
a = map(int, input().split())
a = sorted(a, reverse=True)
score = 0
for i in range(0,n):
        if i%2 == 0:
                score += a[i]
        else:
                score -= a[i]
print(score)

# Example run
# Input:
-16240
1637046672
# Output:
0
N = int(input())
a = list(map(int, input().split()))
a.sort()
alice = 0
bob = 0
ban = 0
while len(a) > 0:
    if ban % 2 == 0:
        alice += a.pop()
    else:
        bob += a.pop()
    ban += 1
print(alice - bob)

# Example run
# Input:
-274078593
-28418
# Output:
-28418
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=sum(a)
p=0
for i in range(0,len(a),2):
  p+=a[i]
print(p*2-s)

# Example run
# Input:
18
-1028681
# Output:
-1028681
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
i = 0
ans = 0
for i in range(n):
    if i%2 == 0:
        ans += a[i]
    else:
        ans -= a[i]
print(ans)

# Example run
# Input:
-1759593
-6
# Output:
0
n = int(input())
var = list(map(int, input().split()))
var_max = 0
alice = 0
bob = 0
for y in range(n):
    var_max = 0
    for x in var:
        if(var_max <= x):
            var_max = x
    var.remove(var_max)
    if(y % 2 == 0):
        alice += var_max
    else:
        bob += var_max
print(alice - bob)


# Example run
# Input:
-65
0
# Output:
0
if __name__ == '__main__':
    N = int(input())
    a_list = list(map(int, input().split()))

    a_list = sorted(a_list, reverse=True)

    print(sum(a_list[0::2])-sum(a_list[1::2]))


# Example run
# Input:
-68
-31
# Output:
-31
N = input()
a = input().split()

a.sort()
a.reverse()

alice = 0
bob = 0

a_num = len(a)

for i in range(a_num):
  if i % 2 == 0:
    alice += int(a[i])
  else:
    bob += int(a[i])

print(alice - bob)

# Example run
# Input:
dSsm`%X6*
65153902
# Output:
65153902
N = int(input())
a = [int(i) for i in input().split()]

a.sort(reverse = True)

alice = 0
bob = 0
for i in range(N):
    if i%2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice-bob)

# Example run
# Input:
0
805965556
# Output:
0
def resolve():
	n = int(input())
	c = list(map(int, input().split()))
	c = sorted(c, reverse=True)
	a, b = 0, 0
	for i in range(n):
		if i % 2 == 0:
			a += c[i]
		else:
			b += c[i]
	print(a-b)
resolve()

# Example run
# Input:
-130994
-18762704
# Output:
0
N = int(input())
la = list(map(int, input().split()))
larev = sorted(la, reverse=True)

A = sum(larev[0::2])
B = sum(larev[1::2])

print(A - B)

# Example run
# Input:
-902193
6
# Output:
6
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
alice = sum(A[::2])
bob = sum(A[1::2])
print(alice - bob)


# Example run
# Input:
5354599
52
# Output:
52
n = int(input())
a = list(map(int, input().split()))

ali = 0
bob = 0

a.sort(reverse=True)
for i, m in enumerate(a):
    if i % 2 == 0:
        ali += m
    else:
        bob += m

print(ali - bob)

# Example run
# Input:
45607
-877447
# Output:
-877447
N = int(input())
l = list(map(int,input().split()))
l_r = sorted(l,reverse=True)
Alice = l_r[::2]
Bob = l_r[1::2]

m =0
n = 0
for i in Alice:
    m += i
for j in Bob:
    n += j
print({m-n})


# Example run
# Input:
1419428
-2147483648
# Output:
{-2147483648}
N = int(input())
cards = list(map(int, input().split()))

alice = 0
bob = 0
for i in range(N+1):
  if i % 2 == 0:
    alice += cards[i]
  else:
    bob += cards[i]

print(alice-bob)

# Example run
# Input:
-15860207
-54634663
# Output:
0
n=int(input())
nl=sorted(list(map(int, input().split())),reverse=True)
print(sum(nl[0::2])-sum(nl[1::2]))

# Example run
# Input:
-52564348
-7737
# Output:
-7737
N = int(input())
a = list(map(int, input().split()))
score_A = 0
score_B = 0
a.sort(reverse=True)
i = 1
for n in a:
  if i % 2 == 1:
    score_A += n
  elif i % 2 == 0:
    score_B += n
  
  i += 1


result = score_A - score_B
print(result)

# Example run
# Input:
-1
60
# Output:
60
N = int(input())
A = list(map(int, input().split()))
A.sort()
Alice = 0; Bob = 0
for i in range(N):
    if i%2 == 0:
        Alice += A.pop()
    else:
        Bob += A.pop()
print(Alice - Bob)


# Example run
# Input:
-41270
-2
# Output:
0
input()
a=sorted(map(int,input().split()))[::-1]
print(sum(a[::2])-sum(a[1::2]))

# Example run
# Input:
L-)iTg5DK
5354599
# Output:
5354599
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

allis = 0
bob = 0

for i in range(N):
    if i % 2 == 0:
        allis += a[i]
    else:
        bob += a[i]

print(allis-bob)


# Example run
# Input:
-15915
-501843
# Output:
0
d = '2 7 4'
d = input()
d = input()
d = [int(i) for i in d.split()]
d.sort()
s1 = 0
s2 = 0
i = len(d)-1
while(i>=0):
    s1 = s1 + d[i]
    if((i-1)>=0):
        s2 = s2 + d[i-1]
    i = i-2
print(s1-s2)




# Example run
# Input:
rhwBF
-56446
# Output:
-56446
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
a = A[0::2]
b = A[1::2]
print(sum(a) - sum(b))


# Example run
# Input:
-1
-3439167
# Output:
-3439167
n = int(input())
nums = sorted(list(map(int,input().split())),reverse = True)
Alice = sum(nums[::2])
Bob = sum(nums[1::2])
print(Alice - Bob)

# Example run
# Input:
-1
2199169
# Output:
2199169
_=input()
aN=[int(x) for x in input().split()]
aN.sort(reverse=True)
print(sum(aN[::2])-sum(aN[1::2]))

# Example run
# Input:
e3zvshd]
45580
# Output:
45580
# 入力割り当て
N = int(input())
A = list(map(int, input().split()))

# sort
A_sort = sorted(A, reverse=True)

# 変数定義
n = 0
m = 0
i = 0

# 降順に割り当て
for i in range(N):
	if i%2 == 0:
		n += A_sort[i]
	else:
		m += A_sort[i]

# 結果の表示
ans = n - m
print(ans)

# Example run
# Input:
-224231
-640183291
# Output:
0
n=int(input())
l=sorted(list(map(int,input().split())),reverse=True)
print(sum(l[0::2])-sum(l[1::2]))


# Example run
# Input:
1332
-2239572
# Output:
-2239572
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = sum([a[i] for i in range(0,n,2)])
bob = sum([a[i] for i in range(1,n,2)])
print(alice-bob)


# Example run
# Input:
-121
6114
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = sum(a[::2])
bob = sum(a[1::2])
print(alice-bob)

# Example run
# Input:
7381
449660
# Output:
449660
n = int(input())
a = list(map(int, input().split()))
alice = []
bob = []

for i in range(n):
    if i % 2 == 0:
        alice.append(max(a))
        a.remove(max(a))
    else:
        bob.append(max(a))
        a.remove(max(a))

print(sum(alice)-sum(bob))

# Example run
# Input:
-53605951
3
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

print(sum(a[::2]) - sum(a[1::2]))


# Example run
# Input:
3
-563
# Output:
-563
input()
a=sorted(map(int,input().split()))[::-1]
print(sum(a[::2])-sum(a[1::2]))

# Example run
# Input:
>x#!w6b>
-45
# Output:
-45
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
alice=sum(a[0::2])
bob=sum(a[1::2])
print(alice-bob)

# Example run
# Input:
-473
-7
# Output:
-7
def ret_max_index(n, list):
    i = 0
    tmp = 0
    max = 0
    for i in range(n):
        if(max < list[i]):
            tmp = i
            max = list[i]
    return tmp

N = int(input())
lis = [int(i) for i in input().split()]

j = 0
k = 0
alice = 0
bob = 0
max = 0
lis_elem = len(lis)

for j in range(N):
    lis_elem = len(lis)
    max = lis[ret_max_index(lis_elem, lis)]
    #print("max:",max)
    del lis[ret_max_index(lis_elem, lis)]
    if(j%2 == 0):
        alice = alice + max
    elif(j%2 == 1):
        bob = bob + max

print(alice - bob)

# Example run
# Input:
-1
96
# Output:
0
def card_game_for_two():
    input() # 一行目の入力は使わない　
    cards = sorted(list(map(int, input().split())), reverse=True)

    score_diff = sum(cards[::2]) - sum(cards[1::2])

    print(score_diff)

card_game_for_two()

# Example run
# Input:
W9^tx=.[p
-117864
# Output:
-117864
n=int(input())
a=list(map(int,input().split()))
a.sort()

print(abs(sum(a[1::2])-sum(a[::2])))

# Example run
# Input:
-1800135697
415326
# Output:
415326
n = int(input())
a = list(map(int,input().split()))

sort_list = sorted(a)
rev_list = list(reversed(sort_list))

alice_sum = 0
bob_sum = 0

alice = rev_list[::2]
bob = rev_list[1::2]

for i in alice:
    alice_sum += i
for i in bob:
    bob_sum += i

ans = alice_sum - bob_sum

print(ans)





# Example run
# Input:
-7737
-126905272
# Output:
-126905272
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
al, bo = 0, 0
for i in a[0::2]:
    al += i
for i in a[1::2]:
    bo += i
print(al - bo)

# Example run
# Input:
1813543
-252699780
# Output:
-252699780
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += a[i]
    else:
        ans -= a[i]
print(ans)

# Example run
# Input:
-3753932
42339391
# Output:
0
n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
ans=0
for i in range(len(arr)):
    if i%2==0:ans+=arr[i]
    else:ans-=arr[i]
print(ans)

# Example run
# Input:
108968
10559
# Output:
10559
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]
print(alice-bob)


# Example run
# Input:
-1201474778
113
# Output:
0
#Card Game for Two
n=int(input())  #N<=100
a = list(map(int,input().split()))

a.sort(reverse=True)
alice=a[::2]
alice=sum(alice)

bob=a[1::2]
bob=sum(bob)
print(alice-bob)

# Example run
# Input:
-1
-3439167
# Output:
-3439167
N = int(input())
A = list(map(int, input().split()))
n = range(N)
list_Alice = [0]
list_Bob = [0]
A.sort(reverse = True)
for i in n:
  if i%2 == 0:
    list_Alice.append(A[i])
  else:
    list_Bob.append(A[i])
print(sum(list_Alice) - sum(list_Bob))

# Example run
# Input:
0
252889820
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in range(len(a)//2) :
    a[i*2+1] *= -1
print(sum(a))

# Example run
# Input:
1008752943
-37
# Output:
-37
N = int(input())
a = list(map(int,input().split()))
a.sort(),a.reverse()
a_A,a_B = a[::2],a[1::2]
print(sum(a_A)-sum(a_B))



# Example run
# Input:
471619987
-3753932
# Output:
-3753932
N = int(input())
a_list = list(map(int, input().split(' ')))
a_list.sort()
Alice = sum(a_list[-1::-2])
Bob = sum(a_list[-2::-2])
result = Alice - Bob
print(result)

# Example run
# Input:
-309220
-11329
# Output:
-11329
N = int(input())
a_list = [int(i) for i in input().split()]

alice = 0
bob = 0
flag = True
for a in sorted(a_list, reverse=True):
    if flag:
        alice += a
    else:
        bob += a
    flag = not flag
print(alice-bob)


# Example run
# Input:
-1
-3439167
# Output:
-3439167
num = input().split(" ")

num.sort(reverse=True)

A = 0
B = 0
t=0
for i in num:
    if t%2==0:
        A+=int(i)
    else:
        B+=int(i)
    t+=1
print(A-B)

# Example run
# Input:
-70037
# Output:
-70037
N=int(input())
Keys=list(map(int,input().split()))
Keys.sort(reverse=True)
Score=0
for i in range(0,N):
    if i%2 == 0:
        Score+=Keys[i]
    else:
        Score -= Keys[i]
print(Score)


# Example run
# Input:
-3108573
51
# Output:
0
import math
n=int(input())
a=(list(map(int,input().split())))
a.append(0)
al=0
bo=0
for i in range(0,(n+1)//2,1):
    al+=max(a)
    a.remove(max(a))
    
    bo+=max(a)
    a.remove(max(a))
print(al-bo)

# Example run
# Input:
-16371
-52564348
# Output:
0
n = int(input())
a = list(map(int, input().split()))

alice = 0
bob = 0

for i in range(1,len(a)+1):
    if i % 2 != 0:
        alice += a.pop(a.index(max(a)))
    else:
        bob += a.pop(a.index(max(a)))

print(alice - bob)
        

# Example run
# Input:
11
-40
# Output:
-40
n = int(input())
a = list(map(int, input().split()))

a.sort()
a.reverse()

Alice=a[0::2]
Bob = a[1::2]

print(sum(Alice) - sum(Bob))

# Example run
# Input:
30456987
645801
# Output:
645801
n = int(input())
a = list(map(int,input().split()))

alice = 0
bob = 0

a.reverse()

for i in range(n):
    if i % 2 == 0:
        alice += a[i]

    else:
        bob += a[i]

print(alice - bob)

# Example run
# Input:
1
8030667
# Output:
8030667
n = int(input())
card = list(map(int,input().split()))

card.sort(reverse=True)
alice = []
bob = []

for i in range(len(card)):
    if i % 2 == 0:
        alice.append(card[i])
    else:
        bob.append(card[i])

print(sum(alice)-sum(bob))

# Example run
# Input:
-497
-15860207
# Output:
-15860207
N = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
print(sum(cards[::2]) - sum(cards[1::2]))

# Example run
# Input:
985477
0
# Output:
0
n = int(input())
a = list(map(int, input().split()))

a_sorted = sorted(a, reverse=True)
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 1:
        alice += a_sorted[i]
    else:
        bob += a_sorted[i]
print(abs(alice-bob))

# Example run
# Input:
0
1418198351
# Output:
0
N=int(input())
a=list(map(int,input().split()))

Alice=[]    #Aliceが持っているカード
Bob=[]      #Bobが持っているカード
for i in range(N):
    if i%2==0:      #偶数だったらAlieがとる番
        Alice.append(max(a))
        a.remove(max(a))
    else:           #奇数だったらBobがとる番
        Bob.append(max(a))
        a.remove(max(a))

print(sum(Alice)-sum(Bob))



# Example run
# Input:
0
33729406
# Output:
0
N = int(input())
a = str(input()).split(" ")
a_list = list(map(int,a))

a_list_sort = a_list.sort(reverse=True)

Alice = a_list[1::2]
Bob = a_list[0::2]

Alice_score = sum(Alice)
Bob_score = sum(Bob)

dif = abs(Alice_score - Bob_score)
print(dif)

# Example run
# Input:
-23909
-68
# Output:
68
N=int(input())
li=list(map(int, input().split()))
li.sort(reverse=True)
Alice=[]
Bob=[]

for i in range(N):
  if i%2==0:
    Alice.append(li[i])
  else:
    Bob.append(li[i])

print(sum(Alice)-sum(Bob))

# Example run
# Input:
-15860207
-54634663
# Output:
0
n = input()
a = list(map(int, input().split()))

Alice_sum = 0
Bob_sum = 0
a.sort(reverse=True)
for i in range(0,len(a)):
    if i % 2 == 0:
        Alice_sum += a[i]
    else:
        Bob_sum += a[i]

print(Alice_sum - Bob_sum)

# Example run
# Input:
]P}lXg<'
1
# Output:
1
N = int(input())
A = map(int, input().split())
A = sorted(A, reverse=True)
print(sum(A[::2]) - sum(A[1::2]))

# Example run
# Input:
-46095437
-5
# Output:
-5
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
A = a[::2]
B = a[1::2]
print(sum(A) - sum(B))

# Example run
# Input:
655252
-55768
# Output:
-55768
N = int(input())
a = [int(i) for i in input().split()]
Alice = 0
Bob = 0
a.sort(reverse=True)
for i in range(N):
    if i%2 == 0:
        Alice += a[i]
    else:
        Bob += a[i]
print(Alice-Bob)


# Example run
# Input:
-6956
-7038374
# Output:
0
input()
s=sorted(map(int,input().split()))[::-1]
print(abs(sum(s[::2])-sum(s[1::2])))

# Example run
# Input:
i[%sQ
1
# Output:
1
n = int(input())
a = list(map(int, input().split()))

ali = 0
bob = 0

a.sort()
# print(a)
while True:
    if(len(a) > 0):
        ali += a.pop()
    else:
        break
    if(len(a) > 0):
        bob += a.pop()
    else:
        break

print(ali - bob)


# Example run
# Input:
-140
165350
# Output:
165350
input()
a=sorted(list(map(int,input().split())))[::-1]
print(sum(a[::2])-sum(a[1::2]))

# Example run
# Input:
!9,=^6
-40780112
# Output:
-40780112
if __name__ == "__main__":
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    A.sort(reverse=True)
    al = 0
    bob = 0
    for i, a in enumerate(A):
        if i % 2 == 0:
            al += a
        else:
            bob += a
    print(al - bob)


# Example run
# Input:
-1168909
0
# Output:
0
N = int(input())
a_list = [int(i) for i in input().split()]

a_list.sort(reverse=True)
alice, bob = 0, 0
for idx, a in enumerate(a_list):
    if idx % 2 == 0:
        alice += a
    else:
        bob += a
print(alice - bob)

# Example run
# Input:
-15303
-412794
# Output:
-412794
N = int(input())
a_list = []
a_list = [int(x) for x in input().split()]

a_list.sort()
a_list.reverse()

x = 0
y = 0
n = 0

for a in a_list:
  if n % 2 == 0:
    x = x + a
    n = n +1
  else:
    y = y + a
    n = n +1

sabun = x - y

print(sabun)


# Example run
# Input:
-84521052
-2
# Output:
-2
a=int(input())

b=list(map(int, input().split()))
b.sort(reverse=True)
alice=0
bob=0
c=iter(b)
for i in c:
    alice+=i
    try:
    	bob+=next(c)
    except:
      break
print(alice-bob)

# Example run
# Input:
139
-42245
# Output:
-42245
N = int(input())
a = list(map(int, input().split()))

a = sorted(a, reverse=True)
ans = 0
for i, x in enumerate(a):
    if i%2==0:
        ans+=x
    else:
        ans-=x
print(ans)


# Example run
# Input:
2569
30315
# Output:
30315
n=int(input())
a=[int(j) for j in input().split()]
a.sort()
a.reverse()
alice,bob=0,0
for i in range(n):
    if i%2==0:
        alice+=a[i]
    else:
        bob+=a[i]
print(alice-bob)

# Example run
# Input:
-1423
-614
# Output:
0
N = int(input())
A = sorted(map(int, input().split()),reverse=True)
print( sum(A[0::2]) - sum(A[1::2]))

# Example run
# Input:
120644
22710854
# Output:
22710854
N = int(input())
a = list(map(int,input().split()))

acnt =0
bcnt=0
a.sort(reverse=True)

for i in range(len(a)):
    if i%2==0:
        acnt += a[i]
    else:
        bcnt += a[i]
    
print(acnt-bcnt)

# Example run
# Input:
601
-331
# Output:
-331
n = int(input())
a = list(map(int, input().split()))
ali = 0
bob = 0
a.sort()
a.reverse()

for i in range(len(a)):
    if i % 2 == 0:
        ali += a[i]
    else:
        bob += a[i]

print(ali - bob)

# Example run
# Input:
-23909
-68
# Output:
-68
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
score = 0
for i in range(N):
    score = score + a[i]*(-1)**i
print(score)

# Example run
# Input:
-27
38
# Output:
0
N = int(input())
Ai = list(map(int,input().split()))
Alice = 0
Bob = 0

for i in Ai:
    Alice += max(Ai)
    Ai.remove(max(Ai))
    if not Ai:
        break
    Bob += max(Ai)
    Ai.remove(max(Ai))

print(Alice-Bob)

# Example run
# Input:
20794
14319043
# Output:
14319043
N=input()

Ai = list(map(int,input().split()))

alice = 0
bob = 0

Ai.sort()
#print(Ai)

while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

print(alice - bob)


# Example run
# Input:
:;/OF
0
# Output:
0
n = int(input())
a = list(map(int,input().split()))
alice = 0
bob = 0
a.sort(reverse=True)

for i in range(n):
    if i%2 == 0:
        alice += a[i]
    else:
        bob += a[i]
ans = alice - bob
print(ans)


# Example run
# Input:
-6212597
36241
# Output:
0
n=int(input())
lista=list(map(int,input().split()))
lista.sort(reverse=True)
sum=0
for i,e in enumerate(lista):
    if i%2==0:
        sum+=e
    else:
        sum-=e
print(sum)


# Example run
# Input:
141725276
-109089799
# Output:
-109089799
N = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
print(sum(a[:: 2]) - sum(a[1::2]))


# Example run
# Input:
1288
-11392175
# Output:
-11392175
n = int(input())
li = list(map(int,input().split()))
list.sort(li, reverse = True)
switch = 1
Alice = 0
Bob = 0
for i in li:
    if switch == 1:
        Alice += i
        switch = 0
    else:
        Bob += i
        switch = 1
print(Alice - Bob)

# Example run
# Input:
19487
-126312
# Output:
-126312
n = int(input())
a=list(map(int, input().split()))

a.sort(reverse=True)
alice=0
bob=0
for i in range(len(a)):
  if i%2 ==0 :
    alice+=a[i]
  else:
    bob+=a[i]
print(alice-bob)

# Example run
# Input:
13
-123410341
# Output:
-123410341
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
A.sort(reverse=True)
Alice = []
Bob = []

for i in range(N):
  if i % 2 == 0:
    Alice.append(A[i])
  else:
    Bob.append(A[i])

print(sum(Alice) - sum(Bob))

# Example run
# Input:
-52564348
-7737
# Output:
0
firstint = int(input())
inputary = input()
listA= inputary.split()
numlist =[ int(x) for x in listA]
numlist.sort(reverse=True)
Alice = 0
Bob = 0
for index,elm in enumerate(numlist):
    if index % 2 == 0:
        Alice += int(numlist[index])
    else:
        Bob += int(numlist[index])

print(Alice - Bob)

# Example run
# Input:
-14665841
-235202
# Output:
-235202