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

# Example run
# Input:
19928
129445
# Output:
129445
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n= int(input())
a = li()
sa = sorted(a)
sa.reverse()
ans = 0
for i in range(n):
    if i%2==0:
        ans += sa[i]
    else:
        ans -= sa[i]
print(ans)

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

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

# Example run
# Input:
eXf?
38254
# Output:
38254
def main():
    card_num = int(input())
    cards = list(map(int, input().split(" ")))
    cards.sort(reverse=True)
    answer = 0
    for i in range(card_num):
        if i % 2:
            answer -= cards[i]
        else:
            answer += cards[i]
    print(answer)


if __name__ == '__main__':
    main()

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


# Example run
# Input:
-10884483
-10
# Output:
0
N = input()
x = list(map(int, input().split()))

x.sort(reverse=True)
alice = 0
bob = 0
for i, j in enumerate(x):
    if i % 2 ==0:
        alice += j
    else:
        bob += j

print(alice - bob)

# Example run
# Input:
=EjU8YU=C
58900
# Output:
58900
# -*- coding: utf-8 -*-

def main():
    # 入力
    N = int(input())
    nums = list(map(int, input().split()))

    # 探索
    alice_sum = 0
    bob_sum = 0

    nums.sort(reverse=True)
    for i in range(len(nums)):
        if i % 2 == 0:
            alice_sum += nums[i]
        else:
            bob_sum += nums[i]

    print(alice_sum - bob_sum)


main()


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

# Example run
# Input:
2069520666
471
# Output:
471
N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)[::-1]
# print(A)
ans = sum(A[::2]) - sum(A[1::2])
print(ans)

# Example run
# Input:
-65
0
# Output:
0
n=int(input())
a=list(map(int,input().split()))
a.sort()
Alice=0
Bob=0
for i in range(n):
  if len(a)>0:
    Alice+=a.pop()
  if len(a)>0:
    Bob+=a.pop()
print(Alice-Bob)

# Example run
# Input:
-3528
-5900
# Output:
0
n = int(input())
K = [int(i) for i in input().split()]
K.sort()
K.reverse()
A, B = [], []
for i in range(n):
    if i % 2 == 0:
        A.append(K[i])
    else:
        B.append(K[i])
print(sum(A) - sum(B))

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

a = sorted(a, reverse=True)

A = 0
B = 0

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

print(A-B)        



# Example run
# Input:
-90312
-12211339
# Output:
0
import functools
_ = input()
A = [int(i) for i in input().split()]
score = 0
for i, a in enumerate(sorted(A, reverse=True)):
    score += a if i % 2 == 0 else -a
print(score)


# Example run
# Input:
}U(rSd@vC
3
# Output:
3
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

a.sort(reverse=True)

ali = 0
bob = 0

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








# Example run
# Input:
-2
669
# 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:
-1394868732
964893
# Output:
0
n = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)

i = n
ca = 0
cb = 0
for i in range(n):
    if i%2 == 1:
        ca += a[i]
    else:
        cb += a[i]

print(abs(ca-cb))
    

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

als = sorted(al,reverse = True)

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

print(alice-bob)

# Example run
# Input:
-14953
0
# Output:
0
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l, reverse=True)
l_a=[]
l_b=[]
for i in range(n):
  if i%2==0:
    l_a.append(l1[i])
  else:
    l_b.append(l1[i])
print(sum(l_a)-sum(l_b))

# Example run
# Input:
-147
-3225
# Output:
0
N=int(input())
a=[int(i) for i in input().split(" ")]
a.sort()
a.reverse()

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

# Example run
# Input:
-1504387
31
# Output:
0
n = int(input())

a_i_list = list(map(int, input().split(" ")))

a_i_list_sorted = sorted(a_i_list, reverse=True)

alice_sum = 0
bob_sum = 0

for index, val in enumerate(a_i_list_sorted):
  if index % 2 == 0:
    alice_sum += val
  else:
    bob_sum += val

print(alice_sum - bob_sum)

# Example run
# Input:
1041204430
105477721
# Output:
105477721
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from math import ceil

n=ni()
a=nl()

sa = sorted(a)[::-1]
print(sum(a[:ceil(n/2)])-sum(a[ceil(n/2):]))


# Example run
# Input:
-5271130
19
# Output:
-19
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
A = sum(a[::2])
B = sum(a[1::2])

print(A - B)

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

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

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

# Example run
# Input:
-877447
8312590
# Output:
8312590
n = int(input())
a_inputs = sorted([int(i) for i in input().split()],reverse=True)

alice = 0
for i in range(n):
    if i%2==0:
        alice+=a_inputs[i]
print(2*alice-sum(a_inputs))




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

# Initialize
Alice = 0
Bob = 0

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

print(Alice - Bob)

# Example run
# Input:
-497
-15860207
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
alice = 0
bob = 0
n = 0
while len(a) > 0:
    if n == 0:
        alice += a.pop()
        n = 1
    else:
        bob += a.pop()
        n = 0
print(alice - bob)

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

sumA=0
sumB=0

while lists!=[]:
    a=max(lists)
    sumA=sumA+a
    lists.remove(a)
    if lists!=[]:    
        b=max(lists)
        sumB=sumB+b
        lists.remove(b)

d=sumA-sumB
print(d)

# Example run
# Input:
-109089799
-74270783
# Output:
-74270783
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=True)
x = []
y = []
for i in range(len(a)):
    if i%2==0:
        x.append(a[i])
    else:
        y.append(a[i])
print(sum(x)-sum(y))


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

a.sort(reverse=True)
dif = 0
for i, p in enumerate(a):
    if i%2 == 0:
        dif += p
    else:
        dif -= p
print(dif)

# Example run
# Input:
19804
0
# Output:
0
n = int(input())
a = list(map(lambda x:int(x),input().split()))
a.sort(reverse=True)
al = 0
bo = 0
if n==1:
  al = a[0]
else:
  for i in range(0,n,2):
    al += a[i]
  for i in range(1,n,2):
    bo += a[i]
print(al-bo)

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


# Example run
# Input:
-9179099
165350
# Output:
0
N = int(input())
alist = input().split()
alist = sorted(alist, reverse=True)
count = 0
alice = 0
bob = 0

for a in alist:
    if count % 2:
        alice += int(a)
    else:
        bob += int(a)
    count+=1
print(alice - bob)

# Example run
# Input:
-168
5946
# Output:
-5946
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:
-114
-473
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)[::-1]
alice, bob = 0, 0
for i in range(n):
    if i%2==0: alice += a.pop(0)
    else: bob += a.pop(0)
print(alice - bob)

# Example run
# Input:
-24
-35784
# Output:
0
def get(S):
    return list(map(S, input().split()))

[N] = get(int)
A = get(int)
A = sorted(A)

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

print(Alice - Bob)



# Example run
# Input:
5568815
11756850
# Output:
11756850
N = int(input())
A = [int(c) for c in input().split()]

A.sort(reverse=True)
alice = sum([A[i] for i in range(0, N, 2)])
bob = sum([A[i] for i in range(1, N, 2)])
print(alice - bob)


# Example run
# Input:
-55564347
103913001
# Output:
0
# B - Card Game for Two
N = int(input())
A = [int(a) for a in input().split()]

A= sorted(A,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:
-65
0
# 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+=i
  else:
    y+=i
print(abs(x-y))


# Example run
# Input:
104
-200741513
# Output:
52
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:
141
-450
# Output:
-450
n = int(input())
a = list(map(int, input().split()))
Alice = 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:
-3
24
# Output:
0
N = int(input())
a = list(map(int,input().split()))
l = sorted(a, reverse = True)
count = 0
for i in range(N):
    if i % 2 == 0:
        count += l[i]
    else:
        count -= l[i]
print(count)

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

ascore = bscore = 0
for i in range(1, n+1):
    if i % 2 == 1:
        ascore += max(a)
    else:
        bscore += max(a)
    a.remove(max(a))
print(ascore - bscore)


# Example run
# Input:
-142
137752
# Output:
0
n = int(input())
A = sorted(map(int, input().split()), reverse = True)


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


# Example run
# Input:
-133790981
215616622
# Output:
215616622
def main():
    N = int(input())
    a = [int(x) for x in input().split()]
    apoints = 0
    bpoints = 0
    for i in range(N):
        if i%2 == 0:
            apoints += max(a)
        else:
            bpoints += max(a)
        a.remove(max(a))
    print(apoints - bpoints)

if __name__ == '__main__':
    main()

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

input_lis.sort(reverse=True)
a,b = 0,0
for i in range(len(input_lis)):
    if i % 2 == 0:
        a += input_lis[i]
    else:
        b += input_lis[i]
        
print(a-b)

# Example run
# Input:
-10841372
-2552
# Output:
-2552
n = input()
list_num = [int(num) for num in input().split()]
 
list_num.sort(reverse=True)
a = sum(list_num[0::2])
b = sum(list_num[1::2])
 
print(a-b)

# Example run
# Input:
!Wl~Jlh}
-7
# Output:
-7
N = int(input())
A = list(map(int, input().split()))
alice = []
bob = []

for i in range(len(A)):
  max_n = max(A)
  A.remove(max_n)
  if i%2 == 0:
    alice.append(max_n)
  else:
    bob.append(max_n)
print(sum(alice) - sum(bob))

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

a.sort(reverse=True)
alice_score = sum(a[0::2])
bob_score = sum(a[1::2])

print(alice_score - bob_score)

# Example run
# Input:
D`T
-128117474
# Output:
-128117474
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
a = sorted(list(map(int, input().split())))
A = sum(a[-1::-2])
B = sum(a[-2::-2])
print(str(A-B))

# Example run
# Input:
681963
77305
# Output:
77305
N=int(input())
a=input().split(' ')

def choice(a):
    x=max(a)
    a.remove(max(a))
    return x
    
alice=0
bob=0

while len(a)!=0:
    alice+=int(choice(a))
    if len(a)==0:
        break
    bob+=int(choice(a))
    
print(alice-bob)
    

# Example run
# Input:
13087
-31
# Output:
-31
n = int(input())
a_list = list(map(int, input().split()))
Alice = 0
Bob = 0
while n > 0:
    max_Alice = max(a_list)
    s = str(max_Alice)
    a_list[a_list.index(max(a_list))] = 0
    Alice += int(s)
    n -= 1
    if n == 0:
        break
    else:
        max_Bob = max(a_list)
        t = str(max_Bob)
        a_list[a_list.index(max(a_list))] = 0
        Bob += int(t)
        n -= 1
print(Alice - Bob)


# Example run
# Input:
-2147483648
16806
# Output:
0
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:
-15860207
-54634663
# Output:
-54634663
input()
l=sorted(list(map(int,input().split())),reverse=True)
print(sum(l[::2])-sum(l[1::2]))

# Example run
# Input:
XUU]r
-22775593
# Output:
-22775593
n = int(input())
a = sorted(map(int, input().split()))
print(abs(sum(a[0:][::2])-sum(a[1:][::2])))

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

a.sort(reverse=True)
al = True
al_s = 0
bo_s = 0

for i in a:
    if al:
        al_s = al_s + i
        al = False
    else:
        bo_s = bo_s + i
        al = True

print(al_s - bo_s)


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

alice = 0
bob = 0

a.sort(reverse = True)

i = 0

while True:
    if i >= n:
        break
    alice += a[i]
    i += 1
    if i >= n:
        break
    bob += a[i]
    i += 1

print(alice - bob)



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

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


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

# Example run
# Input:
42339391
-80
# Output:
-80
def intget():
    return int(input())

_n = intget()
ar = list(map(int, input().split()))
ar.sort()
ar.reverse()

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

print(alice - bob)


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

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

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

# Example run
# Input:
-73864104
56
# Output:
0
n = int(input())
a = list(map(int, input().split()))
sort_a = sorted(a, reverse=True)

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


# Example run
# Input:
7381
449660
# Output:
449660
def solve(A):
    A = sorted(A, reverse=True)
    return sum(A[::2])-sum(A[1::2])

N = int(input())

A = [int(x) for x in input().split()]
print(solve(A))


# Example run
# Input:
-330
-2503
# Output:
-2503
N = int(input())
A = list(map(int,input().split()))
SA = sorted(A,reverse=True)
ALI =0
BOB=0
for i in range(0,N,2):
    ALI += int(SA[i])
for n in range(1,N-1,2):
    BOB += int(SA[n])
ans = ALI - BOB
print(ans)

# Example run
# Input:
-1854054
68688
# Output:
0
N=int(input())
a=list(map(int,input().split()))
A=0
B=0
if N%2==0:
  for i in range(int(N/2)):
    A=A+max(a)
    a.remove(max(a))
    B=B+max(a)
    a.remove(max(a))
else:
  for i in range(int(N/2)+1):
    a.append(0)
    A=A+max(a)
    a.remove(max(a))
    B=B+max(a)
    a.remove(max(a))
  
print(A-B)

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

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

for i in range(N):
   for j in reversed(range(i+1,N)):
        #print(i,j)
        if a[j] > a[j-1]:
            temp = a[j]
            a[j] = a[j-1]
            a[j-1] = temp

Alice = 0
Bob = 0

k = 0
count =1
while k < N:
    if count % 2 == 0:
        Bob += a[k]
    else:
        Alice += a[k]
    k += 1
    count += 1

print(Alice-Bob)

# Example run
# Input:
-28977
-22775593
# Output:
0
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
for i in range(N):
  ans+=(-1)**i * A[i]
print(ans)

# Example run
# Input:
-1
734377
# Output:
0
N = int(input())
a = list(map(int, input().split()))
sorted_a = list(reversed(sorted(a)))
print(sorted_a)
alice = 0
bob = 0
for i in range(N):
    if i % 2 == 0:
        alice += sorted_a[i]
    else:
        bob += sorted_a[i]
print(alice - bob)

# Example run
# Input:
-2
669
# Output:
[669]
0
n = input()
num = 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:
)0CAqT
675805
# Output:
675805
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
print(sum(a[::2])-sum(a[1::2]))


# Example run
# Input:
41078
119781
# Output:
119781
N = int(input())
vals = list(map(int, input().split()))

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

# Example run
# Input:
-84521052
-2
# Output:
-2
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
roundnum=0
alice=0
bob=0
def game():
    global roundnum
    global alice
    global bob
    if roundnum%2==0:
        alice+=a.pop()
    else:
        bob+=a.pop()
    roundnum+=1
        
while a:
    game()
    
print(alice-bob)

# Example run
# Input:
-256478906
-8056
# Output:
-8056
# 入力受け取り
N = int(input())
Cards = list(map(int,input().split()))
# 合計値初期化
sum_A = 0
sum_B = 0
#添え字
t = 0
while not(max(Cards) == 0):
        if t % 2 == 0:
            sum_A += max(Cards)
            a = Cards.index(max(Cards))
            Cards[a] = 0
            t += 1
        else:
            sum_B += max(Cards)
            a = Cards.index(max(Cards))
            Cards[a] = 0
            t += 1

print(sum_A - sum_B)


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

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


# Example run
# Input:
-65
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:
7098909
1005028
# Output:
1005028
N = int(input())
a = sorted([int(x) for x in input().split()], reverse=True)

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

# Example run
# Input:
31499
-58743
# Output:
-58743
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 26 18:51:52 2020

@author: 藤原聖士
"""

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

list.sort(a,reverse=True)

fugou=1
count=0

for i in range(N):
    count+=a[i]*fugou
    fugou*=-1

print (count)

# Example run
# Input:
-795212538
36241
# Output:
0
N = int(input())
a = list(map(int, input().split()))
a_reverse = sorted(a, reverse=True)

# print(a_reverse)

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

print(Alice - Bob)

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


# Example run
# Input:
-1
-3439167
# Output:
-3439167
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=True)
    alice = [A[i] for i in range(N) if not i & 1]
    bob = [A[i] for i in range(N) if i & 1]

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

main()


# Example run
# Input:
-15
332
# Output:
0
N = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
res = 0
for i, x in enumerate(a):
    if i%2==0:
        res+=x
    else:
        res-=x
print(res) 

# Example run
# Input:
5101803
129445
# Output:
129445
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+=i
  else:
    y+=i
print(x-y)


# Example run
# Input:
134
-5930
# Output:
-67
N = int(input())
A_LIST = sorted(list(map(int, input().split(' '))), reverse=True)

n_a = 0
n_b = 0
for i, x in enumerate(A_LIST):
    if i % 2 == 0:
        n_a += x
    else:
        n_b += x
        
print(n_a - n_b)

# Example run
# Input:
424
-70037
# Output:
-70037
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse=True)
a = []
b = []

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

print(sum(a)-sum(b))

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

# Example run
# Input:
-5271130
19
# Output:
0
N = int(input())
card = list(map(int,input().split()))
A = 0
B = 0
card.sort(reverse = True)
while True:
    A += card[0]
    card.pop(0)
    if not card:
        break
    B += card[0]
    card.pop(0)
    if not card:
        break
print(A - B)

# Example run
# Input:
176397305
-2046600
# Output:
-2046600
n = int(input())
num = list(map(int, input().split()))
sum1 = sum2 = 0
for i in range(n):
    if i % 2 == 0:
        x = max(num)
        a = num.index(x)
        sum1 += x
        del num[a]
    else:
        y = max(num)
        b = num.index(y)
        sum2 += y
        del num[b]

print(sum1 - sum2)
 


# Example run
# Input:
-696
-2978029
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
Alice = 0
Bob = 0
for i in range(0, len(a), 2):
    Alice += a[i]
for i in range(1, len(a), 2):
    Bob += a[i]
print(Alice - Bob)

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

sorted_a = sorted(a, reverse=True)

alice = 0
bob = 0
for i in range (N):
    #Aliceのターン
    if i % 2 == 0:
        alice += sorted_a[i]
    else:
        bob += sorted_a[i]

print(alice-bob)

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

ai = input().split()

ai = list(map(int,ai))

ai.sort(reverse=True)

sum1 = 0;
sum2 = 0;

for i in range(N):
	if i%2 == 1:
		sum2+=ai[i]
	else:
		sum1 +=ai[i]

print(sum1-sum2) 

# Example run
# Input:
-4941179
-1
# Output:
0
N = int(input())
alice = 0
bob = 0
a = [int(i) for i in input().split()] 
while len(a) != 0:
    alice += max(a)
    a.remove(max(a))
    while len(a) != 0:
        bob += max(a)
        a.remove(max(a))
        break
print(alice - bob)

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

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

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

# Example run
# Input:
-14
0
# Output:
0
x = int(input())
y = [int(i) for i in input().split()]
y.sort(reverse=True)

a = 0
b = 0

for i in range(1,x+1):
  if (i % 2) != 0:
    a += y[i-1]
  else:
    b += y[i-1]

print(a-b)

# Example run
# Input:
-86
11
# Output:
0
n=int(input())
a=sorted(list(map(int,input().split())),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:
-28
-512
# Output:
0