Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)

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


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

# Example run
# Input:
1973033
-264371717
# Output:
-264371717
n = int(input())
num_list = list(map(int, input().split(' ')))
num_list.sort(reverse = True)

alice = 0
bob = 0

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

print(alice - bob)


# Example run
# Input:
-160045822
155287
# Output:
155287
n = int(input())
cards = list(map(int, input().split()))

alice = 0
bob = 0
for i in range(n):
    if len(cards) == 0:
        break
    card = max(cards)
    cards.remove(card)
    if i % 2 == 0:
        alice += card
    else:
        bob += card

print(alice - bob)

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

x,y = 0,0

for i in range(0,n,2):
    x += b[i]
for i in range(1,n,2):
    y += b[i]

print(x-y)


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

# Example run
# Input:
-24
3469
# Output:
0
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    A=LIST()
    A=sorted(A,reverse=True)
    al=len(A)
    alice=0
    bob=0
    for i in range(al//2):
        alice+=A[2*i]
        bob+=A[2*i+1]
    if al%2==1:
        alice+=A[-1]
    print(alice-bob)    
if __name__ == '__main__':
    do()

# Example run
# Input:
-37
1
# Output:
1
n = int(input())
a_list = [int(i) for i in input().split()]

turn = 0
alice = 0
bob = 0

for i in range(n):
    turn += 1
    if turn%2 != 0:
        alice += max(a_list)
        
    else:
        bob += max(a_list)
    a_list.remove(max(a_list))

print(alice - bob)


# Example run
# Input:
-330
-2503
# 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:
6395997
20415230
# Output:
20415230
n = int(input())
c = list(map(int,input().split()))
a,b = 0,0

c.sort(reverse=True)
for i,j in enumerate(c):
  if i % 2 == 0:
    a += j
  else:
    b += j

print(a-b)

# Example run
# Input:
0
1418198351
# Output:
1418198351
n = int(input())

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

srt_as = sorted(As, reverse=True)

Alice = 0
Bob = 0

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

print(Alice-Bob)

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


# Example run
# Input:
-14081225
49638
# 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:
7842
-19797306
# Output:
-19797306
n = int(input())

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

a_point = 0
b_point = 0
for i in range(len(arr)):
    if i % 2 == 0:
        a_point += arr[i]
    else:
        b_point += arr[i]

print(a_point - b_point)

# Example run
# Input:
-12142
51
# Output:
51
def main():
    N = int(input())
    A = sorted([int(a) for a in input().split()], reverse = True)
    Alice = 0
    for i in range(N):
        if i % 2 == 0:
            Alice += A[i]
    return 2*Alice - sum(A)

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


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

alice = 0
bob = 0
count = 0

for i in range(0, len(a)):
	if count % 2 == 0:
		alice += a.pop(0)
	elif count % 2 == 1:
		bob += a.pop(0)
	count += 1

print(alice - bob)

# Example run
# Input:
65153902
20794
# Output:
20794
N = int(input())
A = list(map(int,input().split()))
p1, p2 = 0, 0
for i in range(N):
	max_A = max(A)
	if i % 2 == 0:
		p1 += max_A
	else:
		p2 += max_A
	A.remove(max_A)
print(p1 - p2)

# Example run
# Input:
0
8131
# Output:
0
tmp = int(input())
num = sorted(list(map(int,input().split())),reverse=True)
bob = 0
mary = 0
for i in range(tmp):
  if i%2 == 0:
    mary += num[i]
  else:
    bob += num[i]
print(str(mary -bob))

# Example run
# Input:
-5930
-31
# Output:
0
input()
l=sorted([int(_) for _ in input().split()])[::-1]
print(sum(l[::2])-sum(l[1::2]))

# Example run
# Input:
NAw}[:jG
1186387
# Output:
1186387
card_num = int(input())
card_list = input().split()
card_list = list(map(int, card_list))
# print(card_list)
card_list.sort(reverse = True)
# print(card_list)

Alice = 0
Bob = 0
for i, j in enumerate(card_list):
    if (i + 1) % 2 == 0:
        Bob += j
    else:
        Alice += j

# print(Alice ,Bob)
diff = abs(Alice - Bob)
print(diff)


# Example run
# Input:
-252699780
988493674
# Output:
988493674
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:
-5271130
19
# Output:
0
n=int(input())
a=sorted(list(map(int,input().split())),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:
-39
2569
# Output:
0
n = int(input())
a = list(map(int, input().split()))

a.sort()

num = len(a)-1
alice, bob = 0, 0

while num >= 0:
  alice += a[num]
  num -= 1
  if num < 0:
    break
  bob += a[num]
  num -= 1
  
print(alice-bob)

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

A = 0
B = 0

for i in range(1, N+1):
    if i % 2 == 1:
        A += card[i-1]
    else:
        B += card[i-1]

print(A -B)

# Example run
# Input:
-17
-153163
# Output:
0
N = int(input())
kList = list(map(int, input().split()))
aTotal = 0
bTotal = 0
kList.sort(reverse=True)

for i in range(N):
    if i % 2 == 0:
        aTotal += kList[i]
    else:
        bTotal += kList[i]

print(aTotal - bTotal)

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

#aを大きい順にならべかえる。
a.sort(reverse=True)

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


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

# Example run
# Input:
-23909
-68
# Output:
-68
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:
-450
139
# Output:
0
N = int(input())
a = map(int,input().split())
A = list(a)
A.sort(reverse = True)
ans = 0
_ans = 0
for i in range(N):
  _i = i * 2
  if _i <= N-1 :
    ans += A[_i]
for _q in range(N):
  _ii = _q * 2 +1    
  if _ii <= N-1:
    _ans -= A[_ii]
print(ans + _ans)



# Example run
# Input:
-135
-117864
# Output:
0
N = int(input())
list_A = list(input().split())
list_a = list(map(int, list_A))

Alice = 0
Bob = 0

if N % 2 == 0:
    for _ in range(int(N / 2)):
        Max = max(list_a)
        Alice += Max
        list_a.remove(Max)

        Max = max(list_a)
        Bob += Max
        list_a.remove(Max)

else:
    for _ in range(int((N - 1) / 2)):
        Max = max(list_a)
        Alice += Max
        list_a.remove(Max)

        Max = max(list_a)
        Bob += Max
        list_a.remove(Max)

    Alice += list_a[0]

print(Alice - Bob)

# Example run
# Input:
-28
-2
# 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:
223540
-3022
# Output:
-3022
N = int(input())
a = list(map(int, input().split()))
 
a.sort(reverse=True)
 
print(sum(a[::2])-sum(a[1::2]))

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

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

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

# Example run
# Input:
21
0
# Output:
0
n = int(input())
a = list(map(int,input().split()))
sum_ = sum(a)
sorted(a)
alice = 0
for i in range(len(a)):
    if i % 2 == 0:
        alice += a[-i-1]
print(2*alice - sum_)
#print(alice)

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

# Example run
# Input:
-80
19
# Output:
0
n = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
c = 0
for i in range(n):
  c += ((-1)**i)*A[i]
print(c)


# Example run
# Input:
-156
2371602
# Output:
0
N = int(input())
score = list(map(int, input().split()))
score.sort()
score.reverse()
a = []
b = []
for i in range(N):
  if(i % 2 == 1):
    a.append(score[i])
  else:
    b.append(score[i])
             
print(sum(b) - sum(a))
  

# Example run
# Input:
-194151326
1
# Output:
0
N = int(input())
A_list = list(map(int, input().split()))
A_list= sorted(A_list)[::-1]

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

# Example run
# Input:
-4705
-2410709
# Output:
-2410709
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
alice=A[::2]
alicepoint=sum(alice)
bobpoint=sum(A)-alicepoint
print(alicepoint-bobpoint)

# Example run
# Input:
2116
-579377
# Output:
-579377
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:
7883823
0
# Output:
0
n=int(input())
li=list(map(int,input().split()))
li.sort
a=[]
b=[]
for i in range(n):
  if n%2==1:
    if i%2==0:
      a.append(li[i])
    else:
      b.append(li[i])
  else:
    if i%2==0:
      b.append(li[i])
    else:
      a.append(li[i])
print(sum(a)-sum(b))

# Example run
# Input:
-6163826
139893
# 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:
-17
-3
# Output:
0
N = int(input())
lis = input().split()
num_lis = [int(x) for x in lis]

def Turn(AB, l):
    m = max(l)
    AB += m
    l.remove(m)

    return (AB, l)

Alice = 0
Bob = 0

while num_lis:
    Alice, num_lis = Turn(Alice, num_lis)
    
    if num_lis:
        Bob, num_lis = Turn(Bob, num_lis)
    
print(Alice - Bob)

# Example run
# Input:
-1
-3439167
# Output:
-3439167
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:
-2239572
-31
# Output:
-31
N = int(input())
str_list = input().split()
num_list = [int(a) for a in str_list]
Alice = 0
Bob = 0
count = 1
while num_list:
    temp = max(num_list)
    if count % 2 != 0:
        Alice += temp
    else:
        Bob += temp
    num_list.remove(temp)
    count += 1

print(Alice - Bob)

# Example run
# Input:
2072477
30125521
# Output:
30125521
N = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)

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

print(A - B)

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

a.sort()
a.reverse()

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

print(A-B)

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

sortedList = sorted(a,reverse=True)



ansList = [sortedList[i] if i%2==0 else -sortedList[i] 
           for i in range(n)]
ans = sum(ansList)

print(ans)

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

A = sorted(A, reverse=True)
print(sum(A[0::2]) - sum(A[1::2]))

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

alicePointList = a[::2]
bobPointList = a[1::2]

print(sum(alicePointList)-sum(bobPointList))

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


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

# Example run
# Input:
-10841372
-2552
# 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:
150
-18771736
# Output:
-18771736
input()
A=sorted(map(int,input().split()))
print(sum(A[::-2])-sum(A[-2::-2]))

# Example run
# Input:
tQHWPR
1748
# Output:
1748
n=int(input())
a=sorted(list(map(int,input().split())))[::-1]

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

# Example run
# Input:
-24
-1477
# Output:
0
n = input()
aa = list(map(int, input().split()))
aa.sort(reverse=True)
al = sum(aa[::2])
bb = sum(aa[1::2])
print(al - bb)


# Example run
# Input:
8u=^Atb
3
# Output:
3
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a, b, turn = 0, 0, 1
while len(A) != 0:
    if turn & 1:
        a += A.pop()
    else:
        b += A.pop()
    turn += 1
print(a-b)

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

print(alice-bob)

# Example run
# Input:
-450
139
# Output:
139
n = int(input())

l = sorted([int(i) for i in input().split()],reverse = True)

alice = [i for idx,i in enumerate(l) if idx % 2 == 0]
bob = [i for idx,i in enumerate(l) if idx % 2 == 1]

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

    

# Example run
# Input:
211
-6815
# Output:
-6815
N = int(input())
A = list(map(int, input().split()))
Alice = 0
Bob = 0
A.sort(reverse=True)
while len(A) > 0:
    Alice += A.pop(0)
    if len(A) > 0:
        Bob += A.pop(0)
print(Alice - Bob)

# Example run
# Input:
0
10
# Output:
10
import math
from collections import deque
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
a = readInts()
a.sort()
if len(a)%2:
	a.append(0)
alice = 0
bob = 0
for i in range(0,len(a),2):
	alice+=a[i]
	bob+=a[i+1]
print(alice-bob)

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

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


# Example run
# Input:
$hF;EkO
10040638
# Output:
10040638
N = int(input())
a = list(map(int, input().split()))

Alice = []
Bob = []
a.sort()
a.reverse()

for x in range(N):
    if x % 2 == 0:
        Alice.append(a[x])
    else:
        Bob.append(a[x])

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

# Example run
# Input:
-70037
-1002
# Output:
0
def main():
    N = int(input())
    A = [int(a) for a in 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)
main()

# Example run
# Input:
253629
361083
# Output:
361083
N = int(input())
A = list(map(int,input().split()))
A.sort()
alice_score = []
bob_score = []
for i in range(N):
    if i % 2 == 0:
        alice_score.append(A.pop())
    else:
        bob_score.append(A.pop())
print(sum(alice_score) - sum(bob_score))

# Example run
# Input:
-2
-497
# Output:
0
N=int(input())
List=list(map(int,input().split()))
List.sort(key=lambda x:x)
n=0
Alice=0
Bob=0
while n<=N-1:
  if n%2==0:
    Alice+=List[N-1-n]
  else     :
    Bob+=List[N-1-n]
  n+=1
print(Alice-Bob)

# Example run
# Input:
-2
7883823
# Output:
0
N = input()
a = list(map(int, input().split()))
a = sorted(a, reverse = True)
Alist = []
Blist = []
for i in range(len(a)):
    if i % 2 == 0:
        Alist.append(a[i])
    else:
        Blist.append(a[i])
print(sum(Alist) - sum(Blist))

# Example run
# Input:
6ej=k^S/8
981571
# Output:
981571
# -*- coding: utf-8 -*-

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

_as.sort(reverse=True)

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

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


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

# Example run
# Input:
S43brt#
104248
# Output:
104248
#088 B
N =int(input())

A=list(map(int,input().split()))
A.sort(reverse=True)
Alice=0
Bob =0
for j,i in enumerate(A):
    if j %2==0:
        Alice+=i
    else:
        Bob+=i
print(Alice-Bob)

# Example run
# Input:
-22588477
11
# Output:
11
N = int(input())
a = list(map(int, input().split(' ')))

aSorted = sorted(a, reverse=True)

alice = 0
bob = 0

for i in range(N):
    # アリスのターン
    if i % 2 == 0:
        alice += aSorted[i]
    # ボブのターン
    else:
        bob += aSorted[i]

print(alice - bob)


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

a = sorted(list(map(int,input().split())),reverse=True)

Alice = sum([a[i] for i in range(N) if i%2 == 0])
Bob= sum([a[i] for i in range(N) if i%2 == 1])
print(Alice-Bob)

# Example run
# Input:
-90312
-12211339
# 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:
-21
6534
# Output:
6534
N=int(input())
list1=sorted(list(map(int,input().split())),reverse=True)

s=0
i=0

for i in range(N):

    s+=list1[i]*(-1)**i
    i+=1

print(s)

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

a.sort()

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

print(Alice - Bob)

# Example run
# Input:
-877447
8312590
# Output:
8312590
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
Alice = 0
for i in range(0, n, 2):
    print(i)
    Alice += l[i]
Bob = sum(l) - Alice
print(abs(Bob - Alice))


# Example run
# Input:
-31
-58867430
# Output:
58867430
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:
.dV#s;5
647746204
# Output:
647746204
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
pt=0
for i in a[::2]:
  pt+=i
for i in a[1::2]:
  pt-=i
print(pt)

# Example run
# Input:
3320259
-2147483648
# Output:
-2147483648
N = int(input())
a = list(map(int, input().split()))
alice, bob = 0,0
for i in range(int(N/2)):
    alice += max(a)
    a.remove(max(a))
    bob += max(a)
    a.remove(max(a))
if(N%2)==1:
    alice+=max(a)
print(alice-bob)

# Example run
# Input:
-39355
1
# Output:
1
N = input()
A = list(input().split())
A = list(map(int,A))
A = sorted(A,reverse = True)
a = 0
b = 0
try :
  while len(A) != 0 :
    a += A.pop(0)
    b += A.pop(0)
  print(a-b)
except IndexError :
  print(a-b)



# Example run
# Input:
CNR'(
236801619
# Output:
236801619
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:
-24166826
-802253
# 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:
-52564348
-7737
# Output:
0
n = int(input())
a = sorted(list(map(int,input().split())))
x = [0,0]
for i in range(n):
    x[i%2]+=a[i]
print(abs(x[1]-x[0]))

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

# Example run
# Input:
-11392175
-9
# Output:
-9
icase=0
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    asum=0
    for i in range(0,n,2):
        asum=asum+a[i]
    print(2*asum-sum(a))

# Example run
# Input:
-499948
-21000
# Output:
21000
##### 解けた #####

N=int(input())
A=list(map(int,input().split(" ")))
As=list(reversed(sorted(A)))
print(sum(As[::2])-sum(As[1::2]))

# Example run
# Input:
-55768
55
# Output:
55
n = int(input())

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

a.sort(reverse=True)

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


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

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


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

a.sort(reverse=True)

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

print(ans - ans2)

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

# Example run
# Input:
10
6252
# Output:
6252