Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
N = int(input())
a = input().split()
a = list(map(int,a))
a.sort()
A = 0
B = 0
for i in range(1,N+1):
  if i%2 == 0:
    B = B + a[N-i]
  else:
    A = A + a[N-i]
print(A-B)

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

# Example run
# Input:
m#d=C>#
-23
# Output:
-23
n=int(input())
a=list(map(int, input().split()))
a.sort()
ans=0
k=1
for i in a:
  ans+=k*i
  k*=-1
if ans<0:
  ans*=-1
print(ans)

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

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

a.sort(reverse=True)

alice = 0
bob = 0

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

# Example run
# Input:
-104837
-69520
# Output:
-69520
_ = input()
print(sum(k if i%2 == 0 else -k for i,k in enumerate(sorted(map(int,input().split()),reverse=True))))

# Example run
# Input:
ayU[S!:U
29
# Output:
29
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
ans1 = 0
ans2 = 0
for i in range(n):
    if i % 2 == 0:
        ans1 += a[i]
    else:
        ans2 += a[i]
print(ans1-ans2)

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


# Example run
# Input:
31499
-58743
# Output:
-58743
#Card Game for Two
a=int(input())
b=list(map(int,input().split()))
b.sort()
total=0
total2=0
for i in range(a):
    if i%2==0:
        total+=b[i]
    else:
        total2+=b[i]
print(max(total,total2)-min(total,total2))

# Example run
# Input:
-11385106
-114
# Output:
0
#7th
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
# print(a)
alice = sum(a[0::2])
bob = sum(a[1::2])
print(alice-bob)

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


# Example run
# Input:
-274078593
-28418
# Output:
-28418
n=int(input())
A=list(map(int,input().split(' ')))
A.sort()
a=0
b=0
i=0
while i < n:
    if i%2==0:
        a+= A[i]
    else:
        b += A[i]
    i += 1
print(abs(a-b))

# Example run
# Input:
-887384
13499019
# Output:
0
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:
0
13
# Output:
13
N = int(input())
a = list(map(int,input().split()))

a.sort(reverse=True)
print(a)
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:
-1836
-168854
# Output:
[-168854]
0
n=int(input())
a=sorted([int(i) for i in input().split()])
ans=sum(a[::2])-sum(a[1::2])
print(ans)

# Example run
# Input:
-87
141725276
# Output:
141725276
def main():
    N = int(input())
    a = sorted(map(int, input().split()))[::-1]
    diff = sum(a[::2]) - sum(a[1::2])
    print(diff)


if __name__ == "__main__":
    main()

# Example run
# Input:
-74461
-1151131
# Output:
-1151131
n = int(input())
array = list(map(int,input().split()))
array.sort(reverse=True)
alice = 0
bob = 0

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

# Example run
# Input:
-20238871
43064
# Output:
0
n = int(input())
cards = list(map(int,input().split()))
cards = sorted(cards,reverse=True)


Alice = sum(cards[::2])
Bob = sum(cards[1::2])
print(Alice-Bob)

# Example run
# Input:
-3225
-5024207
# Output:
-5024207
n = int(input())
a_n = list(map(int, input().split()))

a_n = sorted(a_n, reverse=True)

res = 0
for i in range(len(a_n)):
    if i % 2 == 0:
        res = res + a_n[i]
    else:
        res = res - a_n[i]
print(res)


# Example run
# Input:
-918915
187
# Output:
187
#!/usr/bin/env python3
#ABC88 B

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:
-28418
-29
# Output:
0
N = int(input())
cards = [int(i) for i in input().split()]

cards = sorted(cards, reverse=True)

Alice = 0
Bob = 0

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

# Example run
# Input:
-2540
-1836
# Output:
-1836
N = int(input())
Card = list(map(int,input().split()))

Card.sort(reverse=True)

if len(Card)>=2:
    A = sum(Card[::2])
    B = sum(Card[1::2])
else:
    A = Card[0]
    B = 0

print(A-B)

# Example run
# Input:
1186387
-1643990
# Output:
-1643990
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, card_list)

    turn += 1

print(alice_point - bob_point)

# Example run
# Input:
-2
-99110661
# Output:
0
N = input()
MM = input().split()
list1 =[]
for i in MM:
  x = int(i)
  list1.append(x)
list1.sort(reverse = True)
total = 0
for i in range(len(list1)):
  if i%2 ==0:
    total += list1[i]
  else:
    total -= list1[i]
print(total)

# Example run
# Input:
RZXqH:
171431681
# Output:
171431681
n=int(input())
a = list(map(int, input().split()))
a.sort(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:
-56661351
981571
# Output:
0
n = int(input())
x = sorted([int(i) for i in input().split(" ")],reverse=True)
print(sum(x[::2]) - sum(x[1::2]))

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

# Example run
# Input:
-2777886
182
# Output:
182
N = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse = True)
score_A = 0
score_B = 0
for i in range(len(cards)):
  if i%2 == 0:
    score_A += cards[i]
  else :
    score_B += cards[i]
print(score_A - score_B)

# Example run
# Input:
-26729193
252153
# Output:
252153
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:
-3249
901872
# Output:
0
N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
a.reverse()
Alice = 0
Bob = 0
a.append(0)
a.append(0)
print(a)

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

# Example run
# Input:
-1005173
-60875
# Output:
[-60875, 0, 0]
0
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
isa = True
ali = 0
bob = 0
for t in a:
    if (isa):
        ali += t
    else:
        bob += t
    isa = not isa

print(ali - bob)


# Example run
# Input:
-2773
3897539
# Output:
3897539
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
a.reverse()
bob = 0
i = 0
while 2*i + 1 < len(a):
    a[2*i + 1] = -a[2*i + 1]
    i += 1

print(sum(a))

# Example run
# Input:
10921
86342186
# Output:
86342186
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:
-31766
-1
# Output:
0
N = input()
A = list(map(int, input().split()))

A.sort(reverse=True)

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

# Example run
# Input:
BaYeDOY!
93
# Output:
93
def main():

    n = int(input())
    cards = list(map(int, input().split()))
    cards.sort(reverse=True)
    alice, bob = 0, 0
    if n % 2 == 0:
        for i in range(int(n / 2)):
            alice += cards[2 * i]
            bob += cards[2 * i + 1]
    else:
        for j in range(int(n / 2)):
            alice += cards[2 * j]
            bob += cards[2 * j + 1]
        alice += cards[n - 1]
    ans = alice - bob
    print(ans)

if __name__ == '__main__':
    main()

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

b = sorted(a, reverse = True)

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

print(total)


# Example run
# Input:
-155785153
-104837
# Output:
-104837
N = int(input())
a = [int(i) for i in input().split()]
Alice = 0
Bob = 0
count = 0
while not all((x == 0 for x in a)):
  if count%2 == 0:
    max_value = max(a)
    Alice += max_value
    max_index = a.index(max_value)
    a[max_index] = 0
    count += 1
  elif count%2 == 1:
    max_value = max(a)
    Bob += max_value
    max_index = a.index(max_value)
    a[max_index] = 0
    count += 1
print(abs(Alice - Bob))

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

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

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

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

# Example run
# Input:
-831
110
# Output:
110
n=int(input())
cards=sorted(map(int, input().split()), reverse=True)
a=1
b=0
Alice=0
Bob=0
for i in cards:
    if a == 1 and b == 0:
       Alice+=i
       a=0
       b=1
    elif a == 0 and b == 1:
       Bob+=i
       a=1
       b=0
print(Alice-Bob)

# Example run
# Input:
8
0
# Output:
0
N=int(input())
a=list(map(int, input().split()))
b=sorted(a,reverse=True)
pnt=0
for i in range(N):
  pnt+=b[i]*(1-(i%2)*2)
print(pnt)

# Example run
# Input:
-316
-160045822
# 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:
-812896393
-97075663
# Output:
-97075663
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:
0
-84521052
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
if n % 2 == 1:
  a.append(0)
for i in range(len(a)//2):
  ans += a[i*2] - a[i*2+1]
print(ans)

# Example run
# Input:
-16860
0
# Output:
0
n = int(input())
data = input().split()

int_data = [int(int_data) for int_data in data]
int_data.sort(reverse=True)

Alice = 0
Bob = 0

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

# Example run
# Input:
-31
-58867430
# Output:
0
n = int(input())
nums = sorted(list(map(int, input().split())), key=lambda x: -x)
alice = 0
bob = 0
for i, num in enumerate(nums):
    if i % 2 == 0:
        alice += num
    else:
        bob += num
print(alice - bob)

# Example run
# Input:
13499019
3132478
# Output:
3132478
n = int(input())
arr = list(map(int, input().split()))
alice = 0
bob = 0
chance = "A"
for _ in range(len(arr)):
	i = max(arr)
	if chance == "A":
		alice += i
		chance = "B"
	else:
		bob += i
		chance = "A"
	indx = arr.index(i)
	del arr[indx]
print(alice - bob)

# Example run
# Input:
-497
-15860207
# Output:
-15860207
N = int(input()) #入力値
A = sorted(map(int, input().split()), reverse = True)
Bob=0
Alice=0
for i in range(0,N):
      if i % 2 == 0: # Bobが偶数なら実行
         Alice=Alice+int(A[i])
      else:
         Bob=Bob+int(A[i])
print(Alice-Bob)


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

a.sort()
a.reverse()
p = [0,0]
for i in range(N):
    p[i%2] += a[i]

print(p[0]-p[1])



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

# Example run
# Input:
e3zvshd]
45580
# Output:
45580
n = int(input())
a = list(map(int , input().strip().split()))
total = 0

if len(a) % 2 != 0:
  a.append(0)
  
a.sort()

for i in range(int(len(a) / 2)):
  total += a[2 * i] - a[2 * i + 1]

print(total * (-1))

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

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



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

print(a-b)

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


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

# Example run
# Input:
665422
14319043
# Output:
14319043
n=int(input())
l=list(map(int,input().split()))
l.sort()
sumA=0
sumB=0
for i in range(1,n+1):
  if i%2==1:
    sumA+=l[(-1)*i]
  else:
    sumB+=l[(-1)*i]
print(sumA-sumB)

# Example run
# Input:
-4635017
-21
# Output:
0
N = int(input())
a = [int(_) for _ 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:
-6212597
36241
# Output:
0
N=int(input())
a=list(map(int,input().split()))

a=sorted(a,reverse=True)
b=0
c=0

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


print(b-c)

# Example run
# Input:
-2777886
182
# Output:
0
N = int(input())

a_list = list(map(int, input().split()))
a_list.sort(reverse = True)

count = 0
allice_total = 0
bob_total = 0
for a in a_list:
    if count % 2 == 0:
        allice_total += a
    else:
        bob_total += a
    count += 1

print(allice_total - bob_total)





# Example run
# Input:
-406
-7520
# Output:
-7520
def test():
    n = int(input())
    a = list(map(int,input().split()))
    flag = 0
    alice = 0; bob = 0
    for i in range(n):
        if flag == 0:
            alice += max(a)
            a.remove(max(a))
            flag = 1
        elif flag == 1:
            bob += max(a)
            a.remove(max(a))
            flag = 0
    print(alice-bob)


if __name__ == "__main__":
    test()


# Example run
# Input:
0
-6956
# Output:
0
n = int(input())
a = list(map(int, input().split()))
alice_sum = 0
bob_sum = 0
turn = 1
a.sort(reverse=True)
for i in range(n):
    if turn == 1:
        alice_sum += a.pop(0)
    else:
        bob_sum += a.pop(0)
    turn *= (-1)
print(alice_sum-bob_sum)

# Example run
# Input:
-464240
19804
# Output:
0
N = int(input())
A = [-int(x) for x in input().split()]
A.sort(reverse=True)
a, b, turn = 0, 0, 1
while len(A) != 0:
    if turn & 1:
        a += A.pop(0)
    else:
        b += A.pop(0)
    turn += 1
print(a-b)

# Example run
# Input:
7
868
# Output:
-868
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
b.reverse()
c = 0
d = 0
for i in range(0,len(a),2):
    c += b[i]
for j in range(1,len(a),2):
    d += b[j]
    
print(c-d)

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

# Example run
# Input:
10823
-9225256
# Output:
-9225256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = 0
Bob = 0

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

print(Alice - Bob)

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

a.sort(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:
-1643990
363865392
# Output:
0
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
alice = bob = 0
for i in range(N):
    if i%2 == 0:
        alice += A[i]
    else:
        bob += A[i]
    
print(alice - bob)

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

li.sort()
li = li[::-1]

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

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

# Example run
# Input:
3485
17754
# Output:
17754
N = int(input())
*CARDS, = sorted(map(int, input().split()))[::-1]
#print(CARDS)
print(sum(CARDS[::2]) - sum(CARDS[1::2]))


# Example run
# Input:
20480
1510792572
# Output:
1510792572
N=input()
a= sorted([int(j) for j in input().split()],reverse=True)
print(sum(a[::2])-sum(a[1::2]))

# Example run
# Input:
bseXf?
38254
# Output:
38254
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:
-1
-422501
# Output:
-422501
N = int(input())
a = list(map(int,input().split()))
if len(a)%2 != 0:
    a.append(0)
    N += 1
alice = []
bob = []
for i in range(int(N/2)):
    alice.append(a.pop(a.index(max(a))))
    bob.append(a.pop(a.index(max(a))))
print(sum(alice)-sum(bob))

# Example run
# Input:
-6126
-5
# Output:
0
N = int(input())
lines = input().split(' ')
lines = [int(x) for x in lines]
a_list = sorted(lines)
A = 0
B = 0


while len(a_list) > 0:
	A += a_list.pop()
	if len(a_list) > 0:
		B += a_list.pop()

print(A - B)

# Example run
# Input:
870
-985376852
# Output:
-985376852
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
count = 1
index = len(a)
for i in range(len(a)):
    ans += a[index-1]*count
    index -= 1
    count *= -1

print(ans)


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

for i in range(N):
  if i%2==0:
    result += x[i]
  elif i%2!=0:
    result -= x[i]
  
print(result)

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

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


# Example run
# Input:
-123410341
9062461
# Output:
9062461
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:
-7487220
-1005
# Output:
-1005
N = int(input())
a = map(int,input().split())
a = list(a)
a.sort()
ans = sum(a[0::2])-sum(a[1::2])
print(abs(ans))

# Example run
# Input:
-1998
-147
# Output:
147
# -*- coding: utf-8 -*-

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

cards = sorted(a)
alice = cards[-1::-2]
bob = cards[-2::-2]

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

print(ans)


# Example run
# Input:
0
5354599
# Output:
[5354599]
[]
5354599
n=int(input())
a=sorted([int(i) for i in input().split()])
A=sum([a[i] for i in range(n) if i%2==0])
B=sum([a[i] for i in range(n) if i%2!=0])
print(abs(A-B))

# Example run
# Input:
-62350830
260615611
# Output:
0
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:
-101281970
-210
# Output:
-210
card_n = int(input())
card_collection = list(map(int, input().split()))

scores = {"alice" : 0, "bob" :0}
card_collection.sort()
for i, card in enumerate(card_collection):
    if i % 2 == 0:
        scores['bob'] += card
    else:
        scores['alice'] += card
print(scores['alice'] - scores['bob'])

    

# Example run
# Input:
465
-2090237817
# Output:
2090237817
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
a.reverse()

s=0

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

print(s)

# Example run
# Input:
-318594
-13
# Output:
0
N = int(input())
card_list = input().rstrip().split()
card_list = [int(s) for s in card_list]
sort_card_list = sorted(card_list, reverse = True)
alice_point = 0
bob_point = 0

for i, x in enumerate(sort_card_list):
    if i%2 == 0:
        alice_point = alice_point + x
    else:
        bob_point = bob_point + x

print(alice_point-bob_point)

# Example run
# Input:
-6163826
139893
# Output:
139893
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=1)

ans=[0, 0]
p = 0
for i in range(n) :
    ans[p] += A[i]
    p = (p+1) % 2

print(ans[0] - ans[1])


# Example run
# Input:
-80
-7517
# Output:
0
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
alice=a[::2]
bob=list(filter(lambda x:x not in alice,a))
print(sum(alice)-sum(bob))

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

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

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

Alice = 0
Bob = 0
count=0
B = []
for i in A:
    B.append(i)

for i in range(len(B)):
    if(count==0):
        Alice+=max(B)
        count=1
        index = B.index(max(B))
        B[index] = 0
    else:
        Bob+=max(B)
        count=0
        index = B.index(max(B))
        B[index] = 0

print(Alice - Bob)

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

# Example run
# Input:
9062461
72046879
# Output:
72046879
N=int(input())
a = [int(i) for i in input().split()] 
sorted_a=sorted(a)
sum_A=0
sum_B=0
while sorted_a != []:
    sum_A+= sorted_a[-1]
    if len(sorted_a)!=1:
        sum_B+= sorted_a[-2]
    del sorted_a[-1]
    if sorted_a!=[]:
        del sorted_a[-1]

print(sum_A-sum_B)


# Example run
# Input:
348
-4635017
# Output:
-4635017
N=int(input())
card=list(map(int, input().split()))

card.sort()
card.reverse()

A=card[0::2]
B=card[1::2]

ans=sum(A)-sum(B)

print(ans)


# Example run
# Input:
-898293901
-696
# Output:
-696
n = input()
s = list(map(int,input().split()))
Alice = []
Bob = []
for i in range(len(s)):
    if i % 2 == 0:
        Alice.append(max(s))
        s.remove(max(s))
    else:
        Bob.append(max(s))
        s.remove(max(s))
print(sum(Alice) - sum(Bob))

# Example run
# Input:
'S[L8
51
# Output:
51
N = int(input())
a = sorted([int(x) for x in input().split()], reverse=True)

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

# Example run
# Input:
-398
986892
# Output:
986892
Nlist = list(map(int,input().split()))
ai = list(map(int,input().split()))
N = Nlist[0]
ai.sort(reverse = True)
print(sum(ai[0::2])-sum(ai[1::2]))

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

# Example run
# Input:
-24
-35784
# Output:
-35784
i = input()
l = list(map(int, input().split()))

dl = list(sorted(l))
dl = list(reversed(dl))

ans = 0

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

print(ans)


# Example run
# Input:
0}}x#m
-9
# Output:
-9
n=int(input())
l=sorted(map(int,input().split()))[::-1]
print(sum(l[::2])-sum(l[1::2]))


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