Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
As = sorted(list(map(int, input().split())))
if n % 2 == 1:
    As = [0] + As
print(sum(As[1::2]) - sum(As[::2]))


# Example run
# Input:
-407
0
# Output:
0
# -*- coding: utf-8 -*-
N = int(input())
number_list = list(map(int, input().split()))
sort_number_list = sorted(number_list, reverse=True)
 
Alice = 0
Bob = 0
for i, x in enumerate(sort_number_list):
  i += 1
  if i % 2 != 0:
    Alice += x
  else:
    Bob += x

print("{}".format(Alice - Bob))

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


# Example run
# Input:
13499019
3132478
# Output:
3132478
N = int(input())
card = list(map(int,input().split()))
sorted_card = sorted(card,reverse=True)
Alice = 0
Bob = 0

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

print(Alice - Bob)

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

# Example run
# Input:
-2
669
# 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:
28016
-48
# Output:
-48
N = int(input())
a = list(map(int, input().split()))

a.sort()

alice = 0
bob = 0

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

print(alice - bob)


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

a.sort()
a.reverse()

t = 'A'
alice = []
bob = []
while(True):
    if t == 'A':
        t = 'B'
        x = a.pop(0)
        alice.append(x)
    elif t == 'B':
        t = 'A'
        x = a.pop(0)
        bob.append(x)

    if len(a) == 0:
        break

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


# Example run
# Input:
70800
72046879
# Output:
72046879
N = int(input())
aList = [int(x) for x in input().split()]
aList.sort(reverse=True)
print(sum(aList[::2]) - sum(aList[1::2]))

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

A, B = 0, 0

for i in range(N//2):
    A += a.pop()
    B += a.pop()

if N % 2 == 1:
    A += a.pop()

print(A-B)

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

Alice = 0
Bob = 0

while len(a) > 0:
    m_a = max(a)
    Alice += m_a
    a.remove(m_a)

    if len(a) == 0:
        break
    else:
        m_a = max(a)
        Bob += m_a
        a.remove(m_a)

print(Alice-Bob)

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

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

# Example run
# Input:
-1
-3439167
# Output:
0
N = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)

target_num = sum(a_list[::2]) - sum(a_list[1::2])
print(target_num)

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

alice = []
bob = []
i = 2
while True:
    mx = max(a)
    if i % 2 == 0:
        alice.append(mx)
    else:
        bob.append(mx)
    a.remove(mx)
    i+=1
    if len(a) == 0:
        break

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

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

# Example run
# Input:
15927431
141
# Output:
141
#coding:utf-8
n = int(input())
a = list(map(int, input().split()))

card = sorted(a, reverse=True)

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

# Example run
# Input:
-838
150
# Output:
150
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:
13499019
3132478
# Output:
3132478
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse = True)
A.insert(N,0)
ans = 0
for i in range(0,N,2):
	ans += (A[i] - A[i+1])
print(ans)


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

# Example run
# Input:
`^&b?\S$
-2530
# Output:
-2530
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:
0
11
# Output:
0
n = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
d = 0

for i, card in enumerate(cards):
  if i%2 == 0:
    d += card
  else:
    d -= card
print(d)

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

a.sort(reverse=True)

alice = 0
bob = 0

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

print(alice - bob)


# Example run
# Input:
-445
31959
# Output:
31959
# coding: utf-8
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:
237
-42600
# Output:
-42600
n = int(input())
a = sorted(map(int, input().split()), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

# Example run
# Input:
20616
-11392175
# Output:
-11392175
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:
-39355
1
# Output:
0
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
ans = 0
for i in range(n):
    if i%2 == 0:
        #Alice
        ans += a[i]
    else:#Bob
        ans -= a[i]
print(ans)

# Example run
# Input:
-80
19
# Output:
0
n = int(input())
array = list(map(int, input().strip().split()))

alice_total = 0
bob_total = 0

for i in range(len(array)):
    if i % 2 == 0:
        max_value = max(array)
        max_index = array.index(max_value)
        alice_total += array.pop(max_index)
    else:
        max_value = max(array)
        max_index = array.index(max_value)
        bob_total += array.pop(max_index)

print(alice_total - bob_total)


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

a.sort()

alice = 0
bob = 0
flag = 0
for i in range(N):
    if flag == 0:
        alice += a[N-(i+1)]
        flag = 1
    else:
        bob += a[N-(i+1)]
        flag = 0

print(alice - bob)

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


# Example run
# Input:
S43brt#
104248
# Output:
104248
n = int(input())
a_list = list(map(int, input().split()))
alice = 0
bob = 0


for i in range(len(a_list)):
    if i % 2:
        bob += sorted(a_list, reverse=True)[i]
    else:
        alice += sorted(a_list, reverse=True)[i]

print(str(alice - bob)) 

# Example run
# Input:
1685
-848
# Output:
-848
n = int(input())
ns = sorted(list(map(int, input().split())))[::-1]
alice = sum(ns[0:n:2])
bob = sum(ns[1:n:2])
print(alice-bob)


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

list.sort()

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

print("{}".format(Alice - Bob))

# Example run
# Input:
1
-124978655
# Output:
124978655
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
alice_deck = [a[i] for i in range(len(a)) if i%2==0]
bob_deck = [a[i] for i in range(len(a)) if i%2==1]
print(sum(alice_deck) - sum(bob_deck))

# Example run
# Input:
29651
0
# Output:
0
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
al = 0
bo = 0
for i in range(0, n):
    if i%2 == 0:
        al += int(a[i])
    else:
        bo += int(a[i])

print(al - bo)

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

sorted_list = sorted(a,reverse = True)

Alice,Bob = 0,0 #アリスとボブの点数の宣言

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

ans = Alice - Bob
print(ans)


# Example run
# Input:
-15860207
-54634663
# Output:
0
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

a = sorted(a, reverse=True)

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

print(x-y)


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

# Example run
# Input:
-31
-58867430
# Output:
0
# 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
1165
# Output:
0
n = int(input())
List = list(map(int, input().split()))
List = sorted(List)[::-1]
alice = sum(List[0::2])
bob = sum(List[1::2])
print(alice - bob)

# Example run
# Input:
-31
224
# Output:
224
N = int(input())
a = map(int, input().split(' '))

a=sorted(a, reverse=True)

alice =0
bob   =0

count=0

for i in a:
    if count%2 == 0 :
       alice += i  
    else:
       bob += i
    count+=1

print(alice - bob)

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

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

# Example run
# Input:
0
-6956
# Output:
0
N = int(input())
List = [int(x) for x in input().split()]

List.sort(reverse=True)

ans = sum(List[::2])-sum(List[1::2])

print(ans)

# Example run
# Input:
-70037
-1002
# Output:
-1002
N = int(input())
list_a  = list(map(int, input().split()))

list_a.sort()

sum_of_diff = 0

while list_a:
	tmp_a = list_a.pop()
	try:
		tmp_b = list_a.pop()
	except:
		tmp_b = 0
	sum_of_diff += tmp_a - tmp_b

print(sum_of_diff)



# Example run
# Input:
30543
-187845
# Output:
-187845
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.pop(0)
    else:
        bob += a.pop(0)
print(alice-bob)

# Example run
# Input:
-2
-497
# Output:
0
n = int(input())
c = list(map(int, input().split()))
c.sort()

a, b = 0, 0
f = 'a'
while(len(c) != 0):
    if f == 'a':
        a += c.pop()
        f = 'b'
    elif f == 'b':
        b += c.pop()
        f = 'a'
print(a - b)

# Example run
# Input:
-13
7381
# Output:
7381
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    alice = sum(A[0::2])
    bob = sum(A[1::2])
    return alice-bob

print(main())

# Example run
# Input:
-4953150
3320259
# Output:
3320259
n = int(input())
a_list = list(map(int, input().split()))
alice = 0
bob = 0
a_list.sort(reverse=True)
i = 0
for a_i in a_list:
  if i % 2 == 0:
    alice += a_i
  else:
    bob += a_i
  i += 1
print(alice - bob)

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

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

# Example run
# Input:
ma;M
-254
# Output:
-254
def abc088b_card_game_for_two():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    alice = bob = 0
    for i in range(len(a)):
        if i % 2 == 0:
            alice += a.pop()
        else:
            bob += a.pop()
    print(alice - bob)
abc088b_card_game_for_two()

# Example run
# Input:
-1018584
-247
# Output:
-247
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:
37777
19239
# Output:
19239
N = int(input())
A = sorted(map(int, input().split()), reverse=True)

alice = sum(A[0::2])
bob = sum(A[1::2])

print(alice - bob)

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

print(abs(a-b))


# Example run
# Input:
31751463
-3
# Output:
3
N=int(input())
numbers=list(map(int,input().split()))
new_numbers=sorted(numbers,reverse=True)
Alice=0

Bob=0
for i in range(N//2+N%2):
    Alice+=new_numbers[2*i]
for i in range(N//2):
    Bob+=new_numbers[2*i+1]
print(Alice-Bob) 


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

# Example run
# Input:
-679619851
112974694
# Output:
112974694
num = input()
nums = [int(x) for x  in input().split()]
nums = sorted(nums, reverse=True)
alice = sum(nums[::2])
bob = sum(nums[1::2])
print(alice-bob)

# Example run
# Input:
YQocc[TJS
-29082932
# Output:
-29082932
n = int(input())
a = list(sorted(map(int, input().split())))

alice = []
bob = []

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

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

# Example run
# Input:
28952
-124042
# Output:
-124042
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
a = [arr[n - i - 1] for i in range(n) if (i + 1) % 2 == 1]
b = [arr[n - i - 1] for i in range(n) if (i + 1) % 2 == 0]
print(sum(a) - sum(b))

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


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

# Example run
# Input:
450137
-9486
# Output:
-9486
#ABC 088 B - Card Game for Two
N = int(input())
card_list = [int(i) for i in input().split()]
alice = 0
bob = 0
for i in range(N):
    if i%2==0:
        m = max(card_list)
        alice += m
        card_list.remove(m)
    if i%2==1:
        m = max(card_list)
        bob += m
        card_list.remove(m)
print(alice-bob)

# Example run
# Input:
-5930
-31
# 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:
-27928965
7381
# Output:
7381
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:
-848
-29392
# Output:
0
a=int(input())
b=list(map(int,input().split()))
ans=0
for i in range(a):
    if  i%2==1:
        ans-=max(b)
        b.remove(max(b))
    else:
        ans+=max(b)
        b.remove(max(b))
print(ans)

# Example run
# Input:
0
33729406
# Output:
0
N = int(input())
a = list(map(int, input().rstrip().split()))
a_sort = sorted(a, reverse = True)
num = 0
for i in range(N):
    if i % 2 == 0:
        num += a_sort[i]
    else:
        num -= a_sort[i]
print(num)


# Example run
# Input:
0
8131
# Output:
0
n = input()
a = sorted([int(i) for i in input().split()], reverse=True) #sortメソッドは破壊的、sorted関数は非破壊的
print(sum(a[::2]) - sum(a[1::2]))


# Example run
# Input:
!d1,AYZU
220661337
# Output:
220661337
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ca = 0
cb = 0
for i in range(n):
    if i%2 == 0:
        ca += a[i]
    else:
        cb += a[i]

print(ca-cb)

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

# Example run
# Input:
5946
8
# Output:
8
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n):
    p = a.pop()
    if i % 2 == 0:
        ans += p
    else:
        ans -= p
print(ans)


# Example run
# Input:
-30
0
# Output:
0
import copy

def main():
    N = int(input())
    A = list(map(int, input().split()))

    p1_total = 0
    p2_total = 0
    for i in range(N):
        if i % 2 == 0:
            tmp = max(A)
            p1_total += tmp
            del A[A.index(tmp)]
        else:
            tmp = max(A)
            p2_total += tmp
            del A[A.index(tmp)]

    print(p1_total - p2_total)

if __name__ == '__main__':
    main()

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

# Example run
# Input:
10
5330
# Output:
5330
num = int(input())
org_list = list(map(int, input().split()))

new_list = sorted(org_list, reverse=True)

alice_sum = sum(new_list[::2])
bob_sub = sum(new_list[1::2])

# print(new_list)
# print(str(alice_sum) + ":" +str(bob_sub))
print(str(alice_sum-bob_sub))

# Example run
# Input:
1
-54266464
# Output:
-54266464
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
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:
-3886793
-1959
# Output:
0
input()
values = sorted(tuple(map(int, input().split(' '))), reverse=True)

pa = sum(values[::2])
pb = sum(values[1::2])

print(pa - pb)


# Example run
# Input:
8vLAk
-158606
# Output:
-158606
n=int(input())
a=list(map(int, input().split()))
t=0
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
-84521052
# Output:
-84521052
# 088 B
n = int(input())
aa = list(map(int, input().split()))
alice = 0
bob=0
aa = sorted(aa, reverse = True)
for i,a in enumerate(aa):
    if i % 2 == 0:
        alice += a
    else:
        bob += a
# print(alice, bob)
print(abs(alice-bob))

# Example run
# Input:
1186387
-1643990
# Output:
1643990
#-*-cording:utf-8-*-
N = int(input())
A = input().split()
A.sort()
A.reverse()
a=list(map(int,A))
Alice = a[1::2]
Bob = a[0::2]
allA=sum(Alice)
allB=sum(Bob)
Ans=allA-allB
print(-Ans)


# Example run
# Input:
-124978655
-23909
# Output:
-23909
input()

alice = 0
bob = 0
is_alice = True
for n in sorted(map(int, input().split()), reverse=True):
    if is_alice:
        alice += n
    else:
        bob += n
    is_alice = not is_alice

print(alice - bob)


# Example run
# Input:
]MO|p9.
-1018584
# Output:
-1018584
n = input()
a = list(map(int, input().split()))
alice = 0
bob = 0

for i, num in enumerate(sorted(a)[::-1]):
    if i%2 == 0:
        alice += num
    else:
        bob += num

print(alice - bob)

# Example run
# Input:
U]r$Yl
-686
# Output:
-686
N = int(input())
a = sorted(list(map(int,input().split())))
print(sum(a[::2])-sum(a[1::2]))

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

A=[]
B=[]

for i in range(len(a)):
    if i%2==1:
        A.append(a[i])
    else:
        B.append(a[i])

print(abs(sum(A)-sum(B)))

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

# Example run
# Input:
-2
-99110661
# Output:
-99110661
N = int(input())
A = list(map(int, input().split()))
A.sort()
Alice = 0
Bob = 0
while 1:
    try:
        Alice += A.pop(-1)
    except IndexError:
        break
    try:
        Bob += A.pop(-1)
    except IndexError:
        break
print(Alice-Bob)

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


# Example run
# Input:
-18229
-16112
# Output:
0
n = int(input())
card = list(map(int,input().split()))

card.sort(reverse=True)

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

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

# Example run
# Input:
-114
-473
# Output:
-473
n = int(input())
a = [int(i) for i in input().split()]
score_Alice = 0
score_Bob   = 0
turnA = True
a.sort(reverse = True)
for i in range(n):
  if turnA == True:
    score_Alice += a[i]
  else:
    score_Bob   += a[i]
  turnA = not turnA
print(score_Alice - score_Bob)
  

# Example run
# Input:
1
4887419
# Output:
4887419
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("Three")
    else:print("Four")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())




n = ip()                              #入力整数1つ
#a,b= (int(i) for i in input().split())      #入力整数横2つ
#k,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
a.sort(reverse=True)
s = 0
for i in range(1,len(a),2):
    a[i]*=-1
print(sum(a))


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

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

# Example run
# Input:
-4868286
-104837
# Output:
-104837
input()
cards = sorted(list(map(int, input().split())), reverse=True)

length = len(cards)
mid = 0
if length % 2 == 0:
    mid = int(length / 2)
else:
    mid = int(length / 2) + 1

print(sum(cards[0:mid]) - sum(cards[mid:]))


# Example run
# Input:
tN_j
6
# Output:
6
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    sw = 0
    alice = 0
    bob = 0
    for i in a:
        if sw == 0:
            alice += i
            sw = 1
        else:
            bob += i
            sw = 0
    print(alice-bob)

if __name__ == '__main__':
    main()



# Example run
# Input:
-11989124
-407
# Output:
-407
N = int(input())
A = sorted(list( map( int, input().split() ) ), reverse=True)
Alice = 0
Bob = 0
for i in range(0,N,2):
    Alice += A[i]
    if i+1 <= N-1:
        Bob += A[i+1]
print(Alice-Bob)

# Example run
# Input:
-180
-525602
# Output:
0
n = int(input())
a = sorted(map(int, input().split()),reverse=True)
alice = 0
bob = 0
for i in range(0,n,2) :
    alice += a[i]
for j in range(1,n,2) :
    bob += a[j]
print(alice-bob)


# Example run
# Input:
-65
0
# Output:
0
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
v=sum(a)
alice_count=0
for i in range(n):
    if i%2==0:
        alice_count+=a[i]
bob_count=v-alice_count
print(alice_count-bob_count)

# Example run
# Input:
-1
-3439167
# Output:
3439167