Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)
arrA.sort()
arrA = arrA[::-1]

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

ans = Alice-Bob

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


# Example run
# Input:
-14953
0
# Output:
0
# B - Card Game for Two
n = int(input())
num_list = list(map(int, input().split()))

num_list = sorted(num_list, reverse=True)
a, b = 0, 0
for i, s in enumerate(num_list):
    if i%2==0:
        a += s
    else:
        b += s
print(a-b)


# Example run
# Input:
-160045822
155287
# Output:
155287
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:
141725276
-109089799
# Output:
-109089799
num = int(input())
ls = list(map(int,input().split()))
new_ls = sorted(ls,reverse = True)

Alice = 0
Bob = 0

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

print(Alice - Bob)


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

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

# Example run
# Input:
-168854
-5
# 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:
-146654
12
# Output:
12
N = int(input())
a = [int(x) for x in input().split()]
a = sorted(a, reverse=True)
ans = 0
for n in range(0,N,2):
    ans += a[n]
    if n+1 < N:
        ans -= a[n+1]
print(ans)

# Example run
# Input:
-1
-931255046
# Output:
0
N = int(input())
A = sorted(map(int,input().split(' ')),reverse = True)

ans = sum(A[::2]) - sum(A[1::2])
print(ans)

# Example run
# Input:
214
12
# Output:
12
#088_B
n=int(input())
a=sorted(list(map(int,input().split())))[::-1]
print(sum(a[::2])-sum(a[1::2]))

# Example run
# Input:
-377
-491914923
# Output:
-491914923
N=int(input())
A=list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N+1):
  if num % 2 ==0:
    sum1 += num
  else:
    sum2 += num
print(sum1-sum2)

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

# Example run
# Input:
34
-27
# Output:
-27
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:
-226728064
-196
# Output:
0
N = int(input())
A = list(map(int,input().split()))

turn = 0
point = [0,0]
while A:
    t = max(A)
    A.remove(t)
    point[turn%2] += t
    turn += 1

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

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

A,B = 0,0
for i in range(n):
  if i == 0 or i%2 == 0:
    A += a[i]
  else:
    B += a[i]

if A > B:
  print(A-B)
else:
  print(B-A)

# Example run
# Input:
-7606
26622290
# Output:
0
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
answer = 0
for i in range(0,N,2):
  answer += a[i]
for i in range(1,N,2):
  answer -= a[i]
print(answer)

# Example run
# Input:
-47187920
-8116
# Output:
0
N = int(input())
an = sorted(list(map(int,input().split())),reverse = True)
A = 0
B = 0
for num,i in enumerate(an):
    if num%2==0:
        A+=i
    else:
        B+=i
print(abs(A-B))

# Example run
# Input:
-6163826
139893
# Output:
139893
n = int(input())
a = list(map(int, input().split()))
data = sorted(a, reverse = True)    # aを降順にソート
Alice = 0
Bob = 0
for i in range(n):
    if i % 2 == 0:
        Alice += data[i]
    else:
        Bob += data[i]
print(Alice - Bob)


# Example run
# Input:
-11989124
-407
# Output:
0
n = int(input())
A = sorted(map(int, input().split()))[::-1]
# print(A)
loop = 0
scoreA = 0
scoreB = 0
for e in A:
    if loop % 2 == 0:
        scoreA += e
    else:
        scoreB += e
    loop += 1
print(scoreA - scoreB)


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

# Example run
# Input:
-188803
-802253
# Output:
0
N = int(input())
A = list(sorted(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:
-63933682
-2714471
# Output:
0
n=int(input())
a=list(map(int,input().split()))
a.sort()
f=True
ans=0
for i in range(n):
	if(f):
		ans+=a[i]
		f=False
	else:
		f=True
print(ans)


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

alice_num = sum(a[::2])
bob_num   = sum(a[1::2])
print(alice_num - bob_num)


# Example run
# Input:
19
-4868286
# Output:
-4868286
import math
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
for i in range(1, math.floor(N / 2 + 1)):
    Alice += max(a)
    a.remove(max(a))
    Bob += max(a)
    a.remove(max(a))
if N %2 != 0:
    Alice += max(a)
print(Alice - Bob)

# Example run
# Input:
-407
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(alice - bob)

# Example run
# Input:
-1836
-168854
# Output:
0
# -*- coding: utf-8 -*-
a = int(input())  # Nを入力
b = input()  # a1,a2...anを入力
b = map(int, b.split())  # a1,a2...anをint型でリストに入れる
b = sorted(b)  # 大きい順に並べる 
b = b[::-1]  # リストの要素の順番を逆転する
c = b[::2]  # Aliceのとる要素を抽出
c_number = len(c)
d = b[1::2]  # Bobのとる要素を抽出
d_number = len(d)
c_sum = 0
d_sum = 0
for i in range(c_number):
    c_sum += c[i] # Aliceのとる要素の合計
for g in range(d_number):
    d_sum += d[g]  # Bobのとる要素の合計
print(c_sum - d_sum)  # 差分を出力


# Example run
# Input:
449660
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(Alice - Bob)


# Example run
# Input:
-168
5946
# Output:
0
# B - Card Game for Two
#25min
N = int(input())
a_input = map(int, input().split())
a = list(a_input)
alice = 0
bob = 0
a.sort(reverse=True)
for i in range(N):
    if i%2 == 0:
        alice = alice + a[i]
    else:
        bob = bob + a[i]
print(alice-bob)

# Example run
# Input:
-29588
-5
# Output:
0
n = int(input())
listA = list(map(int, input().split()))

listA.sort()
listA.reverse()

pointA=0
pointB=0
index=0
while index <n:
    if index%2 ==0:
        pointA+=listA[index]
    else:
        pointB+=listA[index]
    index+=1

print(pointA-pointB)

# Example run
# Input:
0
-11989124
# Output:
0
N = input()
alist = list(map(int, input().split()))
alist.sort(reverse = True)
AliSc = 0
BobSc = 0

while alist != []:
    AliSc += alist[0]
    del alist[0]
    if alist != []:
        BobSc += alist[0]
        del alist[0]
    else:
        break

print(AliSc - BobSc)


# Example run
# Input:
7kdR.Z+]
796395
# Output:
796395
n=int(input())
a=list(map(int,input().split()))

Alice=0
Bob=0
a.sort()
#print(a)
h=len(a)
for i in range(h):
    if len(a)>0:
        Alice+=a[-1]
        del a[-1]
        h-=1
    if len(a)>0:
        Bob+=a[-1]
        del a[-1]
        h-=1
print(Alice-Bob)

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


# Example run
# Input:
22710854
-2147483648
# Output:
-2147483648
n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)
Alice = [a[i] for i in range(n) if i % 2 == 0]
print(2 * sum(Alice) - sum(a))

# Example run
# Input:
-181
1419428
# Output:
-1419428
n = int(input())
a = list(map(int, input().split()))
a.sort()

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

print(alice-bob)


# Example run
# Input:
38379
11
# Output:
11
N = int(input())
x = [int(i) for i in input().split()]
x.sort()
x.reverse()
answer = 0
for j in range(len(x)):
 if j%2 == 0: answer+=x[j]
 else: answer-=x[j]
print(answer) 

# Example run
# Input:
-170
-478262
# Output:
-478262
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = sum(a)
for i in range(n):
    if i%2 == 1:
        ans -= 2*a[i]
print(ans)

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

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


print(alice-bob)

# Example run
# Input:
-86
11
# Output:
11
n = int(input())
ls = list(map(int,input().split()))
A = []
B = []
lsn = sorted(ls,reverse = True)

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

# Example run
# Input:
-4
1363926
# Output:
1363926
N = int(input())
a = list(int(i) for i in input().split())

Alice = 0
Bob = 0

if N%2 == 0:
    for n in range(int(N/2)):
        Alice += max(a)
        a.remove(max(a))
        Bob += max(a)
        a.remove(max(a))
else:
    for n in range(int((N-1)/2)):
        Alice += max(a)
        a.remove(max(a))
        Bob += max(a)
        a.remove(max(a))
    Alice += max(a)
print(Alice - Bob)

# Example run
# Input:
-220
9
# Output:
0
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
A = sum([i for i in a[::2]])
B = sum([j for j in a[1::2]])
print(A - B)


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

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

# Example run
# Input:
-17
-3786437
# Output:
-3786437
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:
1
-38175
# Output:
-38175
n = int(input())
c = list(map(int,input().split()))
c.sort(reverse = True)
a = 0
b = 0
if n % 2 == 0:
    for i in range(n // 2 ):
        a += c[i * 2]
        b += c[i * 2 + 1]
else:
    for i in range(n // 2 ):
        a += c[i * 2]
        b += c[i * 2 + 1]
    a += c[n - 1]

print(a - b)

# Example run
# Input:
-58867430
-56661351
# Output:
0
n = int(input())
nums = [int(i) for i in input().split()]

nums.sort(reverse=True)
print(sum(nums[0::2]) - sum(nums[1::2]))


# Example run
# Input:
-58867430
-56661351
# Output:
-56661351
n = int(input())
aSum = 0
bSum = 0
ans = 0
cards = [int(x) for x in input().split()]

for j in range(1,n+1):
    if j % 2 == 1:
        aSum += max(cards)
        cards.remove(max(cards))
    else:
        bSum += max(cards)
        cards.remove(max(cards))
ans = aSum - bSum
print(ans)

# Example run
# Input:
-17
-153163
# Output:
0
n=int(input())
c=sorted([int(i) for i in input().split()])[::-1]
a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(c[i])
    else:
        b.append(c[i])
print(sum(a)-sum(b))

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

Alice = []
Bob = []

while 0 < len(a):
    Alice.append(a.pop(a.index(max(a))))
    if 0 < len(a):
        Bob.append(a.pop(a.index(max(a))))

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

# Example run
# Input:
-3978447
1
# Output:
1
def card_game_for_two(N: int, A: list) -> int:
    sorted_A = sorted(A, key=lambda x: - x)
    alice = sum(a for i, a in enumerate(sorted_A) if i % 2 == 0)
    bob = sum(a for i, a in enumerate(sorted_A) if i % 2 == 1)
    return alice - bob


if __name__ == "__main__":
    N = int(input())
    A = map(int, input().split())
    ans = card_game_for_two(N, A)
    print(ans)


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

# Example run
# Input:
-14
0
# Output:
0
#
# abc088 b
#
n = int(input())
cards = list(map(int, input().split()))
a = 0
b = 0
for i in range(n):
    r = max(cards)
    if i % 2 == 0:
        a += r
    else:
        b += r
    cards.remove(r)
print(a-b)


# Example run
# Input:
-1406309
-967
# Output:
0
N = int(input())
a_list = [a for a in map(int, input().split())]
a_list.sort()
a_list.reverse()
alice = 0
bob = 0

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

# Example run
# Input:
-1771
87
# Output:
0
# B

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

alice = 0
bob = 0
flag = 0
while len(A):
    i = A.index(max(A))
    if flag == 0:
        alice += A[i]
        flag = 1
        del A[i]
    else:
        bob += A[i]
        flag = 0
        del A[i]

print(alice - bob)

# Example run
# Input:
-307298630
-1794
# Output:
-1794
input()
card = list(map(int,input().split()))
card.sort(reverse=True)
alice_turn = 1
alice = 0
bob = 0
for n in card:
  if alice_turn == 1:
    alice += n
    alice_turn = 0
  else:
    bob += n
    alice_turn = 1
print(alice-bob)

# Example run
# Input:
B`g>!d1
62746
# Output:
62746
N = int(input())
a = list(map(int, input().split()))

a.sort()
a.reverse()
print(a)

Alice = 0
Bob  = 0

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

print(Alice - Bob)

# Example run
# Input:
559
31946
# Output:
[31946]
31946
# coding: utf-8


class Player:

    def __init__(self):
        self.point = 0

    def add_point(self, point):
        self.point += point

    def get_point(self):
        return self.point


def main():

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

    alice = Player()
    bob = Player()
    players = [alice, bob]
    for i, card in enumerate(cards):
        players[i % len(players)].add_point(card)

    print(alice.get_point() - bob.get_point())

    return 0


if __name__ == '__main__':
    main()


# Example run
# Input:
28016
-48
# Output:
-48
def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort()

    Alice = 0
    Bob = 0
    j = 0

    for i in range(N - 1, -1, -1):
        if j % 2 == 0:
            Alice += a[i]
        else:
            Bob += a[i]
        j += 1

    print(Alice - Bob)

main()

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

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

print(alice-bob)


# Example run
# Input:
31934639
0
# 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:
54504816
-1005173
# Output:
-1005173
N = int(input())
a = list(map(int,input().split()))
sumA = 0
sumB = 0
for i in range(1,N+1):
    m = max(a)
    if i%2 == 1:
        sumA += m
    else:
        sumB += m
    a.remove(m)

print(sumA-sumB)



# Example run
# Input:
-11989124
-407
# 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:
-1045001
48199211
# Output:
48199211
n = input()
a = input().split()

tmp = sorted(a, reverse=True)

al = 0
bo = 0

for i in range(len(tmp)):
  if i %2 == 0:
    al = al + int(tmp[i])

  else:
    bo = bo + int(tmp[i])

print(al - bo)

# Example run
# Input:
u]Dspi35v
152731
# Output:
152731
n = int(input())
an = list(map(int,input().split()))
a = sorted(an, 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:
-4664
26550845
# Output:
0
n = int(input())
a = list(map(int, input().split()))
i = 0
Alice = []
Bob = []
while i < n:
    if a == []:
        break
    else:
        Alice.append(max(a))
        a.remove(max(a))
    if a == []:
        break
    else:
        Bob.append(max(a))
        a.remove(max(a))
    i += 1
print(abs(sum(Alice) - sum(Bob)))

# Example run
# Input:
-168
5946
# Output:
0
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = 0
bob = 0
count = 1
for c in a:
    if count%2==1:
        alice += c
    else:
        bob += c
    count +=1
print(alice-bob)

# Example run
# Input:
1973033
-264371717
# Output:
-264371717
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc088/tasks/abc088_b

def main():
    n = int(input())
    i = list(map(int,input().split()))
    # j = list(map(int,input().split()))

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

    # print(i[::2])
    # print(i[1::2])
    print(sum(i[::2]) - sum(i[1::2]))

main()


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

# Example run
# Input:
-1595467139
3280
# Output:
3280
n = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
L1 = L[0::2]
L2 = L[1::2]
print(sum(L1)-sum(L2))

# Example run
# Input:
20794
14319043
# Output:
14319043
N = int(input())
alist = list(map(int, input().split(" ")))
alist.sort()
alist.reverse()
score_a = sum(alist[::2])
score_b = sum(alist[1::2])
print(score_a - score_b)

# Example run
# Input:
-12503953
-345658
# Output:
-345658
n=int(input())

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

a.sort(reverse=True)

a=[(-1)**i*j for i,j in enumerate(a)]

print(sum(a))

# Example run
# Input:
9062461
72046879
# Output:
72046879
N = input()
a = input().split()

a.sort()
a.reverse()

alice = 0
bob = 0

a_num = len(a)

for i in range(a_num):
  if i % 2 == 0:
    alice += int(a[i])
  else:
    bob += int(a[i])

print(alice - bob)

# Example run
# Input:
7u+a
-9071
# Output:
-9071
n = int(input())
a = list(map(int,input().split()))

a.sort(reverse=True)

alice_score = 0
bob_score =0

for i,j in enumerate(a):
    if i % 2 == 0:
        alice_score += j
    else:
        bob_score += j

print(alice_score-bob_score)
        

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

# Example run
# Input:
-30
-3011
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for e, i in enumerate(a):
    if e % 2 != 0:
        ans += i
    else:
        ans -= i

print (abs(ans))

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

# Example run
# Input:
-473
-7
# 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(alice-bob)

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

a.sort()
alice = sum(a[0:N:2])
Bob = sum(a[1:N:2])

result = alice - Bob
result = abs(result)

print(result)


# Example run
# Input:
13499019
3132478
# Output:
3132478
_ = input()
xs = list(map(int, input().split()))

ys = reversed(sorted(xs))
zs = [y if i % 2 == 0 else -y for i, y in enumerate(ys)]
print(sum(zs))

# Example run
# Input:
fMa)B=<
-1575
# Output:
-1575
n = int(input())
a = sorted([int(i) for i in input().split()])[::-1]

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


# Example run
# Input:
5
-893630
# Output:
-893630
_ = input()
A = sorted(list(map(int, input().strip().split(' '))),reverse=True)

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


# Example run
# Input:
0}}x#m
-9
# Output:
-9
n = int(input())

num_list = sorted([ int(v) for v in input().split() ])

a_sum, b_sum = 0, 0

for i in range(n):
  if i % 2 == 0:
    a_sum += num_list[i]
  else:
    b_sum += num_list[i]

print(abs(a_sum-b_sum))

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

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

x = len(a)

Alice = 0
Bob = 0

for i in range(x):
    for j in range(x - 1 - i):
        if a[j] < a[j + 1]:
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp

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

   
z = Alice - Bob

print(z)

# Example run
# Input:
49968
20415230
# Output:
20415230
N = int(input())
A = list(map(int, input().split()))
if len(A) & 1:
  A.append(0)
A.sort()
print(sum([A[i+1]-A[i] for i in range(0, len(A), 2)]))

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

# Example run
# Input:
-5056872
2072477
# Output:
2072477
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    print(sum(A[::2]) - sum(A[1::2]))


if __name__ == "__main__":
    main()


# Example run
# Input:
203880
-75
# Output:
-75
def gusaku():
    n = int(input())
    List = list(map(int, input().split()))
    # 昇順ソートなので，前のsumnが小さくなる
    List_sorted = sorted(List, reverse=True)
    print(sum(List_sorted[::2]) - sum(List_sorted[1::2]))

gusaku()

# Example run
# Input:
-10841372
-2552
# Output:
-2552
n = input()
num = [i for i in map(int,input().split(" "))]

num.sort(reverse=True)

A = 0
B = 0
t=0
for i in num:
    if t%2==0:
        A+=int(i)
    else:
        B+=int(i)
    t+=1
print(A-B)


# Example run
# Input:
C1{'
0
# Output:
0
N = int(input())
L = input().split()
a = [ int(x) for x in L ]
a.sort(reverse=True)

Alice = 0
Bob = 0

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

# Example run
# Input:
-69520
-73864104
# Output:
-73864104
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : June 30, 2020
##################################################### SOURCE START #####################################################

N = int(input().strip())
An = list(map(int, input().strip().split()))

An = sorted(An, reverse=True)

p1 = sum(An[0::2])
p2 = sum(An[1::2])

print(p1 - p2)

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker


# Example run
# Input:
1
-38175
# Output:
-38175
N = int(input())
list = map(int,input().split(" "))
cards = sorted(list,reverse=True)

#Aliceの得点（偶数番目の総和）
alice = 0
for i in range(int(N/2) + 1):
    alice = alice + cards[2 * i]

#Bobの得点（奇数番目の総和）
bob = 0
for j in range(int(N/2)):
    bob = bob + cards[2 * j + 1]
    
print(alice - bob)

# Example run
# Input:
-8
-39
# Output:
0
S=0
N = int(input())
l = map(int, input().split())

l = list(sorted(l))

for i in range(1, N+1):
    print(i)
    if i%2 == 1:
        S+=l[N-i]
        #print(S)
    else:
        S-=l[N-i]
        #print(S)
            

#print('--------')
print(S)

# Example run
# Input:
1
-124978655
# Output:
1
-124978655
N = int(input())
cards = list(map(int,input().split()))
alice,bob = 0, 0
for i in range(N):
    choice = cards.pop(cards.index(max(cards)))
    if i % 2 == 0:
        alice += choice
    else:
        bob += choice
print(alice-bob)
    

# Example run
# Input:
-6865417
-48
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a.sort()
odds = sum(a[1::2])
even = sum(a[0::2])
if odds >= even:
    print(odds-even)
else:
    print(even-odds)

# Example run
# Input:
-331
18
# Output:
18