Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    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:
757115353
-7698469
# Output:
-7698469
N = int(input())
an = map(int,input().split())

an_dash = sorted(an)
Bob = 0
Alice = 0


for i in an_dash:
    Bob = sum(an_dash[0::2])
for i in an_dash:
    Alice = sum(an_dash[1::2])

print(Alice - Bob)

# Example run
# Input:
-296641124
-21
# Output:
21
a = int(input())
ar = list(map(int,input().split(" ")))
A = 0
B = 0
while True:
  A += max(ar)
  ar.remove(max(ar))
  if len(ar) == 0:
      break
  B += max(ar)
  ar.remove(max(ar))
  if len(ar) == 0:
      break
print(A - B)

# Example run
# Input:
15761764
-37
# Output:
-37
N = int(input())
a = [int(i) for i in input().split()]

a = sorted(a, reverse=True)
scr_a = 0
scr_b = 0

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

print(scr_a - scr_b)

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

# Example run
# Input:
3185105
629110165
# Output:
629110165
N = int(input())
number = list(map(int, input().split()))

Alice = 0
Bob = 0

number.sort(reverse=True)

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

print(Alice - Bob)

# Example run
# Input:
-4422
-15015728
# Output:
0
n = input()
a = [int(i) for i in input().split()]
a = sorted(a)
alice = 0
bob = 0
for i in reversed(range(len(a))):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]
print(alice-bob)

# Example run
# Input:
xed)
431
# Output:
431
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest088-B
#  TODO https://atcoder.jp/contests/abc088/tasks/abc088_b
def calcAlice(cardList):
	cardMany = len(cardList)
	alicePoint = 0
	checkRange = range(0,cardMany,+2)
	for i in checkRange:
		alicePoint = alicePoint + cardList[i]
	return alicePoint

def calcBob(cardList):
	cardMany = len(cardList)
	bobPoint = 0
	checkRange = range(1,cardMany,+2)
	for i in checkRange:
		bobPoint = bobPoint + cardList[i]
	return bobPoint

def  diffTwoScore(allCards,cardsNumberGivenList):
	cardNumberSortedList=sorted(cardsNumberGivenList,reverse=True)
	getScoreForAlice = calcAlice(cardNumberSortedList)
	getScoreForBob = calcBob(cardNumberSortedList)
	diffPoint = getScoreForAlice - getScoreForBob
	answer = diffPoint
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	cardsNumberRawList = list(map(int,input().strip().split(' ')))
	solution=diffTwoScore(N,cardsNumberRawList)
	print("{}".format(solution))

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

A.sort(reverse=True)
Alice = sum(A[::2])
Bob = sum(A[1::2])
print(Alice-Bob)


# Example run
# Input:
1611931113
-19
# Output:
-19
# -*- coding: utf-8 -*-
input()

numbers = sorted(list(map(int, input().split())))

alice = bob = 0

while(len(numbers)):
	if len(numbers) == 1:
		alice += numbers.pop()
	else:
		alice += numbers.pop()
		bob += numbers.pop()

print(alice - bob)

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

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

# Example run
# Input:
681963
77305
# Output:
77305
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:
-1406309
-967
# Output:
0
N=int(input())
A=[int(x) for x in input().split()]

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

# Example run
# Input:
-65
0
# Output:
0
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("{}".format(Alice - Bob))

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

ans = 0
k = 0
for i in range(n):
  res = max(a)
  if k % 2 == 0:
    ans += res
  else:
    ans -= res
  a.remove(res)
  k += 1
  
print(ans)

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

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

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

print(alice - bob)

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

# Example run
# Input:
-53605951
3
# Output:
3
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=False)
ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += A[i]
    else:
        ans -= A[i]

print(abs(ans))


# Example run
# Input:
-4934
203
# Output:
0
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
alice = A[::2]
bob = A[1::2]

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

# Example run
# Input:
-900588730
10483
# Output:
10483
input()

a = sorted(map(int, input().split()), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

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

a.sort(reverse=True)

res= sum(a[0::2])-sum(a[1::2])

print(res)




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

# Example run
# Input:
-2147483648
450137
# Output:
450137
n = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
ans = 0
while len(a) != 0:
    Alice += max(a)
    a.remove(max(a))
    if a:
        Bob += max(a)
        a.remove(max(a))
ans = Alice - Bob
print(ans)


# Example run
# Input:
1
377
# Output:
377
N = int(input())
a = list(map(int, input().split(' ')))
a = sorted(a)
a = a[::-1] 
A = a[::2]
B = a[1::2]
print(sum(A)-sum(B))

# Example run
# Input:
-83
-39355
# Output:
-39355
N = int(input())
li = list(map(int, input().split()))
lili = sorted(li)
lili.reverse()
score = 0
isA = 1
for i in lili:
    if isA % 2 == 1:
        score += i
    else:
        score -= i
    isA += 1
print(score)

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

Alice = 0
Bob = 0

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

# Example run
# Input:
901872
211
# Output:
211
N = int(input())
aList = list(map(int, input().split()))
aList.sort(reverse = True)
point = [0, 0]
for i in range(N):
    point[i%2] += aList[i]
print(point[0] - point[1])

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

alice = 0
bob = 0

ai_s.sort(reverse=True)

while ai_s:
    alice += ai_s.pop(0)
    if ai_s:
        bob += ai_s.pop(0)

ans = alice - bob
print(ans)



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

a.sort(reverse=True)

Alice = 0
Bob = 0
i = 1

for j in a:
    if i % 2 == 1:
        Alice += j
    else:
        Bob += j

    i += 1

print(Alice - Bob)

# Example run
# Input:
1900838388
-233787
# Output:
-233787
n = int(input())
alice = 0
bob = 0

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

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

# Example run
# Input:
-1
-3439167
# Output:
3439167
def resolve():
    N = int(input())
    a = list(map(int, input().split()))
    Alice = sorted(a)[::2]
    Bob = sorted(a)[1::2]
    print(abs(sum(Alice)-sum(Bob)))
resolve()

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

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

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

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

A.sort()
A.reverse()

Alice = 0
Bob = 0

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

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

# Example run
# Input:
665
-3123902
# Output:
-3123902
n = int(input())
AS = list(map(int,input().split()))

points = [0,0]#alice,bob
i = 0
while AS:
  point = max(AS)
  points[i] += point
  AS.remove(point)
  i = 1-i
print(points[0]-points[1])



# Example run
# Input:
1510792572
-224960337
# Output:
-224960337
def card_game():
    n = int(input())
    a_li = [int(i) for i in input().split()]

    a_li.sort()

    return sum([i for i in a_li[::2]]) - sum([i for i in a_li[1::2]])


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


# Example run
# Input:
-5554
48148
# Output:
48148
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
x = 0
y = 0

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

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


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

list=sorted(list)[::-1]
A=0
B=0

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

# Example run
# Input:
3420734
-989028
# Output:
-989028
n = int(input())
card = list(map(int,input().split()))

card.sort()

ans = 0
for i in range(n//2):
            ans += card[2*i]-card[2*i+1]
if n%2==1:
            ans += card[-1]

print(ans)

# Example run
# Input:
0
8131
# Output:
0
def main(N,xs):
    # type: (int, List[int]) -> None
    xs.sort(reverse=True)
    alice = xs[0::2]
    bob = xs[1::2]
    print(sum(alice)-sum(bob))
    return

if __name__ == '__main__':
    N = int(input())
    xs = list(map(int,input().split()))
    main(N,xs)


# Example run
# Input:
-997466
6783
# Output:
6783
#-*- coding:utf-8 -*-

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split()))
    As.sort(reverse=True)
    alice = 0
    bob   = 0
    for i in range(len(As)):
        if i%2 == 0:
            alice += As[i]
        else:
            bob   += As[i]
    print(alice - bob)


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

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

cards.sort(reverse=True)

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

print(a - b)

# Example run
# Input:
0
87
# Output:
0
N = int(input())
a = sorted(map(int, input().split()), reverse=True)
alice = a[0::2]
bob = a[1::2]

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


# Example run
# Input:
14707
-5
# Output:
-5
def main():
    n = int(input())
    a = [int(x) for x in input().split()]

    a.sort(reverse = True)

    Alice, Bob = 0, 0

    for turn in range(0, len(a), 2):
        Alice += a[turn]

    for turn in range(1, len(a), 2):
        Bob += a[turn]

    print(Alice - Bob)

if __name__ == "__main__":
    main()


# Example run
# Input:
155287
-746
# Output:
-746
# coding: utf-8
# Your code here!
n=int(input())
a=list(map(int,input().split()))
A=0
B=0
for i in range(n):
    if i%2==0:
        A+=max(a)
        a.remove(max(a))
    else:
        B+=max(a)
        a.remove(max(a))
print(A-B)
        

# Example run
# Input:
-1
-3439167
# Output:
0
url = "https://atcoder.jp/contests/abc088/tasks/abc088_b"

def main():
    g = input()
    lis = list(map(int, input().split()))
    lis.sort(reverse=True)
    a = 0
    b = 0
    for i in range(len(lis)):
        if i % 2 == 0:
            a += lis[i]
        else:
            b += lis[i]
    print(a - b)


if __name__ == '__main__':
    main()




# Example run
# Input:
vfWhX\&
665422
# Output:
665422
n = int(input())
a =list(map(int,input().split()))
p = sorted(a)[::-1]
print(sum(p[::2])-sum(p[1::2]))
   

# Example run
# Input:
107
186860433
# Output:
186860433
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 += A[i]
        else:
            Bob += A[i]

    print(Alice - Bob)


if __name__ == "__main__":
    main()


# Example run
# Input:
-18579092
21643
# Output:
0
n = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)
alice, bob = 0, 0
for i, val in enumerate(cards):
  alice += val if i%2==0 else 0
  bob += val if i%2==1 else 0
print(alice - bob)

# Example run
# Input:
165350
-2
# Output:
-2
n = int(input())
li = sorted(list(map(int, input().split())), reverse = True)

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

# Example run
# Input:
0
-6956
# Output:
-6956
N = int(input())
x = list(map(int, input().split()))
A = [0] * N
B = [0] * N
x.sort()
x.reverse()
for i in range(N):
    if i % 2 == 0:
        A[i] = x[i]
    else:
        B[i] = x[i]
print(sum(A) - sum(B))

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

alice = sum(a[::2])
bob = sum(a[1::2])

print(alice - bob)  

# Example run
# Input:
22710854
-2147483648
# Output:
-2147483648
N = int(input())
a = list(map(int, input().split()))
a.sort()
A_score = 0
B_score = 0
counter = 0
while len(a)>0:
  if counter % 2 == 0:
    A_score += a.pop()
  else:
    B_score += a.pop()
  counter += 1

print(A_score - B_score)

# Example run
# Input:
-7038374
-6
# Output:
-6
n = int(input())
a = list(map(int,input().split()))
alice = 0
bob = 0
a.sort()
while True:
    alice += max(a)
    a.pop()
    a.sort()
    if a == []:
        break
    bob += max(a)
    a.pop()
    if a == []:
        break
print(alice - bob)

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

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


# Example run
# Input:
-160045822
155287
# Output:
155287
N = int(input())
a = [int(i) for i in 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:
-274078593
-28418
# Output:
0
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
A1 = a[0:n:2]
A2 = a[1:n:2]
print(sum(A1)-sum(A2))


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

# Example run
# Input:
Br7-
-2
# Output:
-2
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:
-12503953
-345658
# Output:
-345658
import sys


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

    a.sort()
    a.reverse()

    alice = sum(a[::2])
    bob = sum(a[1::2])
    ans = alice - bob
    print(ans)


if __name__ == "__main__":
    resolve()


# Example run
# Input:
8131
1813543
# Output:
1813543
n = int(input())
card = list(map(int,input().split()))
card = sorted(card,reverse=True)
alice = 0
bob = 0


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

print(alice-bob)


# Example run
# Input:
10559
1792657
# Output:
1792657
n = int(input())
cards = [int(i) for i in input().split(' ')]
cards.sort(reverse=True)

alice = 0
bob = 0

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

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


# Example run
# Input:
-1051
-27
# Output:
-27
N = int(input())
a = [int(i) for i in input().split()]
a_sorted = sorted(a,reverse=True)
diff = 0
for i in range(int(N/2)):
       diff +=  a_sorted[2*i] - a_sorted[2*i + 1]
if(N%2 != 0):
       diff += a_sorted[N-1]
print(diff)
               


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

ans=0
for i in range(n):
    ans+=a[-i-1]*(-1)**(i)
    
    
print(ans)


# Example run
# Input:
-31
-58867430
# 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:
-14
0
# Output:
0
N = int(input())
a_list = list(map(int,input().split()))
it = iter(a_list)

alice = list()
bob   = list()

for i in range(int(len(a_list)+1/2)):
	try:
		alice.append(max(a_list))
		a_list.remove(max(a_list))
		bob.append(max(a_list))
		a_list.remove(max(a_list))
	except ValueError:
		break

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


# Example run
# Input:
-6212597
36241
# Output:
36241
N=input()

Ai = sorted(list(map(int,input().split())))

alice = 0
bob = 0

#Ai.sort()
#print(Ai)

while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

print(alice - bob)

# Example run
# Input:
iNo/$h8
55692629
# Output:
55692629
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
alice = sum(a[::2])
bob = sum(a[1::2])

print(alice-bob)

# Example run
# Input:
-3
-1
# Output:
-1
# https://atcoder.jp/contests/abc088/tasks/abc088_b
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))


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

print(alice - bob)


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

# Example run
# Input:
655579180
-22914821
# Output:
-22914821
from collections import deque
 
N = int(input())
a = deque(sorted([int(i) for i in input().split()]))
 
sub = 0
for i in range(N):
    if i % 2 == 0:
        sub += a.pop()
    else:
        sub -= a.pop()
 
print(sub)

# Example run
# Input:
-7
9186
# Output:
0
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
for i in range(N):
    m = max(a)
    x = a.index(m)
    if i % 2 == 0:
        A += m
    else:
        B += m
    a[x] = 0
print(A - B)


# Example run
# Input:
-57594492
-2243514
# Output:
0
# coding: utf-8

n = int(input())
a = [int(i) for i in input().split()]
junban = True
Alice = Bob = 0

while a:
    if junban:
        Alice += max(a)
        a.remove(max(a))
        junban = False
    else:
        Bob += max(a)
        a.remove(max(a))
        junban = True

print(Alice -Bob)

# Example run
# Input:
981571
-6163826
# Output:
-6163826
def main():
    n = int(input())
    cards = list(map(int, input().split()))
    alice_point = 0
    bob_point = 0

    cards.sort()
    for i in range(0, n):
        if i%2 == 0:
            alice_point += cards[i]
        else:
            bob_point += cards[i]

    print(alice_point - bob_point)

if __name__ == '__main__':
    main()

# Example run
# Input:
-7617381
-568126729
# Output:
0
N = int(input())
a = list(map(int, input().split()))
a_total, b_total = 0,0
for k in range(N):
    m = max(a)
    if k%2==0:
        a_total += m
    else:
        b_total += m
    a.remove(max(a))
print(a_total-b_total)

# Example run
# Input:
-5058
346
# Output:
0
N = int(input())

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

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



print(abs(b-c))



# Example run
# Input:
-1325982
57961
# 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:
7
-6668663
# Output:
-6668663
n = int(input())
a = list(map(int,input().split()))
a.sort()

c = a[::2]
d = a[1::2]
print(sum(d)-sum(c))

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

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

alice = []
a.sort(reverse=True)
for i in range(0, N, 2):
    alice.append(a[i])
print(2 * sum(alice) - sum(a))


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

card.sort()
card.reverse()

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

x = sum(A) - sum(B)

print(x)

# Example run
# Input:
35
-2
# Output:
-2
N = input()

lst_A = input().split()

A_sum = 0
B_sum = 0

for i in range(len(lst_A)):
    lst_A[i] = int(lst_A[i])

lst_A.append(-1)

lst_A.sort(reverse=True)

while 1:
    if lst_A[0] == -1:
        break
    A_sum += lst_A[0]
    del lst_A[0]
    if lst_A[0] == -1:
        break
    B_sum += lst_A[0]
    del lst_A[0]

ans = A_sum - B_sum
print(ans)

# Example run
# Input:
*'x-S-PK
-31
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
ans = 0
for i in range(0, n, 2):
    ans += a[i]
for i in range(1, n, 2):
    ans -= a[i]
print(ans)

# Example run
# Input:
-3
24
# Output:
0
N = int(input())
Ai = list(map(int,input().split()))
Alice = 0
Bob = 0
Ai.append(0)

for i in Ai:
    Alice += max(Ai)
    Ai.remove(max(Ai))
    if not Ai:
        break
    Bob += max(Ai)
    Ai.remove(max(Ai))

print(Alice-Bob)

# Example run
# Input:
134
-5930
# Output:
5930
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    A.sort(reverse=True)
    ans = sum(A[0::2]) - sum(A[1::2])
    print(ans)
    
    
solve()

# Example run
# Input:
-464240
19804
# Output:
19804
n=input()
l=list(map(int,input().split()))
l.sort()
ans=0
while l:
    ans+=l.pop()
    if l:
        ans-=l.pop()
print(ans)

# Example run
# Input:
"O?Wixhv
137752
# Output:
137752
n = int(input())

an = list(map(int,input().split()))
an = sorted(an,reverse=True)
print(sum(an[0::2])-sum(an[1::2]))

# Example run
# Input:
-112
-246934
# Output:
-246934
# ABC 088: B – Card Game for Two
n = int(input())
a = [int(s) for s in input().split()]

a.sort(reverse = True)

score_Alice = sum(a[0::2])
score_Bob = sum(a[1::2])

print(score_Alice - score_Bob)

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

# Example run
# Input:
e3zvshd]
45580
# Output:
45580
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:
0
-23
# Output:
0
N = int(input())
a = list(map(int, input().split()))

Alice, Bob = 0, 0

for i in range(N):
  if i % 2 == 0:
    Alice += a.pop(a.index(max(a)))
  else:
    Bob += a.pop(a.index(max(a)))
    
ans = abs(Alice - Bob)

print(ans)

# Example run
# Input:
-123410341
9062461
# Output:
0