Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
N = int(input())
a = list(map(int,input().split()))

x = sorted(a)[::-1]
sum_al = 0
sum_bb = 0
for i in range(N):
    if i % 2 ==0:
        sum_al += x[i]
    else:
        sum_bb += x[i]

print(sum_al - sum_bb)


# Example run
# Input:
0
1418198351
# Output:
0
a=int(input())
b=[int(i) for i in input().split()]
c=sorted(b)
#print(c)
d=sum(c[0::2])
e=sum(c[1::2])
print(abs(e-d))


# Example run
# Input:
1
-38175
# Output:
38175
import math
import itertools
import statistics
#import collections
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]
 
print(alice-bob)

# Example run
# Input:
-755
-256478906
# Output:
0
#!/usr/bin/env python3

def main():
    sn = input()
    sa = input().split(' ')
    a = [int(s) for s in sa]

    a.sort()
    a.reverse()
    na = 0
    nb = 0
    for n in a[0::2]:
        na += n
    for n in a[1::2]:
        nb += n

    print(na - nb)


if __name__ == '__main__':
    main()


# Example run
# Input:
T~.yFv
4
# Output:
4
N=int(input())
a=list(map(int,input().split()))
l=len(a)
a.sort(reverse=True)
alice=bob=c=0
for i in range(l):
    if c%2==0:
        alice+=a[i]

    else:
        bob+=a[i]
    c+=1
print(alice-bob)



# Example run
# Input:
168618
188355
# Output:
188355
n = int(input())
A = sorted([int(i) for i in input().split()])

alice = []
bob = []

while len(A) > 0:
    a = A.pop()
    alice.append(a)
    if len(A) > 0:
        b = A.pop()
        bob.append(b)
    

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

# Example run
# Input:
-1005
39756387
# Output:
39756387
n=int(input())
a=list(map(int,input().split()))
alice=[]
bob=[]
for i in range(len(a)):
    alice.append(max(a))
    a.remove(max(a))
    if len(a)==0:
        print(sum(alice)-sum(bob))
        break
    bob.append(max(a))
    a.remove(max(a))
    if len(a)==0:
        print(sum(alice)-sum(bob))
        break


# Example run
# Input:
-316
-160045822
# Output:
-160045822
n = input()
a = list(map(int, input().split()))
a.sort()
ans = 0

for i, j in enumerate(a):
    if i % 2 == 0:
        ans += j
    else:
        ans -= j

print(abs(ans))

# Example run
# Input:
&0/F!2e
-330190783
# Output:
330190783
N = int(input())
list_a = list(map(int, input().split()))
list_a.sort(reverse=True)
Alice = sum(list_a[::2])
Bob = sum(list_a[1::2])
print(Alice-Bob)

# Example run
# Input:
3132478
-7930
# Output:
-7930
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = 0
f = 0
for a in A:
  if f == 0:
    ans += a
  else:
    ans -= a
  f ^= 1
print(ans)

# Example run
# Input:
5182
0
# Output:
0
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[i]
  else:
    Bob += a[i]
print(Alice-Bob)

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

# Example run
# Input:
1
-124978655
# Output:
-124978655
n=int(input())
a=list(map(int,input().split()))
a.sort()
A=0
B=0
for i in range(n):
    if i%2==0:
        A+=a[i]
    else:
        B+=a[i]
print(abs(A-B))

# Example run
# Input:
-75
57223618
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
total = 0
for i,x in enumerate(a):
  total += x*(-1)**i
print(total)

# Example run
# Input:
-80
19
# Output:
19
N = int(input())
a = list(map(int, input().split()))
r = 0
for i in range(len(a)):
    m = max(a)
    a.remove(m)
    # print(m)
    if i % 2 == 0:
        r += m
    else:
        r -= m
print(r)

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


# Example run
# Input:
141725276
-109089799
# Output:
-109089799
N = int(input())
a = list(map(int, input().split( )))
a.sort()
a.reverse()
a_alice = a[::2]
print(sum(a_alice)-(sum(a)-sum(a_alice)))

# Example run
# Input:
-2552
-330190783
# Output:
-330190783
n=int(input())
n_list=list(map(int,input().split()))
alice=[]
bob=[]
while(n_list!=[]):
    a=max(n_list)
    alice.append(a)
    n_list.remove(a)
    if(n_list==[]):
        break
    b=max(n_list)
    bob.append(b)
    n_list.remove(b)
print(sum(alice)-sum(bob))

# Example run
# Input:
-58867430
-56661351
# Output:
-56661351
n = int(input())
aaa = list(map(int, input().split()))
aaa.sort(reverse=True)
al = sum(aaa[::2])
bb = sum(aaa[1::2])
print(al-bb)


# Example run
# Input:
860
0
# Output:
0
N = int(input())

*A, = map(int, input().split())
A.sort(reverse=True)

sum1 = 0
sum2 = 0

for i in range(len(A)):
    if i%2==0:
        sum1 = sum1 + A[i]
    else:
        sum2 = sum2 + A[i]
print(sum1-sum2)

# Example run
# Input:
0
33729406
# Output:
33729406
N = int(input())
l = map(int, input().split())
ls=sorted(l)[::-1]
for i in range(N):
    Alice = ls[0::2] 
    Bob   = ls[1::2]
print(sum(Alice)-sum(Bob))

# Example run
# Input:
4
-87
# Output:
-87
n = int(input())
al = list(map(int, input().split()))
al.sort(reverse=True)
ali = 0
bob = 0
for i, a in enumerate(al):
    if i % 2 == 0:
        ali += a
    else:
        bob += a
print(ali-bob)


# Example run
# Input:
3132478
-7930
# Output:
-7930
n = int(input())
cards = (list)(map(int, input().split()))

cards = sorted(cards, reverse=True)

print(2*sum(cards[0::2]) - sum(cards))


# Example run
# Input:
-1595467139
3280
# Output:
3280
n=int(input())
s=list(map(int,input().split()))
s=sorted(s)
 
#Alice,Bob
a=[]
b=[]
 
for i in range(n):
    if i%2==0:
        a.append(s[i])
    else:
        b.append(s[i])
        
print(sum(a)-sum(b))

# Example run
# Input:
-497
-15860207
# Output:
0
n = input()
a = list(map(int, input().split()))
a= sorted(a, reverse=True)
print(a)
ans =0
for i in a:
    if i%2 == 0:
        ans += i
    elif i%2 ==1:
        ans -= i
print(ans)

# Example run
# Input:
8LI
32167
# Output:
[32167]
-32167
n=int(input())
a=list(map(int, input().split()))
t=0
a.sort()
for i in range(len(a)):
  if i%2==0:
    t+=a[n-i-1]
  else:
    t-=a[n-i-1]
print(t)


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

a.sort(reverse=True)

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

# Example run
# Input:
-114
-473
# Output:
-473
def main():
    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 = Alice + a[i]
        else:
            Bob = Bob + a[i]
    ans = Alice - Bob
    print(ans)

if __name__ == '__main__':
    main()


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

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

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

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


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

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

# Example run
# Input:
298151
-755
# Output:
-755
n = int(input())
a = sorted(list(map(int,input().split())), reverse=True)
a = [(-1)**i * a_ for i, a_ in enumerate(a)]
print(sum(a))

# Example run
# Input:
-3753932
42339391
# Output:
42339391
N = int(input())
A = [int(_) for _ in input().split()]

xs = sorted(A, reverse=True)

result = sum(xs[0::2]) - sum(xs[1::2])

print(result)


# Example run
# Input:
129445
3
# Output:
3
N = int(input())
A = [int(a) for a in input().split()]
A.sort(reverse=True)
print(sum(A[::2]) - sum(A[1::2]))

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

a.sort(reverse=True)
alice = a[0::2]
bob = a[1::2]

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



# Example run
# Input:
-15303
-412794
# Output:
-412794
N=int(input())
card=list(map(int,input().split()))
card=sorted(card, reverse=True)
a=0
b=0
for i in range(N):
    if i%2==0:
        a+=card.pop(0)
    else:
        b+=card.pop(0)
print(abs(a-b))

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

card.sort()

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

print(alice - bob)

# Example run
# Input:
493
471
# Output:
471
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)

t=0

for i, a in enumerate(A):
    i = i%2
    if i == 0:
        t = t + a
    else:
        t = t - a

print(t)

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

a = sorted(a, reverse=True)

Alice = sum(a[0::2])
Bob = sum(a[1::2])

print(Alice-Bob)

# Example run
# Input:
2116
-579377
# Output:
-579377
N=int(input())
a=list(map(int,input().split()))
na=sorted(a)
Alice=0
Bob=0

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

print(Alice-Bob)

# Example run
# Input:
-93260937
-1469
# Output:
0
data = [input() for x in range(0, 2, 1)]

cards = [int(x) for x in data[1].split(" ")]

#バブルソート
for i in range(0, len(cards), 1):
  
  for j in range(i + 1, len(cards), 1):
    
    if cards[i] > cards[j]:
      tmp1 = cards[i]
      tmp2 = cards[j]
      
      cards[i] = tmp2
      cards[j] = tmp1
      
alice = 0
bob = 0

#cardsをソート

for i, v in enumerate(cards):
  
  if i %2 == 0:
    alice += v
  else:
    bob += v
    
print(alice - bob)


# Example run
# Input:
]O!i,=y=R
1
# Output:
1
n = input()
card = list(map(int, input().split()))
l = sorted(card, reverse=1)
Alice, Bob = 0, 0
for i in range(len(l)):
    if i % 2:
        Bob += l[i]
    else:
        Alice += l[i]
print(Alice-Bob)


# Example run
# Input:
My>_*s
-15015728
# Output:
-15015728
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
A = sum(a[0:N:2])
B = sum(a[1:N:2])
print(A-B)


# Example run
# Input:
3876
11099514
# Output:
11099514
n = int(input())
l = [int(x) for x in input().split()]
a = 0
b = 0
for i in range(n):
  if i % 2 == 0:
    a += max(l)
    l = l.remove(max(l))
  elif i % 2 == 1:
    b += max(l)
    l = l.remove(max(l))
print(a-b)

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


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

c.sort()

a=b=0
d=len(c)
for i in range(d):
    if i%2==0:
        a+=c[d-i-1]
    else:
        b+=c[d-i-1]

print(abs(a-b))


# Example run
# Input:
-2147483648
-1406309
# Output:
1406309
n = int(input())
l = list(map(int, input().split(' ')))

l.sort()
l.reverse()

result = 0

for e in enumerate(l):
    result += e[1] if e[0] % 2 == 0 else -e[1]

print(result)

# Example run
# Input:
-887384
13499019
# Output:
13499019
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:
-14
1949
# Output:
0
n = int(input())
a_list = list(map(int,input().split()))
s_a_list = sorted(a_list)
alice = 0
bob = 0
while len(s_a_list)>1:
  alice += s_a_list.pop(-1)
  bob += s_a_list.pop(-1)
if len(s_a_list) != 0:
  alice += s_a_list.pop(-1)
print(alice-bob)


# Example run
# Input:
493
471
# Output:
471
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:
-7
-7737
# Output:
-7737
_=input()
a=sorted((map(int,input().split())),reverse=True)
print(sum(a[0::2])-sum(a[1::2]))

# Example run
# Input:
=M6D&5E(
-904
# Output:
-904
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]

print(Alice - Bob)

# Example run
# Input:
-75
57223618
# Output:
0
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()

A = A + [0, 0, 0, 0, 0]
sum = 0
for i in range(N//2 + 2):
  sum = sum + A[i*2] - A[i*2 + 1]
  
print(sum)

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



# Example run
# Input:
D`T
-128117474
# Output:
-128117474
n=int(input())
s=list(map(int,input().split()))
s.sort(reverse=True)
a=[int(i) for i in s[::2]]
b=[int(j) for j in s[1::2]]
print(sum(a)-sum(b))

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

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

# Example run
# Input:
112734
211
# Output:
211
N = int(input())
A = sorted(list(map(int, input().split())))
print(sum(A[::-2])-sum(A[-2::-2]))

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

# リストの中身を降順ソートする
# 元のリストを保持したいならsorted()
a.sort(reverse = True)

alice, bob = 0, 0

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

print(alice - bob)

# Example run
# Input:
18575536
-48655
# Output:
-48655
def card_game():
    n = int(input())
    a_li = [int(i) for i in input().split()]
    ans = 0
    turn_switch = True

    a_li.sort()

    for i in a_li:
        if turn_switch:
            ans += i
            turn_switch = False
        else:
            ans -= i
            turn_switch = True

    return ans


if __name__ == '__main__':
    print(card_game())

# Example run
# Input:
-755
-256478906
# Output:
-256478906
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]

print(alice-bob)


# Example run
# Input:
-30
-54634663
# Output:
0
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 += a[i]
    else:
        bob += a[i]

print(alice - bob)

# Example run
# Input:
-54634663
3615919
# Output:
3615919
# coding: UTF-8

N = int(input())
a = list(map(int, input().split()))
sum_a, sum_b = 0, 0

for i in reversed(range(1, N)):
    for j in reversed(range(1, i+1)):
        if a[j-1] < a[j]:
            s = a[j-1]
            a[j-1] = a[j]
            a[j] = s

for i in range(0, N, 2):
    sum_a += a[i]
for i in range(1, N, 2):
    sum_b += a[i]

print(sum_a - sum_b)

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

# Example run
# Input:
757115353
-7698469
# Output:
-7698469
n = int(input())

a_list = list(map(int, input().split()))
# print(a_list)

a_list = sorted(a_list, reverse=True)
# print(a_list)

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

# Example run
# Input:
-153163
-32942311
# Output:
-32942311
n = int(input())
a = sorted((int(s) for s in input().split()), reverse=True)
ans = sum(v * (-1 if i & 1 else 1) for i, v in enumerate(a))
print(ans)

# Example run
# Input:
-11385106
-114
# Output:
-114
def main():
    N = int(input())
    a = list(map(int, input().split()))
    totalAlice = 0
    totalBob = 0
    a.sort()
    a.reverse()
    for i in range(len(a)):
        if(i % 2 == 0):
            totalAlice += a[i]
        else:
            totalBob += a[i]
    print(totalAlice - totalBob)
main()

# Example run
# Input:
-64990941
-12142
# Output:
-12142
N = int(input())

As = sorted(map(int,input().split()),reverse=True)

alice = 0
bob = 0

for i in range(0,N,2):
    alice += As[i]
    if i < N - 1:
        bob += As[i + 1]

print(alice - bob)

# Example run
# Input:
-15
3431161
# Output:
0
N = int(input())

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

a.sort(reverse=True)

i = 0
A = 0
B = 0

for k in a:
	if i % 2 == 0:
		A += k
	else:
		B += k
	i += 1

print(A - B)

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

# Example run
# Input:
31499
-58743
# Output:
-58743
c = 0
N = int(input())
A = list(map(int, input().split(" ")))
A.sort(reverse=True)
for i in range(N):
    if ((i+1) % 2) != 0:
        c+=A[i]
    else:
        c-=A[i]
print(c)

# Example run
# Input:
-29
-5363
# Output:
0
n = int(input())
a = list(map(int,input().split()))
Ali=0
Bob=0
a.sort()
ab_flag=0
while len(a)!=0:
    if ab_flag==0:
        Ali += a.pop()
        ab_flag=1
    else:
        Bob += a.pop()
        ab_flag=0
print(Ali-Bob)

# Example run
# Input:
-83
-39355
# Output:
-39355
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:
-28418
-29
# Output:
0
N = input()
n = list(map(int, input().split()))
n.sort(reverse=True)
print(sum(n[::2])-sum(n[1::2]))

# Example run
# Input:
LPW
3789255
# Output:
3789255
def main():
    num_ans = int(input())
    card_list = list(map(int, input().split()))
    card_list.sort()
    card_list.reverse()
    print(sum(card_list) - sum(card_list[1::2]) * 2)


if __name__ == '__main__':
    main()


# Example run
# Input:
793
439273
# Output:
439273
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a = deque(sorted(a))#[::-1]
alice, bob = 0, 0
for i in range(n):
    if i%2==0: alice += a.popleft()
    else: bob += a.popleft()
print(alice - bob)

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

# Example run
# Input:
-1595467139
3280
# Output:
0
n = int(input())
argList = list(map(int, input().split()))
argList.sort()
argList.reverse()
a=0
b=0

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

# Example run
# Input:
-597522
-2530418
# Output:
0
#10
n = int(input())
card = list(map(int,input().split()))
card.sort(reverse = True)
A,B = 0,0
for i,j in enumerate(card):
    if i % 2 == 0:
        A += j
    else:
        B += j

print(A-B)

# Example run
# Input:
72046879
23263394
# Output:
23263394
n = int(input())
a = [int(i) for i in 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:
1
21507
# Output:
21507
#abc088 b-card game for two
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
for i in range(len(a)):
    if i%2==0:
        ans+=a[i]
    else:
        ans-=a[i]
print(ans)

# Example run
# Input:
-4941179
-1
# Output:
-1
n = input()
scores = list(map(int, input().split()))

scores.sort()
scores.reverse()
alice_flag = True
alice_score = 0
bob_score = 0

for score in scores:
    if alice_flag:
        alice_score += score
        alice_flag = False
    else:
        bob_score += score
        alice_flag = True

print(alice_score - bob_score)


# Example run
# Input:
R6O
-197
# Output:
-197
N = int(input())
num = list(map(int, input().split()))
num.sort(reverse=True)

A = 0
B = 0
for i in range(N):
    if i%2==0:
        A += num[i]
    else:
        B += num[i]

diff = A - B
print(diff)

# Example run
# Input:
-27566650
49968
# Output:
0
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 += a[i]
    else:
        bob += a[i]
print(alice-bob)

# Example run
# Input:
-967
-58799
# Output:
0
import math
N=int(input())
a=list(map(int,input().split()))
a=sorted(a)
print(a)
alice=0
bob=0
if(N%2==0):
    for i in range(0,N-1,2):
        alice=a[i+1]+alice
        bob=a[i]+bob
else:
    for i in range(1,N-1,2):
        alice=a[i+1]+alice
        bob=a[i]+bob
    alice=alice+a[0]
print(alice-bob)

# Example run
# Input:
-168854
-5
# Output:
[-5]
0
n = int(input())
card_list = list(map(int,input().split(" ")))

card_list_ex = sorted(card_list, reverse=True)


alice,bob = 0,0
for i,j in enumerate(card_list_ex):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
res = alice - bob
print(res)

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

# Example run
# Input:
P)4WbEwF
-27123728
# Output:
-27123728
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
x = sum(a[0::2])
y = sum(a[1::2])
print(abs(x - y))

# Example run
# Input:
446
0
# Output:
0
n=int(input())
card=list(map(int,input().split()))
card.sort()
result=0
while len(card)>0:
   result+=card.pop()
   if len(card)>0:
       result-=card.pop()
print(result)

# Example run
# Input:
3615919
-3550
# Output:
-3550
N = int(input())
arr = sorted(list(map(int, input().split())), reverse=True)
alice_total, bob_total = 0, 0

for i in range(len(arr)):
    if i % 2 == 0:
        alice_total += arr[i]
    else:
        bob_total += arr[i]
print(alice_total - bob_total)


# Example run
# Input:
-114
-473
# Output:
-473
n = int(input())
a = list(map(int, input().split()))
a.sort()
al = 0
bo = 0
while a:
    al += a.pop(-1)
    if not a:
        break
    bo += a.pop(-1)
print(al-bo)

# Example run
# Input:
-54266464
-274078593
# Output:
-274078593
n = int(input())
s = sorted(list(map(int, input().split())), reverse=True)
A = 0
B = 0
for e, i in enumerate(s):
  if e%2==0:
    A += i
  else:
    B += i
print(A-B)

# Example run
# Input:
23
493
# Output:
493
n = int(input())

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

sortList = sorted(a,reverse=True)

alice = []
bob = []

for i in range(n):
    if i % 2 ==0:
      alice.append(sortList[i])
    if i % 2 != 0:
      bob.append(sortList[i])
        
        
print(sum(alice)-sum(bob))

# Example run
# Input:
-65906
8
# Output:
0
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

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

# Example run
# Input:
0
-212
# Output:
-212
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(sum(A[::-2]) - sum(A[-2::-2]))

# Example run
# Input:
-69520
-73864104
# Output:
-73864104
n = int(input())
arr = list(map(int, input().split()))

arr.sort(reverse=True)
answer = [0, 0]
for index in range(len(arr)):
    answer[index % 2] += arr[index]
print(answer[0] - answer[1])

# Example run
# Input:
47
-5701370
# Output:
-5701370
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,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:
0
1
# Output:
0
n=int(input())
a = list(map(int,input().split()))[:n]
a.sort(reverse=True)

A=B=I=0
for i in a:
    if I %2:B+=i
    else:A+=i
    I+=1

print(A-B)
# other
# print(sum(a[::2]) - sum(a[1::2]))


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

alice = 0
bob = 0

for i in range(1, n+1):
  
  if i % 2 != 0:
    card = max(a)
    alice += card
  else:
    card = max(a)
    bob += card
  
  a.remove(card)
  
print(alice - bob)

# Example run
# Input:
-436344399
-83
# Output:
0
N = int(input())
a = sorted(map(int, input().split()), reverse=True)
alice = 0
bob = 0
for i, n in enumerate(a):
    if i % 2 == 0:
        alice += n
    else:
        bob += n
print(alice - bob)


# Example run
# Input:
-1530217
-68
# Output:
-68
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]

print(alice - bob)

# Example run
# Input:
-3463607
18
# Output:
0