Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
nums = [int(i) for i in input().split()]
nums.sort(reverse=True)
turn = 0
alice = 0
bob = 0
for i in nums:
    if turn % 2 == 0:
        alice = alice + i
        turn += 1
    else:
        bob = bob + i
        turn += 1
print(alice - bob)

# Example run
# Input:
-2978029
3
# Output:
3
# coding: utf-8

n = int(input())

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

a.sort(reverse = True)

#print(a)

al = sum([a[i] for i in range(0,n,2)])
bb = sum([a[i] for i in range(1,n,2)])

print(al-bb)

# Example run
# Input:
-2314351
3986
# Output:
0
def main():
    N = int(input())
    S = list(map(int, input().split()))
    S = sorted(S, reverse=True)
    a = []
    b = []

    flg = 0
    for s in S:
        if flg == 0:
            a.append(s)
            flg = 1
        else:
            b.append(s)
            flg = 0

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

if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()


# Example run
# Input:
63
-35798645
# Output:
-35798645
N = int(input())
list_a = list(map(int, input().split()))

list_a = sorted(list_a, reverse=True)

Alice = 0
Bob = 0

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

print(Alice - Bob)

# Example run
# Input:
-81521
1267176863
# Output:
1267176863
#  ABC 088 B - Card Game for Two
N = int(input())
an = list(map(int, input().split()))

Alice = []
Bob = []
while len(an) > 0:
    Alice.append(max(an))
    del an[an.index(max(an))]
    if len(an) > 0:
        Bob.append(max(an))
        del an[an.index(max(an))]
    else:
        break

k = 0
j = 0
for i in range(len(Alice)):
    k += Alice[i]
for i in range(len(Bob)):
    j += Bob[i]

print(str(k-j))

# Example run
# Input:
-5403886
3294212
# Output:
3294212
N = int(input())

a = list(map(int,input().split()))
b = sorted(a,reverse=True)
Alice =[]
Bob =[]
for i in range(N):
    if (i+1)%2 !=0:
        Alice.append(b[i])
    else:
        Bob.append(b[i])

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

# Example run
# Input:
0
-901502927
# Output:
0
n=int(input())
li=sorted(list(map(int,input().split())),reverse=True)
a=0
b=0

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

# Example run
# Input:
0
805965556
# Output:
0 0
0
n = int(input())
cardList = map(int,input().split())
cl = list(cardList)
cl.sort(reverse=True)
alice = 0
bob = 0
turn = True
for c in cl:  
  if turn:
    alice+= c
    turn = False
  else:
    bob +=c
    turn =True
    
print(alice-bob)  

# Example run
# Input:
-1005173
-60875
# Output:
-60875
N = int(input())
A = sorted(list(map(int, input().split())))
offset = True if len(A) % 2 == 0 else False
alice = sum(A[offset::2])
bob = sum(A[not offset::2])
print(alice-bob)


# Example run
# Input:
-62350830
260615611
# Output:
260615611
n = int(input())

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

a_sorted = sorted(a_list, reverse=True)
alice = sum(a_sorted[0::2])
bob = sum(a_sorted[1::2])

print(alice - bob)

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

# Example run
# Input:
F3>yV!
196831
# Output:
196831
N = int(input())
arr = [int(x) for x in input().split()]

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


# Example run
# Input:
-1
-3439167
# Output:
-3439167
n = int(input())
a = sorted(list(map(int,input().split())), reverse = True)

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

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

# Example run
# Input:
0
16
# 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:
713362851
133233772
# Output:
133233772
n = int(input())
a = list(map(int, input().split()))
al, bo = [], []
for i in range(n):
	if i % 2 == 0:
		al.append(max(a))
		a.remove(max(a))
	else:
		bo.append(max(a))
		a.remove(max(a))
print(sum(al)-sum(bo))


# Example run
# Input:
-3550
-11385106
# Output:
0
N = int(input())
cards = list(map(int, input().split(" ")))

cards.sort()
cards.reverse()

p1 = 0
p2 = 0

for i in range(N):
    if i%2==0:
        p1+=cards[i]
    else:
        p2 += cards[i]

print(p1-p2)

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

total=0

for i in range(len(a)):
    if i % 2 == 0 :
        total+=max(a)
        index=a.index(max(a))
        a[index]=0
    else:
        total-=max(a)
        index=a.index(max(a))
        a[index]=0

print(total)

# Example run
# Input:
0
-6956
# Output:
-6956
N = int(input())
data = list(map(int, input().split(' ')))
data.sort(reverse = True)
score = 0
is_Alices_turn = True

for data in data:
    if is_Alices_turn:
        score += data
    else:
        score -= data
    is_Alices_turn = not is_Alices_turn

print(score)

# Example run
# Input:
27004354
-662003357
# Output:
-662003357
N=int(input())
list_a=list(map(int, input().split()))

list_a.sort(reverse=True)

sam_a=0
sam_b=0

for i in range(N):
    if i%2 == 0:
        sam_a+=list_a[i]
    else:
        sam_b+=list_a[i]

print(sam_a-sam_b)

# Example run
# Input:
-10492971
61186
# Output:
0
n=int(input())
s=list(map(int,input().split()))
s.sort()
j=A=B=0
for i in s[::-1]:
    if j==0:A+=i
    else:B+=i
    j=1-j
print(A-B)

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

# Example run
# Input:
rH!o
-9
# Output:
9
n=int(input())
a=list(map(int,input().split()))
alice=0
bob=0
a.sort(reverse=True)
for i in range(n):
    if i%2 == 0:
        alice+=a[i]
    else:
        bob+=a[i]
print(alice-bob)       

# Example run
# Input:
-3753932
42339391
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
b = a[::2]
c = a[1::2]
print(sum(b)-sum(c))

# Example run
# Input:
5831819
-812896393
# Output:
-812896393
n=int(input())
A=[int(x) for x in input().split()]
B=sorted(A)
print(B[-1])
Alice=[]
Bob=[]
while len(B)!=0 and len(B)!=1:
  Alice.append(B[-1])
  B.pop()
  Bob.append(B[-1])
  B.pop()
  print(B)
  print(len(B))
if len(B)==1:
  Alice.append(B[0])
  B.pop()
print(sum(Alice)-sum(Bob))


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

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

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

print(A-B)

# Example run
# Input:
-31081879
2
# Output:
0
N = int(input())
A = [int(i) for i in input().split()]

A.sort(reverse=True)

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



# Example run
# Input:
3185105
629110165
# Output:
629110165
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

Alice = 0
Bob = 0

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

print(Alice - Bob)

# Example run
# Input:
141725276
-109089799
# Output:
-109089799
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
alice=sum(a[::2])
Bob=sum(a[1::2])
print(alice-Bob)

# Example run
# Input:
-139093888
1593280440
# Output:
1593280440
n = int(input())
a = [int(x) for x in input().split()]

a.sort()
print(sum(a[n-1::-2]) - sum(a[n-2::-2]))

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

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

print(ans)


# Example run
# Input:
-227062494
655252
# Output:
0
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse = True)
res = 0
for i in range(n):
  if i % 2 == 0:
    res += a[i]
  else:
    res -= a[i]
print(res)

# Example run
# Input:
-4953150
3320259
# Output:
0
#N,K = map(str,input().split())
N = int(input())
#K = int(input())
X = list(map(int,input().split()))
Y=X.copy()
A=[]
B=[]
while Y:
    a=max(Y)
    A.append(a)
    Y.remove(a)
    if not Y:
        break
    b=max(Y)
    B.append(b)
    Y.remove(b)
print(sum(A)-sum(B))


# Example run
# Input:
-5
-112
# Output:
-112
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
al=[a[2*i] for i in range(n//2)]
bo=[a[2*i+1] for i in range(n//2)]
if n%2!=0:
  al.append(a[-1])
print(sum(al)-sum(bo))

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

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

# Example run
# Input:
~_p|DP\
-29588
# Output:
-29588
N = int(input())
card = list(map(int,input().split()))

card.sort(reverse=True)

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

print(alice - bob)

# Example run
# Input:
30315
-65
# Output:
-65
#Beginner 088 B-Card Game for Two

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

for t in range(N):
    for i in range(N-t):
        if A[t]<A[t+i]:
            b=A[t+i]
            A[t+i]=A[t]
            A[t]=b
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:
-60
-2147483648
# 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:
-7617381
-568126729
# Output:
-568126729
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

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

# Example run
# Input:
-6
30
# Output:
30
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a, reverse=True)
    alice = 0
    bob = 0
    for i in range(n):
        if i % 2 == 0:
            alice += a_sort[i]
        else:
            bob += a_sort[i]
    res = alice - bob
    print(res)
if __name__ == '__main__':
    main()

# Example run
# Input:
0
-84521052
# Output:
0
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:
-87
141725276
# Output:
141725276
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:
17906335
5182
# Output:
5182
N = int(input())
n = map(int, input().split())
an = sorted(n, reverse=True)
i = 0
A = 0
B = 0
while i != N:
  A += an[i]
  i += 1
  if i != N:
    B += an[i]
    i += 1
print(A - B)

# Example run
# Input:
0
-11989124
# Output:
0
N = int(input())
a = list(map(int, input().split()))
A_total = 0
B_total = 0
A_current = 0
B_current = 0
count = 0
while not len(a) == 0:
  if count%2 == 0:
    A_current = max(a)
    a.remove(A_current)
    A_total += A_current
    count += 1
  else:
    B_current = max(a)
    a.remove(B_current)
    B_total += B_current
    count += 1

print(A_total - B_total)

# Example run
# Input:
-318594
-13
# Output:
-13
n = int(input())
num_list = list(map(int, input().split()))
num_list.sort(reverse=True)
result = 0
for i in range(0, len(num_list), 2):
    result += num_list[i]

for i in range(1, len(num_list), 2):
    result -= num_list[i]

print(result)

# Example run
# Input:
-7038374
-6
# Output:
-6
n = int(input())

a = [0]*n


a = input().split()
  
b = [int(s) for s in a]

alice = 0
bob = 0
m = 0

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

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

alice = 0
bob = 0
count = 1
while(count <= n):
    alice += max(a)
    index = a.index(max(a))
    del a[index]
    count += 1
    if(len(a) > 0):
        bob += max(a)
        index = a.index(max(a))
        del a[index]
        count += 1
    
print(alice - bob)


# Example run
# Input:
-16
5215966
# Output:
0
#coding=utf-8
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:
-194
-122062265
# Output:
-122062265
N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
a.reverse()
Alice = 0
Bob = 0
a.append(0)
a.append(0)

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


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

# Example run
# Input:
9\60Qh=t8
0
# Output:
0
n = input()
num = [int(x) for x in input().split()]
num.sort()
num.reverse()

Bob=Alice = 0
loop=0

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

# Example run
# Input:
`WyDw
6462056
# Output:
6462056
n = int(input())
l = list(map(int, input().split()))
alice = 0
bob = 0
l.sort(reverse= True)
while len(l) > 0:
    alice += l.pop(0)
    if len(l) == 0:
        break
    bob += l.pop(0)
print(alice - bob)

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

a.sort(reverse=True)

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

for i in range(0,n,2):
  r += a[i]
  r -= a[i+1]

print(r)

# Example run
# Input:
-989028
54353
# Output:
0
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
alice=sum(b[::2])
Bob=sum(b[1::2])
print(alice-Bob)

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

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

A = 0
B = 0
i = 0
while(True):
 A += a[i]
 i += 1
 if i==n: break
 B += a[i]
 i += 1
 if i==n: break

print(A-B)

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

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

print(alice - sum(a) + alice)


# Example run
# Input:
-3550
-11385106
# Output:
11385106
a=int(input())
li = list(map(int,input().split()))

sortedList = sorted(li, reverse=True)
print(sortedList)

alice = 0
bob = 0
turn = 1

while(len(sortedList)):
  if turn % 2 == 1:
    alice += sortedList.pop(0)
  else:
    bob += sortedList.pop(0)
  
  turn += 1

print(alice - bob)

# Example run
# Input:
3280
32
# Output:
[32]
32
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)

diff = 0

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

print(diff)


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

a = list(int(i) for i in input().split() )

a.sort() #リストaを昇順にソート

i = Alice = Bob = 0

while len(a) >= 1:
	if i % 2 == 0:
		Alice += a.pop(len(a)-1) #リストaの末尾の値を加えて、リストから削除
	elif i % 2 != 0:
		Bob += a.pop(len(a)-1) #リストaの末尾の値を加えて、リストから削除

	i += 1


print(Alice - Bob)

# Example run
# Input:
4
4
# Output:
4
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
x = y = 0
for i, j in enumerate(a):
    if i%2 == 0:
        x += j
    else:
        y += j
print(x - y)

# Example run
# Input:
54
-86
# Output:
-86
N = int(input())

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

a = b = 0
for i,v in enumerate(src):
    if i%2 == 0:
        a += v
    else:
        b += v
print(a - b)


# Example run
# Input:
5771
1038302991
# Output:
1038302991
N = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)

Alice = 0
Bob = 0

print(a_list)

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

print(Alice-Bob)


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

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

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

alice = []
bob = []


while len(a) > 0:
  alice.append(max(a))
  a.remove(max(a))
  if len(a) > 0:
    bob.append(max(a))
    a.remove(max(a))
  else:
    break
    
  
print(sum(alice)-sum(bob))

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

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

a_list = sorted(a_list, reverse = True)

# print(a_list)

Alice_Score = 0
Bob_Score = 0

for i in range(n):

    # 奇数(1, 3, 5…)枚目はAliceのターン
    if i % 2 == 0 :
        Alice_Score = Alice_Score + a_list[i]
    else :
        Bob_Score = Bob_Score + a_list[i]

ans = Alice_Score - Bob_Score

print(ans)

# Example run
# Input:
-252699780
988493674
# Output:
0
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
L = 0

for i in range(len(A)):
     L += ((-1)**i)*A[i]

print(L)

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


# Example run
# Input:
-55768
55
# Output:
55
def searchMaxIndex(arr):
    if len(arr) == 0:
        return -1

    result = 0
    for i in range(len(arr)):
        if arr[i] > arr[result]:
            result = i

    return result

def pullValueBiIndex(arr, index):
    result = arr[index]
    arr.pop(index)
    return result

card_count = int(input())
cards = input()
cards = [int(value) for value in cards.split(' ')]

alice = 0
bob = 0

while len(cards) > 0:
    index = searchMaxIndex(cards)
    alice += pullValueBiIndex(cards, index)

    index = searchMaxIndex(cards)
    if index == -1:
        break
    bob += pullValueBiIndex(cards, index)

print(alice - bob)


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

# Example run
# Input:
oBt
-28
# Output:
-28
n = int(input())
a = sorted([int(i) for i in 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:
-901502927
-60
# Output:
0
N = int(input())
A = list(map(int, input().split()))

# A = [20,18,2,18]
Alice = 0
Bob = 0

A.sort(reverse=True)

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

print(Alice-Bob)

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

a.sort(reverse=True)

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


# Example run
# Input:
21
42
# Output:
42
n = int(input())
a = sorted([int(item) for item in input().split()], reverse=True)

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

print(alice - bob)

# Example run
# Input:
-264371717
10366
# Output:
10366
N = int(input())
A = [int(i) for i in input().split()]

A_sorted = sorted(A, reverse=True)
print(A_sorted)

Alice_point = 0; Bob_point = 0

for i in range(N):
    
    if i % 2 == 0:
        print("Alice=",i)
        Alice_point += A_sorted[i]
    else:
        print("Bob=",i)
        Bob_point += A_sorted[i]
    
ans = Alice_point - Bob_point

print(ans)

# Example run
# Input:
-6163826
139893
# Output:
[139893]
0
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:
-14
948
# Output:
948
def resolve():
    n = int(input())
    al = list(map(int, input().split()))
    al = sorted(al, reverse=True)
    an = 0
    bn = 0
    for i in range(n):
        if i % 2 == 0:
            an += al[i]
        elif i % 2 == 1:
            bn += al[i]
    print(an - bn)
resolve()

# Example run
# Input:
-58
-282811832
# Output:
0
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:
-6865417
-48
# Output:
0
n = int(input())
a = input().split()
a = [int(i) for i in a]
a = list(reversed(sorted(a)))

alice = sum([int(a[i]) for i in range(0, n, 2)])
bob = sum([int(a[i]) for i in range(1, n, 2)])

print(alice-bob)

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

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

print(ans)


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

# Example run
# Input:
-166
2
# Output:
0
N=int(input())
A=0
B=0
for idx, a in enumerate(sorted(map(int, input().split()),reverse=True)):
    if (idx+1)%2:
        A+=a
    else:
        B+=a
print(A-B)


# Example run
# Input:
-117864
-38181262
# Output:
-38181262
N = int(input())
Ai = input().split()
Ai = [int(n) for n in Ai]
Ai = sorted(Ai, reverse=True)
Alice = 0
Bob = 0
for i in range(N):
  if i % 2 == 0:
    Alice += Ai[i]
  else:
    Bob += Ai[i]
print(Alice - Bob)

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

# Example run
# Input:
-124978655
-23909
# Output:
-23909
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n%2 == 0:
    alice = sum(a[1::2])
    bob = sum(a[::2])
else:
    alice = sum(a[::2])
    bob = sum(a[1::2])
print(alice-bob)

# Example run
# Input:
-46849
-7
# Output:
-7
N = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
A, B = 0, 0
for i in range(N):
    if i % 2 == 0:
        A += a[i]
    else:
        B += a[i]

print(A - B)


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

Gap = sum(A)
n = N//2

if N!=1:
    for i in range(n):
       Gap += -2*A[1+2*i]

print(Gap)

# Example run
# Input:
-21
6534
# Output:
6534
n = int(input())
x = list(map(int, input().split()))

a = 0
b = 0
x = sorted(x)

for i in range(n):
    if i % 2 == 0:
        a += x.pop()
    else:
        b += x.pop()

print(a-b)

# Example run
# Input:
-124978655
-23909
# Output:
0
N = int(input())
card = [int(i) for i in input().split()]

Alice = 0
Bob = 0
flag = True

card.sort(reverse = True)
for i in card:
  if flag == True:
    Alice += i
    flag = False
  else:
    Bob += i
    flag = True
  
print(Alice - Bob)  

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

Card_n.sort()

A_n = []
B_n = []

for i in range(len(Card_n)):
    if not i%2 == 0:
        A_n.append(Card_n.pop())
    else:
        B_n.append(Card_n.pop())

#print(A_n)
#print(B_n)
print(abs(sum(A_n) - sum(B_n)))


# Example run
# Input:
92
-3463607
# Output:
3463607
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    a_sorted = sorted(a, reverse=True)

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

    print(alice - bob)


# Example run
# Input:
-927746
-4
# Output:
-4
n = int(input())
a = [int(i) for i in 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:
-40
-18579092
# Output:
0
n = input()
a = map(int, input().split())
new_list = sorted(a, reverse=True)
sum = 0
for i,n in enumerate(new_list):
        if i % 2 == 0:
                sum += n
        else:
                sum -= n
print(sum)

# Example run
# Input:
pjLk(&0
-2552
# Output:
-2552