Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
N=int(input())
li=list(map(int,input().split()))
lis=sorted(li,reverse=True)
lisalice=lis[0::2]
lisbob=lis[1::2]
print(sum(lisalice)-sum(lisbob))

# Example run
# Input:
-7698469
-5952
# Output:
-5952
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:
-66735
-1628416575
# Output:
-1628416575
N = int(input())
a = [int(x) for x in input().split()]
alice = 0
bob = 0
a.sort()
i = 0
for x in reversed(a):
  if(i%2==0):
    alice += x
  else:
    bob += x
  i += 1
print(alice-bob)

# Example run
# Input:
28016
-48
# Output:
-48
N = int(input())
A = list(reversed(sorted(list(map(int, input().split())))))

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

print(ans)


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

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

Alice = 0
Bob = 0
A.sort(reverse=True)
for i in range(len(A)):
    if i%2 == 0:
        Alice += A[0]
    else:
        Bob += A[0]
    A.pop(0)
    
print(Alice-Bob)

# Example run
# Input:
10026
70800
# Output:
70800
n=int(input())
a=[int(i) for i in input().split()]
b=sorted(a)
m=int((n+1)//2)
s=0
for i in range(m):
  s+=b[2*i]
print(s)
  


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


# Example run
# Input:
-86
0
# 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:
-1836
-168854
# Output:
-168854
if __name__ == '__main__':
    int(input())
    l = list(map(int, input().split()))
    # l = [2, 7, 4]
    l.sort()
    l.reverse()
    a = sum(l[::2])
    b = sum(l[1::2])
    print(a - b)



# Example run
# Input:
-2
-2701677
# Output:
-2701677
N = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse = True)#　.sort()　がポイント。.sort(reverse = True) で降順になる
Alice = 0
Bob = 0

for i in range(len(cards)):# range(len())　の記法はポイント
    if i % 2 == 0:
        Alice += cards[i]
    else:
        Bob += cards[i]

difference = Alice - Bob
print(difference)

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

a.sort(reverse=True)

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

print(ans)


# Example run
# Input:
730190
-6
# Output:
-6
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:
134
-5930
# Output:
-5930
n = int(input())
ais = input().split()
ais_int = [int(a) for a in ais]
ais_sort = ais_int.sort()
alice = 0
bob = 0
if n % 2 == 0:
  for i in range(n):
    if i % 2 == 1:
      alice += int(ais_int[i])
    else:
      bob += int(ais_int[i])
else:
  for j in range(n):
    if j % 2 == 0:
      alice += int(ais_int[j])
    else:
      bob += int(ais_int[j])
print(alice - bob)

# Example run
# Input:
1
4887419
# Output:
4887419
N = int(input())
c = list(map(int, input().split()))
c.sort(reverse = True)
A = []
B = []
n = 0
for i in c:
    if n % 2 == 0:
        A.append(i)
    else:
        B.append(i)
    n += 1
print(sum(A) - sum(B))


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


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

# Example run
# Input:
-7737
-126905272
# Output:
0
N = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)

al=list()
bl=list()

i = 0
j = 0
while 2*i < N:
    al.append(l[2*i])
    i = i + 1
while 2*j+1 < N:
    bl.append(l[2*j+1])
    j = j+1
    
print(sum(al)-sum(bl))

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

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


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

total_a = 0
total_b = 0

count = 0

while len(a) > 0:
    if count % 2 == 0:
        max_value = max(a)
        total_a += max_value
        a.remove(max_value)
        count += 1
    else:
        max_value = max(a)
        total_b += max_value
        a.remove(max_value)
        count += 1
    
print(total_a - total_b)

# Example run
# Input:
13
-123410341
# Output:
-123410341
input()
A = list(map(int, input().split()))

a_score = 0
b_score = 0

A.sort(reverse=True)

for i in range(len(A)):
  if i % 2 == 0:
    a_score += A[i]
  else:
    b_score += A[i]

print(a_score - b_score)

# Example run
# Input:
(MWFo`u
-210
# Output:
-210
N = int(input())
A = sorted(list(map(int, input().split())))
print(sum(A[-1::-2])-sum(A[-2::-2]))


# Example run
# Input:
13637464
243
# Output:
243
N = int(input())
L = list(map(int, input().split()))
L.sort()
A = 0
B = 0
for i in range(N):
  if i % 2 == 0:
    A += i
  else:
    B += i
print(A-B)

# Example run
# Input:
-773646
-12962
# Output:
0
N=int(input())
C=list(map(int,input().split()))
Alice=0
Bob=0
new=sorted(C,reverse=True)
for i in range(N):
  if i%2==0:
    Alice+=new[0]
    new.pop(0)
  else:
    Bob+=new[0]
    new.pop(0)
print(Alice-Bob)

# Example run
# Input:
-1
-3439167
# Output:
0
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:
-1
-3439167
# Output:
-3439167
n = int(input())
a = list(map(int, input().split()))

p = 0
q = 0

a = sorted(a, reverse=True)

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

print(p - q)


# Example run
# Input:
-573
531
# 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:
-28977
-22775593
# Output:
-22775593
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

# Example run
# Input:
45093
3
# Output:
3
N = int(input())
numbers_list = sorted([int(num) for num in input().split()])
Alice_sum = sum([numbers_list[index] for index in range(N) if index % 2 == 0])
Bob_sum = sum([numbers_list[index] for index in range(N) if index % 2 != 0])
print(abs(Alice_sum - Bob_sum))

# Example run
# Input:
-473
-7
# Output:
0
n = int(input())
nlist = list(map(int, input().split()))
alice = 0
bob = 0
for i in range(n):
    if(i%2==0):
        alice = alice + max(nlist)
    else:
        bob = bob + max(nlist)
    nlist.remove(max(nlist))
print('{}'.format(alice-bob))

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

A = 0
B = 0
for i, x in enumerate(sorted(a)[::-1]):
    if i % 2 == 0:
        A += x
    else:
        B += x
print(A-B)


# Example run
# Input:
-104837
-69520
# Output:
-69520
n=int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
p=0
q=0

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

# Example run
# Input:
-8145087
17
# Output:
0
N = int(input())
lst = sorted([int(x) for x in input().split()], reverse=True)
ret = 0
for idx, x in enumerate(lst):
    if idx % 2 == 0:
        ret += x
    else:
        ret -= x
print(ret) 

# Example run
# Input:
618445
-3249
# Output:
-3249
# https://atcoder.jp/contests/abc088/tasks/abc088_b
# B - Card Game for Two

n = int(input().split()[0])
a_list = list(map(int, input().split()))

a_list = sorted(a_list, reverse=True)
p_alice = sum(a_list[::2])
p_bob = sum(a_list[1::2])
ans = p_alice - p_bob
print(ans)


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

a.sort(reverse=True)

A = a[0:N:2]
B = a[1:N:2]

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

# Example run
# Input:
-255155
-14
# Output:
0
n = int(input())
card_list = list(map(int,input().split()))
alice_score = 0
bob_score = 0
card_list.sort(reverse = True)
for i in range(0,n):
    if i % 2 == 0:
        alice_score += card_list[i]
    else:
        bob_score += card_list[i]
        
print(alice_score - bob_score)

# Example run
# Input:
-5095
1267176863
# 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:
-497
-15860207
# Output:
-15860207
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())
  
n=i()
a=intl()
a.sort()
alice=0
bob=0
for i in range(-1,-n-1,-1):
	if i%2==1:
		alice+=a[i]
	else:
		bob+=a[i]
print(alice-bob)

# Example run
# Input:
-959568
-377
# 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:
-54266464
-274078593
# Output:
-274078593
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:
-496
-4
# Output:
0
n=int(input())
As=list(map(int,input().split()))
As.sort(reverse=True)

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

print(alice-bob)

# Example run
# Input:
-21640439
6179
# Output:
6179
N = int(input())
A = list(map(int, input().split()))
Alice = 0
Bob = 0
A = sorted(A, reverse = True)
for i, a in enumerate(A):
    if i %2 == 0:
        Alice += a
    else:
        Bob += a

print(Alice - Bob)

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

alice_sum = 0
bob_sum = 0

while len(an_list) != 0:
    alice_sum += max(an_list)
    an_list.remove(max(an_list))
    if len(an_list) != 0:
        bob_sum += max(an_list)
        an_list.remove(max(an_list))

print(alice_sum - bob_sum)


# Example run
# Input:
-56661351
981571
# Output:
981571
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:
-224960337
446
# 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:
3615919
-3550
# Output:
-3550
n=int(input())
num=sorted(list(map(int,input().split())),reverse=True)
a=[]
b=[]
flag=True
for i in range(n):
  l=max(num)
  num.remove(l)
  if flag:
    a.append(l)
    flag=False
  else:
    b.append(l)
    flag=True
print(sum(a)-sum(b))

# Example run
# Input:
-124978655
-23909
# Output:
0
N = input()
A = list(map(int, input().split(" ")))
A.sort(reverse=True)
alice = sum([j for i,j in enumerate(A) if i % 2 == 0])
bob = sum([j for i,j in enumerate(A) if i % 2 != 0])
print(alice - bob)

# Example run
# Input:
!8'gg[Y)
-110923
# Output:
-110923
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

alice = []
bob = []
for i in range(n):
  if (i % 2) == 0:
    alice.append(a[i])
  else:
    bob.append(a[i])

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

# Example run
# Input:
-39355
1
# Output:
0
n = int(input())
num_list = list(map(int, input().split()))

Alice = 0
Bob = 0

for i in range(n):
    current_max = max(num_list)
    if i % 2 == 0:
        Alice += current_max
    else:
        Bob += current_max
    num_list.remove(current_max)

print(Alice - Bob)


# Example run
# Input:
-194715587
-2938
# Output:
0
N = input()
nums = list(map(int, input().split()))

sorted_nums = sorted(nums, reverse=True)

a = 0
b = 0

def calSumOfDig(n):
    total = 0
    for i in n:
        total += i
    return total


ls = calSumOfDig(sorted_nums[0::2]) - calSumOfDig(sorted_nums[1::2])

print(ls)

# Example run
# Input:
1+^6:
-76824657
# Output:
-76824657
def main():
    N = int(input().strip())
    A = [int(x) for x in input().strip().split()]
    A.sort(reverse=True)
    alice = sum(A[0::2])
    bob = sum(A[1::2])
    return alice - bob

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

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

alice = 0
bob = 0

for i in range(n):
    if i%2 == 0 :
        alice += max(a)
        del a[a.index(max(a))]
    else :
        bob += max(a)
        del a[a.index(max(a))]
print(alice - bob)

# Example run
# Input:
-1
-3439167
# Output:
0
N=int(input())
card_list=list(map(int,input().split()))
#各自が自分の数字を最大化するように選択するのが前提なのでAliceが確実に勝つ。
#Aliceは１番目、３番目、５番目、７番目・・・に取っていく
#Bobは２番目、４番目、６番目、８番目・・・に取っていく
#sort関数には、「reverse」という引数が存在します。reverseをTrueに指定することで「降順」を示すことになります。

card_list.sort(reverse=True)
#print(card_list)

card_list_Alice=card_list[::2]
#print(card_list_Alice)
Alice_score=sum(card_list_Alice)
#print(Alice_score)
Bob_score=sum(card_list)-Alice_score
#print(Bob_score)
#Alice_score=card_list[1]+card_list[3]+
#Bob_score=card_list[2]+card_list[4]+

print(Alice_score-Bob_score)


# Example run
# Input:
-2540
-1836
# Output:
-1836
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

i = 0
A = 0
B = 0
while i < N:
    A += a[i]
    if i+1 < N:
        B += a[i+1]
    i += 2
print(A - B)

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

# Example run
# Input:
65153902
20794
# Output:
20794
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

input()
a=sorted(ipt(),reverse=True)
print(sum(a[::2])-sum(a[1::2]))

# Example run
# Input:
8H2.
-230914
# Output:
-230914
n = int(input())
c = list(map(int,input().split()))
c = sorted(c,reverse=True)
Alice=c[0::2]
Bob=c[1::2]
print(sum(Alice)-sum(Bob))

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

# Example run
# Input:
65444
-740
# Output:
-740
def buttle(a):
    alice = 0
    bob = 0

    a.sort(reverse=True)
    for i in range(len(a)):
        if i % 2 != 0:
            continue
        alice += a[i]
        if len(a) > i+1:
            bob += a[i+1]
    return alice - bob

n = int(input())
a = [int(x) for x in input().split()]
print(buttle(a))


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

# Example run
# Input:
-56661351
981571
# Output:
981571
#
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
#print(N, A)

#
alice = 0
bob = 0
for i in range(N//2):
    alice += A[i*2]
    bob += A[i*2 + 1]
if N%2!=0:
    alice += A[-1]

#
print(alice - bob)


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

# Example run
# Input:
-2552
-330190783
# Output:
0
N = int(input())
cards_num = [int(x) for x in input().split(' ')]

cards_num.sort(reverse=True)

bob = []
alice = []

for j in range(len(cards_num)):
    if j % 2 == 0:
        bob.append(cards_num[j])
    else:
        alice.append(cards_num[j])

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

# Example run
# Input:
-501843
-1
# Output:
-1
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:
-62350830
260615611
# Output:
260615611
N = int(input())
A = list(map(int, input().split(' ')))

revA = sorted(A, reverse=True)

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

print(alice - bob)

# Example run
# Input:
-5
-64
# Output:
-64
n=int(input())
lst=list(map(int,input().split()))

alice=0
bob=0

lst.sort()
for i in range(n):
    if i%2==0 :
        alice+=lst.pop()
    else :
        bob+=lst.pop()
print(alice-bob)


# Example run
# Input:
-746
-63
# Output:
0
n = int(input())
ls_a = list(map(int, input().split()))

Alice = 0
Bob = 0

ls_b = sorted(ls_a, reverse=True)

for i in range(n):
    if i % 2 == 0:
        Alice += ls_b[i]
    elif i % 2 == 1:
        Bob += ls_b[i]

print(Alice - Bob)

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


# Example run
# Input:
@53vp2<ju
-959568
# Output:
-959568
N = input()
cards = list(map(int, input().split()))

apoint = 0
bpoint = 0
while True:
	apoint += max(cards)
	cards.remove(max(cards), )

	if len(cards) == 0:
		break

	bpoint += max(cards)
	cards.remove(max(cards))

	if len(cards) == 0:
		break

dif = apoint - bpoint
print(dif)

# Example run
# Input:
fX_C`P
129445
# Output:
129445
N = input()
A = list(map(int, input().split()))
A.sort(reverse=True)

Alice = A[0::2]
Bob = A[1::2]

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

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

# Example run
# Input:
_+Yy
-2147483648
# Output:
-2147483648
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:
0
6681
# 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:
7400050
-15913
# Output:
-15913
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
print(sum(A[::2]) - sum(A[1::2]))

# Example run
# Input:
-32460
-375
# Output:
-375
# coding: utf-8
# Your code here!
num = int(input())
s = sorted(list(map(int,input().split())) ,reverse = True)

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

print(alice - bob)



# Example run
# Input:
-104837
-69520
# Output:
-69520
N = int(input())
a_list = list(map(int, input().split()))

sort_a_list = sorted(a_list, reverse=True)

alice = 0
bob = 0

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

print(alice - bob)

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

# Example run
# Input:
465
0
# 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:
-143891
-195933
# Output:
-195933
_ = input()
num_list = list(map(lambda x: int(x), input().split(" ")))

num_list.sort()
num_list.reverse()

Alice = 0
Bob = 0
turn = True

while(True):
  if len(num_list) == 0:
    break
  
  if turn:
    Alice += num_list.pop(0)
  else:
    Bob += num_list.pop(0)
  turn = not turn
print(Alice - Bob)

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

alice = 0
bob = 0

for i in range(0,N):
  if i %2 == 0:
    alice += card_num[i]
  else:
    bob   += card_num[i] 
ans = int(alice - bob)

print(ans)

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

x = 0
y = 0

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

print(x - y)

X = []


# Example run
# Input:
-4422
-15015728
# Output:
0
import sys

def resolve():
    N = int(input())
    S = list(map(int, input().split(" ")))
    S.sort(reverse=True)
    print(sum(S[0::2]) - sum(S[1::2]))


if '__main__' == __name__:
    resolve()

# Example run
# Input:
-99716696
3280
# Output:
3280
import sys
import math
import bisect

def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    alice = 0
    for i in range(0, n, 2):
        alice += A[i]
    bob = sum(A) - alice
    print(alice - bob)

if __name__ == "__main__":
    main()


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


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

# Example run
# Input:
187
-33958
# Output:
-33958
N = int(input())

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

Alice = 0
Bob = 0

for i in range(len(card)):
    if i % 2 == 0:
        Alice += max(card)
    else:
        Bob += max(card)
    del card[card.index(max(card))]

print(str(Alice - Bob))

# Example run
# Input:
-89083
-3339504
# Output:
-3339504
def main():
    N = int(input())
    an = sorted(list(map(int, input().split())), reverse=True)
    print(sum(an[i] for i in range(0, N, 2)) -
          sum(an[j] for j in range(1, N, 2)))


main()


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

a_list.sort(reverse=True)

alice = 0
for a in a_list[::2]:
    alice += a

bob = 0
for b in a_list[1::2]:
    bob += b

print(alice - bob)

# Example run
# Input:
-259420352
376395
# Output:
376395
x = int(input())
a = list(map(int, input().split()))

b = sorted(a, reverse=True)

ans_Alice = 0
ans_Bob = 0

for i in range(x): 
    if i%2 ==0:
        ans_Alice += int(b[i])
    else:
        ans_Bob += int(b[i])

        
print(int(ans_Alice) - int(ans_Bob))


# Example run
# Input:
-247872467
-5363
# Output:
0
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:
-18579092
21643
# Output:
21643
n = int(input())
nl = list(map(int, input().split()))
a, b = 0, 0
nl.sort(reverse=True)
for i in range(len(nl)):
  if i % 2 == 0:
    a += nl[i]
  else:
    b += nl[i]
print(abs(a - b))

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

sumA=0
sumB=0

for i in range(0,N,2):
    sumA+=list[i]
for j in range(1,N,2):
    sumB+=list[j]

print(sumA-sumB)

# Example run
# Input:
-109089799
-74270783
# Output:
0
N = int(input())
a = map(int, input().split(" "))

l = list(reversed(sorted(a)))

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

print(alice-bob)


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

# Example run
# Input:
1291
-758403
# Output:
-758403
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]
ans = Alice - Bob
print(ans)

# Example run
# Input:
-2147483648
16667401
# Output:
0
s=input()
t=list(map(int,input().split()))
t.sort(reverse=True)
a=0
b=0
d=0
e=0
if len(t)%2==0:
  for i in range(0,len(t),2):
    d+=t[i]
    e+=t[i+1]
  print(d-e)
else:
  for j in range(0,len(t),2):
    d+=t[j]
  for l in range(1,len(t),2):
    e+=t[l]
  print(d-e)

# Example run
# Input:
8u=^Atb
3
# Output:
3