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

a_sum=0
b_sum=0
for i in range(n):
    cnt=0
    max_a=0
    for i in range(n):
        if (a[i]>=max_a):
            max_a=a[i]
            cnt=i
    a_sum = a_sum+a[cnt]
    #print(a_sum,cnt)
    a[cnt]=0
    cnt=0
    max_a=0
    for i in range(n):
        if (a[i]>=max_a):
            max_a=a[i]
            cnt=i
    b_sum = b_sum+a[cnt]
    #print(b_sum)
    a[cnt]=0
print(a_sum-b_sum)
    


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

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


# Example run
# Input:
-161
20
# 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:
-1836
-168854
# Output:
-168854
n = int(input())
a = map(int,input().split())
b = sorted(a)
b.reverse()

Alice = 0
Bob = 0

for i in range(n):
    if i % 2 == 0:
        Alice += b[i]
    else:
        Bob += b[i]
c = Alice - Bob

print(c)

# Example run
# Input:
1
4887419
# Output:
4887419
N = int(input())
card_list = [int(i) for i in input().split()]
card_list.sort(reverse=True)
print(sum(card_list[::2]) - sum(card_list[1::2]))

# Example run
# Input:
-70037
-1002
# Output:
-1002
N = int(input())

cards = map(int, input().split())

sorted_cards = sorted(cards)

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

print(Alice-Bob)

# Example run
# Input:
107
186860433
# Output:
186860433
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
a = sum([v for i, v in enumerate(c) if i % 2 == 0 ])
b = sum([v for i, v in enumerate(c) if i % 2 == 1 ])
print(a - b)

# Example run
# Input:
-15915
-501843
# Output:
-501843
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:
-1018584
-247
# Output:
-247
n = int(input())
alice = 0
bob = 0
cards = [int(val) for val in input().split()]

cards = sorted(cards, reverse=True)

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

# Example run
# Input:
-3463607
18
# Output:
0
N = int(input())
c_list = sorted(list(map(int,input().split())),reverse = True)
a = 0
b = 0

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

# Example run
# Input:
5101803
129445
# Output:
129445
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
Alice = sum(A[::2])
Bob = sum(A)-Alice
print(Alice-Bob)

# Example run
# Input:
17754
6
# Output:
6
N = int(input())
if N == 1:
    a = int(input())
    print(a)
else:
    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:
-247
-12142
# Output:
0
#Card Game for Two
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] > a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a

x = int(input())
cards = input()
card = cards.split(" ")
card = [int(s) for s in card]
bSort(card)
Alice = 0
Bob = 0

for i in range(0,len(card),2):
    Alice += int(card[i])
for i in range(1,len(card),2):
    Bob += int(card[i])
    
print(Alice - Bob)

# Example run
# Input:
10559
1792657
# Output:
1792657
N=int(input())
A_list=list(map(int, input().split()))
A_list = sorted(A_list, reverse=True)
total = 0
for i in range((N+1)//2):
  total = total + A_list[i*2]
print(total)

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

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

# Example run
# Input:
-2
709214891
# Output:
0
N = int(input())
A = sorted([int(X) for X in input().split()],reverse=True)
print(sum(A[::2])-sum(A[1::2]))

# Example run
# Input:
-209505
14111
# Output:
14111
N = int(input())
cards = list(map(int,input().split()))
Alice = []
Bob = []

cards.sort()

for i, x in enumerate(cards):
    if i%2 == 0:
        Alice.append(x)
    else:
        Bob.append(x)

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

# Example run
# Input:
10842
107
# Output:
107
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Alis = 0
Bob = 0

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

# Example run
# Input:
-608
32371647
# Output:
0
n = int(input())
a_list = list(map(int, input().split()))

alice = 0
bob = 0

a_list.sort(reverse=True)

for x in range(0, n, 2):
    alice += a_list[x]

for y in range(1, n, 2):
    bob += a_list[y]

print(alice - bob)


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

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


# Example run
# Input:
-1
-3439167
# Output:
-3439167
n=int(input())
a=list(map(int,input().split()))
alice=0
bob=0
if n%2==0:
    while not len(a)==0:
        alice+=max(a)
        a.remove(max(a))
        bob+=max(a)
        a.remove(max(a))
    print(alice-bob)
else:
    while not len(a)==1:
        alice+=max(a)
        a.remove(max(a))
        bob+=max(a)
        a.remove(max(a))
    alice+=max(a)
    print(alice-bob)  

# Example run
# Input:
-1233237
2527
# Output:
2527
input()
l=sorted(map(int,input().split()))[::-1]
print(sum(l[::2])-sum(l[1::2]))

# Example run
# Input:
rj[ZsdI
941
# Output:
941
n = int(input())
a = [int(i) for i in input().split()]
alice = 0
bob = 0
 
a.sort()
for i in range(1, n+1, 2):
  alice += a[n-i]
  if n-i-1 >= 0:
    bob += a[n-i-1]

    
print(alice-bob)

# Example run
# Input:
-23909
-68
# Output:
0
N = int(input())

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

alice_score = sum(cards[::2])
bob_score = sum(cards[1::2])

print(alice_score - bob_score)


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

# Example run
# Input:
-1138
-22588477
# Output:
0
# B Card Game for Two

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
    
alice = 0
bob = 0
for i, value in enumerate(a):
  if i % 2 == 0:
    alice += value
  else:
    bob += value

print(alice - bob)

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

total_a = 0
total_b = 0

a.sort(reverse=True)
for i in range((n+1)//2):
    total_a += a[i*2]
for i in range(n//2):
    total_b += a[i*2 + 1]
print(total_a - total_b)

# Example run
# Input:
-1406309
-967
# Output:
0
N = int(input())

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

sum_alice = 0
sum_bob = 0
a = sorted(a, reverse=True)

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

print(sum_alice - sum_bob)


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

# Example run
# Input:
NR'(:s!sy
1
# Output:
1
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
total = sum(a)
a_score = 0
for i in range(0,len(a),2):
    a_score += a[i]
print(2*a_score - total)

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

# Example run
# Input:
-40
-18579092
# Output:
-18579092
I = int(input())
L = list(map(int, input().split()))

a = 0
b = 0
while len(L):
    a += L.pop(L.index(max(L)))
    if len(L) == 0: break;
    b += L.pop(L.index(max(L)))

print(abs(a-b))


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

for b in a:
    if (i % 2)==0: Alice += b
    else: Bob += b
    i += 1
print((Alice-Bob))

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


# Example run
# Input:
-1
30456987
# 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]
	else:
		bob += A[-i]

print(alice - bob)

# Example run
# Input:
0
-6956
# Output:
0
N = int(input())
Ali = list(map(int,input().split()))

Ali.sort(reverse = True)

AP = BP = 0

for i in range(N):
  if i%2 == 0:
    AP += Ali[i]
  else:
    BP += Ali[i]

print(AP-BP)

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

# Example run
# Input:
-97071
36241
# Output:
36241
n = int(input())
a = list(input().split())
a.sort(reverse=True)
alice = 0
bob = 0
for index, item in enumerate(a):
    if int(index) == 0 or int(index) % 2 == 0:
        alice += int(item)
    else:
        bob += int(item)
print("{}".format(alice - bob))

# Example run
# Input:
-124978655
-23909
# Output:
-23909
N = int(input())
cards = list(map(int, input().split()))
cards = sorted(cards)

Alice = 0
Bob = 0
while len(cards) >= 2:
    Alice += cards[-1]
    cards = cards[:-1]
    Bob += cards[-1]
    cards = cards[:-1]
if len(cards) == 1:
    Alice += cards[-1]
print(Alice - Bob)


# Example run
# Input:
13087
-31
# Output:
-31
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]
    if i % 2 == 1:
        ans -= A[i]

print(ans)

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

a = sorted(a, reverse=True)

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

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

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

# Example run
# Input:
-20635
-2
# Output:
0
n = int(input())
a = list(map(int, input().split()))
x = []
y = []
for i, v in enumerate(sorted(a, reverse=True)):
    if (i + 1) % 2 != 0:
        x.append(v)
    else:
        y.append(v)
print(sum(x) - sum(y))

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

Alice = []
Bob = []
for i in range(n):
    if i % 2 == 0: 
        Alice.append(max(a))
    else:
        Bob.append(max(a))
    a.remove(max(a))

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


# Example run
# Input:
-118998188
-337
# Output:
0
N = int(input())
A = input().split()
A = [int(a) for a in A]

score_alice= 0
score_bob = 0

while True:
  alice_card = max(A)
  A.remove(alice_card)
  score_alice += alice_card
  
  if len(A) == 0:
    break

  bob_card = max(A)
  A.remove(bob_card)
  score_bob += bob_card
  
  if len(A) == 0:
    break

print(score_alice - score_bob)

# Example run
# Input:
6
-27248
# Output:
-27248
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 0
for i in range(0,N,2):
    ans += a[i]
print(ans*2-sum(a))

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

# Example run
# Input:
-6
-158320719
# Output:
-158320719
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:
-523929617
-147
# Output:
0
N=int(input())
A=list(map(int,input().split()))

A.sort()
A.reverse()

AL=[A[i] for i in range(0,N,2)]
BO=[A[i] for i in range(1,N,2)]

print(sum(AL)-sum(BO))

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

# Example run
# Input:
4743227
# Output:
4743227
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:
-514355545
2248
# 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
      
print(cards)

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:
Lj^Y8
1
# Output:
[1]
1
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:
1
-525059
# Output:
-525059
N = int(input())
cards = [int(x) for x in input().split()]
ALICE = 0
BOB = 0
while cards:
  temp = max(cards)
  cards.remove(temp)
  ALICE+=temp
  if not(cards):
    break
  temp = max(cards)
  cards.remove(temp)
  BOB+=temp

print(ALICE - BOB)

# Example run
# Input:
108901
242419
# Output:
242419
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:
-15015728
42339391
# Output:
0
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

alice = 0
bob = 0
for i, ai in enumerate(a):
    if i % 2 == 0:
        alice += ai
    else:
        bob += ai

print(alice-bob)


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

sorted_A = sorted(A, reverse=True)

Alice_sum = 0
Bob_sum = 0
for i in range(len(sorted_A)):
    if i % 2 == 0:
        Alice_sum = Alice_sum + sorted_A[i]
    else:
        Bob_sum = Bob_sum + sorted_A[i]

print(Alice_sum - Bob_sum)


# Example run
# Input:
5881
44
# Output:
44
N = int(input())
a = sorted(map(int, input().split()))[::-1]

a_p = 0
b_p = 0

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

print(a_p - b_p)


# Example run
# Input:
-6
-420
# Output:
0
def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = 0
    y = 0
    while len(a) > 0:
        m += max(a)
        a.remove(max(a))
        if len(a) == 0:
            break
        y += max(a)
        a.remove(max(a))
    ans = 0
    ans = m - y
    print(ans)
main()


# Example run
# Input:
-53605951
3
# Output:
3
n = int(input())
a = list(int(x) for x in input().split())
a_s = sorted(a, reverse = True)

al = 0
bo = 0
for i in range(n):
    if i % 2 == 0:
        al += a_s[i]
    else:
        bo += a_s[i]

print(al-bo)

# Example run
# Input:
-554740
65444
# Output:
0
N = int(input())
numbers = [x for x in map(int, input().split())]
numbers.sort(reverse=True)
print(sum([numbers[x] for x in range(N) if x % 2 ==0]) 
      - sum([numbers[x] for x in range(N) if x % 2 ==1]))

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

cards.sort(reverse=True)
cards
Alice,Bob = 0,0
flg = 0

while len(cards) != 0:
    if flg == 0: 
        Alice += cards.pop(0)
        flg = 1
    else:
        Bob += cards.pop(0)
        flg = 0
print(Alice-Bob)

# Example run
# Input:
-2090237817
-14
# Output:
-14
def main():
    target_num = input()
    target_list = input().split()

    target_list.sort(reverse=True)

    result_a = 0
    result_b = 0
    a_flg = True
    for target in target_list:
        if a_flg:
            result_a += int(target)
            a_flg = False
        else:
            result_b += int(target)
            a_flg = True

    print(result_a - result_b)


if __name__ == '__main__':
    main()


# Example run
# Input:
)B`
-2058894
# Output:
-2058894
n = int(input())
As = sorted(map(int, input().split()), reverse=True)
print(sum(As[::2])-sum(As[1::2]))

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

a.sort(reverse = True)

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


# Example run
# Input:
115625
-15913
# Output:
-15913
n = int(input())
A = list(map(int,input().split()))
Alice_card = []
Bob_card = []
for i in range(n):
        if i%2 == 0:
                Alice_card.append(A[i])
        else:
                Bob_card.append(A[i])
Alice_total = sum(Alice_card)
Bob_total = sum(Bob_card)
print(abs(Alice_total - Bob_total))

# Example run
# Input:
-728818981
-2811762
# Output:
0
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
d = 0
for a in A[::2]:
  d += a
for a in A[1::2]:
  d -= a
print(d)


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

# Example run
# Input:
152233
2920762
# Output:
2920762
N = int(input())
A = sorted([int(i) for i in input().split()])[::-1]

k = -1
sum1 = 0
sum2 = 0
for i in A:
  if k==-1:
    sum1+=i
  else:
    sum2+=i
  k*=-1
print(sum1 -sum2)



# Example run
# Input:
-1069713
-7
# Output:
-7
N = int(input())
A =[i for i in input().split()]
A = sorted(A,reverse=True)
Alice = 0
Bob = 0
while len(A) != 0:
    Alice += int(A.pop(0))
    if len(A) == 0:
        break
    else:
        Bob += int(A.pop(0))
print(Alice - Bob)

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

# Example run
# Input:
-11989124
-407
# Output:
-407
n = int(input())
card_list = list(map(int, input().split()))

alice_point = 0
bob_point = 0

def pick_card(card_list):
    # print(card_list)
    max = 0
    max_index = 0
    for i in range(card_list.__len__()):
        # print('-------', i)
        if card_list[i] > max:
            # print('@', i, ':', max, '<', card_list[i])
            max = card_list[i]
            max_index = i
    
    del card_list[max_index]

    # print('----', card_list)

    return max, card_list

def sort_card(card_list: list):
    return sorted(card_list, reverse=True)

turn = 0
sorted_list = sort_card(card_list)
while turn < n:
    # print('--', turn)
    if turn % 2 == 0:
        # alice_get, remain_list = pick_card(card_list)
        # alice_point += alice_get
        alice_point += sorted_list.pop(0)
    else:
        # bob_get, remain_list = pick_card(card_list)
        # bob_point += bob_get
        bob_point += sorted_list.pop(0)

    # card_list = remain_list
    # print(alice_point, bob_point, sorted_list)

    turn += 1

print(alice_point - bob_point)

# Example run
# Input:
-28
-512
# Output:
0
n = input()
lst = sorted([int(x) for x in input().split()], reverse=True)
alice = 0
bob = 0
for i in range(len(lst)):
    if i%2:
        bob += lst[i]
    else:
        alice += lst[i]
print(alice-bob)

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

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

A.sort(reverse=True)
l = 0
r = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        l += a
    else:
        r += a
print(l-r)

# Example run
# Input:
-3
-23909
# Output:
-23909
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:
-7698469
-5952
# Output:
-5952
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

X=0
k=1
for a in A:
    X+=k*a
    k*=-1
print(X)


# Example run
# Input:
-1
815
# Output:
815
N = int(input())
cards = list(map(int, input().split()))
A, B = 0, 0
while cards != []:
    A += cards.pop(max(zip(cards, range(len(cards))))[1])
    if cards == []:
        break
    B += cards.pop(max(zip(cards, range(len(cards))))[1])
print(A - B)

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

counter = 0

A.sort(reverse=True)
for n in range(N):
    counter += A[n]*(-1)**n

print(counter)


# Example run
# Input:
-7487220
-1005
# Output:
0
N = int(input())
l = list(map(int,input().split()))

l.sort(reverse=True)
Alice = sum(l[0::2])
Bob = sum(l[1::2])

print(Alice-Bob)

# Example run
# Input:
-554740
65444
# Output:
65444
def main():
    N = map(int, input().split())
    a = [int(s) for s in input().split()]
    a.sort(reverse = True)
    ans = 0
    ans = sum(a[0::2]) - sum(a[1::2])
    print(ans)


if __name__ == '__main__':
    main()


# Example run
# Input:
2eKDu7
-82582
# Output:
-82582
import math
N = int(input())
alst = list(map(int, input().split()))
list.sort(alst, reverse = True)
answer = 0
for i in range(N):
    answer += alst[i] * math.pow(-1, i)
print(int(answer))


# Example run
# Input:
-1002
45236
# Output:
0
i = 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:
-114
-473
# Output:
-473
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(sum(a[n-1::-2])-sum(a[n-2::-2]) if n!=1 else a[0])


# Example run
# Input:
1813543
-252699780
# Output:
0
N = int(input())
A = list(map(int, input().split()))

NewA = sorted(A, reverse=True)

Alice = 0
Bob = 0 

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


print((Alice)-(Bob))

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

# Example run
# Input:
1
-958636
# Output:
-958636
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 =alice+a[i]
	if i%2==1:
		bob = bob+a[i]
ans = alice-bob
print(ans)

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

while a:
    al_val += max(a)
    a.remove(max(a))
    if not a: break
    bo_val += max(a)
    a.remove(max(a))

print(al_val - bo_val)


# Example run
# Input:
-194715587
-2938
# Output:
-2938
total_cards = int(input())
cards_list = list(map(int,input().split()))
alice=0
bob=0
cards_list.sort(reverse=True)
for i in range(len(cards_list)):
    if i%2==0:
        alice +=cards_list[i]
    else:
        bob +=cards_list[i]
ans = alice -bob
print(ans)

# Example run
# Input:
157
1522
# Output:
1522
N = int(input())
A = list(map(int, input().split()))
alice = 0
bob = 0
A.sort(reverse=True)
print(A)
for i in range(N):
    if i%2 == 0:
        alice += A.pop(0)
    else:
        bob += A.pop(0)
print(alice-bob)

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

# Example run
# Input:
-5256
-11
# Output:
0