Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
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:
-180
-525602
# Output:
0
N = int(input())
a = list(map(int, input().split()))

alice = 0
bob = 0

for n in range(N):
    card = max(a)
    alice += card
    a.remove(card)
    if len(a) == 0:
        break
    card = max(a)
    bob += card
    a.remove(card)

print(alice - bob)

# Example run
# Input:
-162200336
-259420352
# Output:
0
if __name__ == '__main__':
    n = int(input())
    k = [int(i) for i in input().split()]
    a = 0
    b = 0
    k.sort(reverse=True)
    flag = True
    for i in k:
        if flag == True:
            a+=i
            flag=False
        else:
            b+=i
            flag=True
    print(a-b)


# Example run
# Input:
-27928965
7381
# Output:
7381
def cardGameForTwo():
	N = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	diffPoint = 0 
	for index in range(0, N):
		if index % 2 == 0:
			diffPoint += a[index]
		else:
			diffPoint -= a[index]
	print(diffPoint)

cardGameForTwo()

# Example run
# Input:
-2540
-1836
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
s1 = 0
s2 = 0
for i in range(0, n, 2):
    s1 += a[i]
for i in range(1, n, 2):
    s2 += a[i]
print(s1 - s2)


# Example run
# Input:
-740
1
# Output:
0
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
al=0
bo=0
 
for i in range(n):
    if i==0 or i%2==0:
        al+=a.pop(0)
    else:
        bo+=a.pop(0)
 
print(al-bo)

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

a.sort(reverse=True)

ans1 = a[::2]
ans2 = a[1::2]

print(sum(ans1)-sum(ans2))

# Example run
# Input:
-887384
13499019
# Output:
13499019
N = int(input())
A = int(input())
card_list = [A]
print(card_list)

# Example run
# Input:
66907706
3425848
# Output:
[3425848]
N = int(input())
card = [int(x) for x in input().split()]

a_sum=0
b_sum=0

for i in range((N+1)//2):
    max_value=max(card)
    max_index=card.index(max_value)
    a_sum+=max_value
    card[max_index]=0

    max_value=max(card)
    max_index=card.index(max_value)
    b_sum+=max_value
    card[max_index]=0

print(a_sum-b_sum)

# Example run
# Input:
-105221
2147483647
# Output:
0
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    card_count = int(input())

    card_numbers = [int(i) for i in input().split()]
    card_numbers.sort(reverse=True)

    alice_score = 0
    bob_score = 0

    alice_cards = card_numbers[::2]
    bob_cards = card_numbers[1::2]

    for i in range(len(alice_cards)):
        alice_score += alice_cards[i]

    for j in range(len(bob_cards)):
        bob_score += bob_cards[j]

    diff = alice_score - bob_score
    print(diff)


# Example run
# Input:
-5927
141879
# Output:
141879
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)

a = sum(l[::2])
b = sum(l[1::2])
print(a-b)


# Example run
# Input:
-31
-58867430
# Output:
-58867430
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()		# 配列を降順に並べ替える

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


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


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


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

a.sort(reverse = True)
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:
-56834839
1288
# 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:
64303
-47268285
# Output:
-47268285
from collections import deque
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
q_li = deque(lis)
a = 0
b = 0
for l in range(n):
    if l % 2 == 0:
        a += q_li.popleft()
    else:
        b += q_li.popleft()
print(a-b)


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

alice = []
bob = []

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

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

# Example run
# Input:
-69520
-73864104
# Output:
0
N = int(input())
cards = list(map(int, input().split()))

cards.sort(reverse = True)
sum_A = 0
sum_B = 0


for i in range(N):
    if i % 2 == 0:
        sum_A += cards[i]
    else:
        sum_B += cards[i]

print(sum_A - sum_B)

# Example run
# Input:
-58138
-607
# Output:
0
N = int(input())
A_list = sorted(list(map(int, input().split())))[::-1]
a_sum = 0
b_sum = 0

for i in range(N):
    if i % 2 == 0:
        a_sum += A_list[i]
    else:
        b_sum += A_list[i]
print(a_sum - b_sum)

# Example run
# Input:
-1141
359
# Output:
0
#088B
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
#print(a)

player_a=[]
player_b=[]

for i in range(len(a)):
	if(i==0 or i%2==0):
		player_a.append(a[i])
	else:
		player_b.append(a[i])

sum_a=sum(player_a)
sum_b=sum(player_b)

ans=sum_a-sum_b

print(ans)

# Example run
# Input:
134
-5930
# Output:
-5930
n = int(input())
a = [int(n) for n in input().split(" ")]

a.sort()

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

# Example run
# Input:
-13
7381
# Output:
7381
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = 0
for i in range(n):
    ans += a[i] * (-1 if i & 1 else 1)
print(ans)


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

a.sort()
a.reverse()

alice,bob=0,0

if n%2 == 0:
    for i in range(int(n/2)):
        alice += a[2*i]
        bob += a[2*i+1]
else:
    for i in range(int((n+1)/2)):
            alice += a[2*i]
            bob += a[2*i+1] if 2*i+1<len(a) else 0

print(alice-bob)


# Example run
# Input:
-28418
-29
# Output:
0
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += A[i]
    else:
        ans -= A[i]

print(ans)


# Example run
# Input:
-162200336
-259420352
# Output:
0
N = int(input())
alice = []
bob = []
L = sorted(list(map(int, input().split())))[::-1]
for i in range(N):
  if i%2==0:
    alice.append(L[i])
  else:
    bob.append(L[i])
print(sum(alice)-sum(bob))

# Example run
# Input:
-264371717
10366
# 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:
465
0
# Output:
0
input()
li = list(map(int, input().split()))
li.sort(reverse=True)
alice = sum([i for index,i in enumerate(li) if index % 2 == 0])
ans = alice * 2 - sum(li)
print(ans)

# Example run
# Input:
6ej=k^S/8
981571
# Output:
981571
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
print(sum(a[::2]) - sum(a[1::2]))

# Example run
# Input:
5182
0
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=1)
print(sum(a[::2]) - sum(a[1::2]))

# Example run
# Input:
10559
1792657
# Output:
1792657
n = input()
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:
AuyGE(ah
-2503
# Output:
-2503
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
print(sum(l[::2])-sum(l[1::2]))

# Example run
# Input:
-16
-4
# Output:
-4
n=int(input())
a=[int(k) for k in input().split()]
a.sort()
s=0
for i in range(len(a)):
    s+=(pow(-1,i)*a[len(a)-1-i])
print(abs(s))

# Example run
# Input:
186860433
108968
# Output:
108968
N = int(input())

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

card.sort(reverse=True)

Alice = [card[i] for i in range(0, N, 2)]
Bob = [card[i] for i in range(1, N, 2)]

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

# Example run
# Input:
-2503
10842
# Output:
0
n = int(input())
cards = list(map(int,input().split()))
cards.sort(reverse=True)
Alice = 0
Bob = 0
for i in range(0, n, 2):
  Alice += cards[i]
for j in range(1, n, 2):
  Bob += cards[j]
z = Alice - Bob
print(z)

# Example run
# Input:
-959568
-377
# Output:
0
n=int(input())
a=list(map(int, input().split()))
alice=0
bob=0
for i in range(n):
    tmp=a.pop(a.index(max(a)))
    if(i%2==0):
        alice+=tmp
    else:
        bob+=tmp
print(alice-bob)


# Example run
# Input:
-3249
901872
# Output:
0
n = int(input())
*A, = map(int, input().split())
A.sort(reverse=True)
turn = 0
x, y = 0, 0
for a in A:
    if turn == 0:
        x += a
    else:
        y += a
    turn = (turn+1) % 2
print(x-y)


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

# Example run
# Input:
56
1049999
# Output:
1049999
#B
n = int(input())
a = list(map(int, input().split()))
a_1 =  sorted(a, reverse=True)
alice = 0
bob = 0

for i in range(0, len(a)):
    if i % 2 != 0:
        bob += a_1[i]
    if i % 2 == 0:
        alice += a_1[i]
        
print (alice - bob)

# Example run
# Input:
-84564737
-18579092
# Output:
-18579092
N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
a.reverse()
Alice_Bob = 0
Bob = 1

for i in a:
	Alice_Bob += i * Bob  
	Bob *= -1
    
print(Alice_Bob)


# Example run
# Input:
6534
2147483647
# Output:
2147483647
N=int(input())
s = sorted(list(map(int,input().split())))
print(abs(sum(s[:N:2])-sum(s[1:N:2])))

# Example run
# Input:
-52564348
-7737
# Output:
0
def main():
    N = int(input())
    a_s = list(map(int,input().split()))
    a_s.sort()
    a_s.reverse()
    Alice,Bob = 0,0
    for i,a in enumerate(a_s):
        if i % 2 == 0:
            Alice += a
        else:
            Bob += a
            
    print(Alice-Bob)


if __name__ == '__main__':
    main()

# Example run
# Input:
10
6252
# Output:
6252
N = int(input())
a_list = list(map(int, input().split()))

sort_a_list = sorted(a_list)

alice_list = []
bob_list = []

for i, a in enumerate(sort_a_list):
    index = i + 1
    if i % 2 == 1:
        alice_list.append(a)
    elif i % 2 == 0:
        bob_list.append(a)

print(sum(alice_list) - sum(bob_list))

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

a.sort(reverse=True)

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

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

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

# Example run
# Input:
-789711774
53
# Output:
0
N=int(input())
*A,=map(int,input().split())

A.sort()
print(sum(A[::-2])-sum(A[-2::-2]))

# Example run
# Input:
134
-5930
# Output:
-5930
def resolve():
    N = int(input())
    arr = list(map(int, input().split()))
    arr.sort(reverse=True)

    ascore = 0
    bscore = 0
    for i in range(N):
        if i%2 == 0:
            ascore += arr[i]
        else:
            bscore += arr[i]

    print(ascore - bscore)
    
resolve()

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

# Example run
# Input:
#:Tc`e
901872
# Output:
901872
N = int(input())
a = list(map(int, input().split()))

A = 0
B = 0
while True:
  m_a = max(a)
  A += m_a
  a.remove(m_a)
  if len(a) == 0: break
  
  m_b = max(a)
  B += m_b
  a.remove(m_b)
  if len(a) == 0: break

print(A-B)

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

# Example run
# Input:
-3108573
51
# Output:
51
N=int(input())
A=sorted(list(map(int,input().split())),reverse=True)
alice=0
bob=0
for i in range(len(A)):
    if i%2==0:
        alice=alice+A[i]
    else:
        bob=bob+A[i]
print(alice-bob)

# Example run
# Input:
1418198351
9
# Output:
9
n=int(input())
a=list(map(int,input().split()))
s=0
a.reverse()
s=sum(a[:n:2])-sum(a[1:n:2])
print(s)

# Example run
# Input:
-5
-64
# Output:
0
N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(N):
    x = max(a)
    a.remove(x)
    if i % 2 == 0:
        ans += x
    else:
        ans -= x
print(ans)

# Example run
# Input:
-60254091
-960
# 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:
-84521052
-2
# Output:
-2
N = int(input())
A = [int(n) for n in input().split()]
A = sorted(A,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:
-6163826
139893
# Output:
0
n=int(input())
s=list(map(int,input().split()))
s=sorted(s)
s.reverse()
sum=0
for i in range(n):
    if i%2==0:
        sum+=s[i]
    else:
        sum-=s[i]
print(int(sum))
        






# Example run
# Input:
0
1418198351
# Output:
0
N = int(input())
A = list(map(int, input().split()))
alice = 0
bob = 0
A.sort()
for i in range(N):
	if i % 2 ==0:
		alice += A[-i - 1]
	else:
		bob += A[-i - 1]

print(alice - bob)

# Example run
# Input:
0
-10855
# Output:
0
n = int(input())
l = sorted(list(map(int, input().split())), reverse=True)
Alice = 0
Bob = 0

for i in range(len(l)):
    if i % 2 == 0:
        Alice += l[i]
    else:
        Bob += l[i]
print(Alice - Bob)

# Example run
# Input:
28016
-48
# Output:
-48
N = int(input())

a = [int(x) for x in input().split()]

a.sort()
ali = 0
bob = 0

for i in range(N):
    if i % 2 == 0:
        ali += a[N-1-i]
    else:
        bob += a[N-1-i]
print(ali-bob)

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

a.sort()

Alice = 0
Bob  = 0

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

print(Alice - Bob)

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

# Example run
# Input:
-224484380
171476207
# Output:
171476207
_ = input()
A = list(map(int, input().split()))

A.sort(reverse=True)
alice = sum([a for i, a in enumerate(A) if i%2 == 0])
bob   = sum([a for i, a in enumerate(A) if i%2 == 1])
print(alice - bob)

# Example run
# Input:
:4}
-4693
# Output:
-4693
N = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
a = sorted(a, key= lambda x: -x)

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

# Example run
# Input:
-887384
13499019
# Output:
13499019
# -*- coding: utf-8 -*-

cnt = int(input())
card_list = [int(i) for i in input().split()]

# 2人の得点
alice = 0
bob = 0

# 高得点順にカードを並べ替え
card_list.sort(reverse=True)

for i in range(cnt):
    # 0開始で偶数ならAlice、奇数ならBobに加点する
    if i % 2 == 0:
        alice += card_list[i]
    else:
        bob += card_list[i]
# 得点差を出力
print(alice - bob)

# Example run
# Input:
-497
-15860207
# Output:
0
import re  # 正規表現, findall('正規表現', 文字列), search('正規表現', 文字列)
import sys # プログラム終了：sys.exit()
# sys.setrecursionlimit(10**6) # 再帰呼び出しの上限を上げる

def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))
# 文字列のまま受け取りたいときはinput()

N = i_input()
A = l_input()

alice = 0
bob = 0

for i in range(N):
    biggest = max(A)
    if i % 2 == 0:
        alice += biggest
    else:
        bob += biggest
    A.remove(biggest)

print(alice - bob)


# Example run
# Input:
-659
0
# Output:
0
n=input()

a=sorted(map(int,input().split()))[::-1]

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

# Example run
# Input:
-},1x
-3964499
# Output:
-3964499
n=int(input())
a=list(map(int,input().split()))
a.sort()
s=0
for i in range(len(a)):
  s+=a[i]*((-1)**i)
print(abs(s))

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

# Example run
# Input:
17754
6
# Output:
6
N=int(input())
A=sorted(list(map(int,input().split())),reverse=True)

al=0
bo=0
for i in range(N):
    if i % 2==0:
        al+=A[i]
    else:
        bo+=A[i]
        
print(al-bo)

# Example run
# Input:
-2552
-330190783
# Output:
0
n=int(input())
ls = list(map(int,input().split()))
ls.sort()
ls.reverse()
ans=0
t = 1
for i in range(n) :
 ans += t * ls[i]
 t *= -1
print(ans)

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

a.sort(reverse=True)
A = 0
B = 0
for i in range(N) :
    if i % 2 == 0 :
        A += a[i]
    else :
        B += a[i]
print(A-B)

# Example run
# Input:
-6
-1138
# Output:
0
#88b
N = int(input())
a_list = [int(e) for e in input().split()]

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


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

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

print(ans)

# Example run
# Input:
5831819
-812896393
# Output:
-812896393
n = int(input()) 
A = list(map(int, input().split()))
A.sort(reverse = True) 
print(sum(A[::2])-sum(A[1::2]))

# Example run
# Input:
14111
112
# Output:
112
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
for i in range(N):
    if i % 2 == 0:
        A = max(a)
        Alice = Alice + A
        a.remove(A)
    else:
        A =max(a)
        Bob = Bob + A
        a.remove(A)
print(Alice - Bob)

# Example run
# Input:
-84559984
-58783
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))

# Example run
# Input:
-5
43544301
# Output:
43544301
N = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
alice = []
bob = []

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

difference = abs(sum(alice) - sum(bob))
print(difference)


# Example run
# Input:
-80
-7517
# Output:
7517
n=int(input())
a=[int(i) for i in input().split()] 
a.sort()
#print(a)
ans=0
flag=1
for i in range(n):
  ans+=(-1)**(i%2)*int(a[-1-i])
print(int(ans))


# Example run
# Input:
-5992
-1
# 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:
-307298630
-1794
# Output:
-1794
N = int(input())

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

a.sort(reverse=True)
ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += a[i]
    else:
        ans -= a[i]

print(ans)

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


# Example run
# Input:
-48655
32683
# Output:
32683
n = int(input())
a = list(map(int,input().split()))
alice = 0
bob = 0

a.sort()
a.reverse()


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

print(alice - bob)
print(a)    


# Example run
# Input:
-28
187
# Output:
0
[187]
N = int(input())
a = input()
a=a.split()
a=[int(s) for s in a]
list.sort(a, reverse=True)
alice = 0
bob = 0

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


# Example run
# Input:
-2147483648
-23476
# Output:
0
N = int(input())
a = sorted([int(x) for x in input().split()], reverse=True)
alice = bob = 0
for i,x in enumerate(a):
    if i%2 == 0:
        alice += x
    else:
        bob += x
print(alice - bob)


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

a.sort(reverse="True")

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

# Example run
# Input:
677816
7
# Output:
7
N = int(input())
a = sorted(list(map(int,input().split())), reverse=True)

Alice = 0
Bob = 0

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

res = Alice - Bob

print(res)

# Example run
# Input:
-755
-256478906
# Output:
0
money = int(input())
A = int(input())

if (money % 500) > A:
    print('NO')
else:
    print('YES')


# Example run
# Input:
2147483647
63
# Output:
NO
N = input()
a = list(map(int, input().split()))
a_sorted = sorted(a, reverse=True)
is_alice = True
a_score = 0
b_score = 0
for num in a_sorted:
    if is_alice == True:
        a_score += num
        is_alice = False
    else:
        b_score += num
        is_alice = True
        
print(a_score - b_score)

# Example run
# Input:
oau}Q!*
7987516
# Output:
7987516
a = int(input())
b = list(map(int,input().split()))
b.sort(reverse=True)
c = sum(b[::2])
d = sum(b[1::2])
print(c-d)

# Example run
# Input:
-31584
2421820
# Output:
2421820
numS = int(input())
num1 = [int(i) for i in input().split()]
num1.sort(reverse=True)

numA = []
numB = []

for index1 in range(numS ):
    if index1%2 == 0:
        numA.append(num1[index1])
    else:
        numB.append(num1[index1])

print(str(sum(numA) - sum(numB)))

# Example run
# Input:
-155785153
-104837
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = list()
Bob = list()
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:
-15860207
-54634663
# Output:
0
N = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)

A = 0
B = 0
idx = 0
for card in cards:
    if idx % 2 == 0:
        A += card
    else:
        B += card
    idx += 1
result = A - B
print(result)

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

# Example run
# Input:
)GJ`Wy
-61
# Output:
-61
a=int(input())
b=[int(i) for i in input().split()]
c=sorted(b)
d=0
if round(len(c))==1:
	d=c[-1]
else:
	for i in range(round(len(c)/2)):
		d=d+c[-2*i+1]-c[-2*i]
print(d)


# Example run
# Input:
-230914
-246934
# Output:
-246934
# -*- coding: utf-8 -*-
n = int(input());
a = list(map(int, input().split(' ')));
alice = [];
bob   = [];

for x in range(n):
    m = max(a);
    i = a.index(m);
    if ( x%2 == 0):
        alice.append( a.pop(i) );
    else:
        bob.append( a.pop(i) );

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

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


# Example run
# Input:
-14
0
# Output:
0
n = int(input())
a_lis = list(map(int, input().split()))
a_lis.sort(reverse=True)
alice = True
al_lis = []
bo_lis = []
for i in a_lis:
    if alice:
        al_lis.append(i)
    else:
        bo_lis.append(i)
    alice = not alice
print(sum(al_lis) - sum(bo_lis))

# Example run
# Input:
1
-84
# Output:
-84
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for i,ai in enumerate(a):
    if i%2==0:
        ans += ai
    else:
        ans -= ai
print(ans)


# Example run
# Input:
-75
57223618
# Output:
57223618
def abc088_b():
    _ = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    print(sum(a[::2]) - sum(a[1::2]))


abc088_b()

# Example run
# Input:
-252699780
988493674
# Output:
988493674