Problem:
 Score: 200 points    Problem Statement  We have N cards. A number a_i is written on the i -th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.      Constraints   N is an integer between 1 and 100 (inclusive).  a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).         Input  Input is given from Standard Input in the following format:  N  a_1  a_2  a_3  ...  a_N       Output  Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.        Sample Input 1 2
3 1      Sample Output 1 2  First, Alice will take the card with 3 . Then, Bob will take the card with 1 .
The difference of their scores will be 3 - 1 = 2 .       Sample Input 2 3
2 7 4      Sample Output 2 5  First, Alice will take the card with 7 . Then, Bob will take the card with 4 . Lastly, Alice will take the card with 2 . The difference of their scores will be 7 - 4 + 2 = 5 . The difference of their scores will be 3 - 1 = 2 .       Sample Input 3 4
20 18 2 18      Sample Output 3 18

Solution (Python):
n=int(input())
n_list=list(map(int,input().split()))
alice=[]
bob=[]
while(n_list!=[]):
    a=max(n_list)
    alice.append(a)
    n_list.remove(a)
    if(n_list==[]):
        break
    b=max(n_list)
    bob.append(b)
    n_list.remove(b)
print(sum(alice)-sum(bob))

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))

alice=0
bob=0

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
Alice = 0
Bob = 0
while 1:
    try:
        Alice += A.pop(-1)
    except IndexError:
        break
    try:
        Bob += A.pop(-1)
    except IndexError:
        break
print(Alice-Bob)

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

a.sort(reverse=True)

ans = 0

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

  
print(ans)

Solution (Python):
from typing import List


def answer(n: int, a: List[int]) -> int:
    alice = 0
    bob = 0

    a.sort(reverse=True)
    for i in range(0, len(a), 2):
        alice += a[i]
    for j in range(1, len(a), 2):
        bob += a[j]

    return abs(alice - bob)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    print(answer(n,a))


if __name__ == '__main__':
    main()

Solution (Python):
def main():

    n = int(input())
    cards = list(map(int, input().split()))
    cards.sort(reverse=True)
    alice, bob = 0, 0
    if n % 2 == 0:
        for i in range(int(n / 2)):
            alice += cards[2 * i]
            bob += cards[2 * i + 1]
    else:
        for j in range(int(n / 2)):
            alice += cards[2 * j]
            bob += cards[2 * j + 1]
        alice += cards[n - 1]
    ans = alice - bob
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
def solve1(n, lst):
    alice, bob = 0, 0

    
    

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

    return alice - bob


n = int(input())
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
print(solve1(n, a))

Solution (Python):
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)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
alice = 0
bob = 0
for i in range(N) :
    if i%2 == 0 : 
        alice += a[i]
    elif i%2 == 1 :
        bob += a[i]
print(alice-bob)

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

a.sort(reverse=True)
alice=0
bob=0
tf=True
for i in a:
    if tf:
        alice+=i
    else:
        bob+=i
    tf=not tf
print(alice-bob)

Solution (Python):
n = int(input())
a=list(map(int, input().split()))
a.sort()
A = []
B = []
for i in range(1,n+1):
    if i % 2 != 0:
        A.append(a[-i])
    else:
        B.append(a[-i])
print(sum(A) - sum(B))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

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

diff = A - B
print(diff)

Solution (Python):
n=int(input())
x = [int(i) for i in input().split()]
xx = sorted(x)
ans=0
aaa=0
if n%2==0:
  for i in range(n//2):
    ans+=xx[i*2+1]-xx[i*2]
  print(ans)
else:
  for i in range(n//2):
    ans+=xx[i*2+1]-xx[i*2]
  aaa=xx[n-1]-ans
  print(aaa)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(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)

Solution (Python):
N = int(input())
lst = input().split()

for i in range(N):
   lst[i] = int(lst[i])
lst.sort(reverse=True)

Alice = 0
Bob = 0

for i in range(N // 2):
   Alice += lst[2 * i]
   Bob += lst[(2 * i) + 1]

if N % 2 == 1:
   Alice += lst[-1]

print(Alice - Bob)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = 0
for num in range(N):
  if num % 2 == 0:
    ans += a[num]
  else:
    ans -= a[num]
print(ans)

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

a.sort()
a.reverse()

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

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

bob=sum(a)-alice
print(alice-bob)

Solution (Python):
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)

Solution (Python):
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
a = LI()








a.sort(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)

Solution (Python):
N=int(input())
card_list=list(map(int,input().split()))





card_list.sort(reverse=True)


card_list_Alice=card_list[::2]

Alice_score=sum(card_list_Alice)

Bob_score=sum(card_list)-Alice_score




print(Alice_score-Bob_score)

Solution (Python):
n = int(input())
data = list(map(int,input().split()))
data.sort(reverse = True)
print(sum(data[::2]) - sum(data[1::2]))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice, Bob = 0, 0

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

Solution (Python):
n = int(input())
i = list(map(int, input().split()))
i.sort(reverse=True)
print(sum(i[0::2])-sum(i[1::2]))

Solution (Python):
n = input()
a = sorted(list(map(int,input().split())),reverse=True)

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

Solution (Python):
with open(0) as f:
    N, *A = map(int, f.read().split())
A.sort(reverse=True)
Alice = sum(A[::2])
Bob = sum(A[1::2])
print(Alice - Bob)

Solution (Python):
N = int(input())

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

Alice = 0
Bob = 0

while len(A) != 0:
    Alice += max(A)
    A.remove(max(A))
    if len(A) == 0:
        break
    Bob += max(A)
    A.remove(max(A))
    if len(A) == 0:
        break

print(Alice-Bob)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
Alice = sum(a[::2])
Bob = sum(a[1::2])
print(Alice-Bob)

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

def sort_reverse(n):
    n.sort(reverse=True)
    return n

N_Even = list(range(0, N, 2))
N_Odd = list(range(1, N, 2))
a1 = sort_reverse(a)
sum1 = 0
sum2 = 0

for i in N_Even:
    sum1 += a1[i]
for j in N_Odd:
    sum2 += a1[j]

print(sum1 - sum2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0

a_sort = sorted(a, reverse=True)

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

print(alice-bob)

Solution (Python):
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)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())),reverse = True)
Alice = 0
Bob = 0
count = 0

while True:
    Alice += a[count]
    count += 1
    if count == n:
        print(Alice - Bob)
        exit()
    Bob += a[count]
    count += 1
    if count == n:
        print(Alice - Bob)
        exit()

Solution (Python):
n = int(input())
arr = list(map(int, input().split(" ")))


arr.sort(reverse=True)

a_arr = []
b_arr = []

for (i, ele) in enumerate(arr):
    
    if i % 2 == 0:
        a_arr.append(ele)
    
    else:
        b_arr.append(ele)

print(sum(a_arr) - sum(b_arr))

Solution (Python):
n=int(input())
ans=0
A=sorted(list(map(int,input().split())))[::-1]
for i in range(n):
  if i % 2 == 0:
    ans += A[i]
  else:
    ans -= A[i]
print(ans)

Solution (Python):



_ = int(input())
A = sorted(list(map(int, input().split())))[::-1]

ans = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        ans += a
    else:
        ans -= a

print(ans)

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    a = list(reversed(sorted(a)))
    alice = [a_[1] for a_ in enumerate(a) if a_[0] % 2 == 0]
    bob = [a_[1] for a_ in enumerate(a) if a_[0] % 2 == 1]
    
    print(sum(alice) - sum(bob))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
num = len(a)
alice = []
bob = []
coun = 1
for i in a:
    if coun % 2 == 1:
        alice.append(i)
    else:
        bob.append(i)
    coun += 1
ans = abs(sum(alice) - sum(bob))
print(ans)

Solution (Python):
N = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)

al=list()
bl=list()

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=0
a.sort()
s=sum(a[:n:2])-sum(a[1:n:2])

print(abs(s))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=0
a.sort()
s=sum(a[:n:2])-sum(a[1:n:2])
if s>0:
    print(s)
else:
    print(-s)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = 0
bob = 0
for i in range(0,n,2):
    alice += a[i]
    if i == n-1:
        break
    bob += a[i+1]
print(alice-bob)

Solution (Python):
def resolve():
    N = int(input())
    an = sorted([int(n) for n in input().split()], reverse=True)

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


if __name__ == '__main__':
    resolve()

Solution (Python):
for a in sorted(map(int,[*open(c:=0)][1].split())):c=a-c
print(c)

Solution (Python):
_,s=open(c:=0)
for a in sorted(map(int,s.split())):c=a-c
print(c)

Solution (Python):


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

a.sort(reverse=True)

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

print(x-y)

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

a = sorted(a, reverse=True)
alice = 0
bob = 0
for i in range(len(a)):
    if i%2==0:
        alice += a[i]
    if i%2==1:
        bob += a[i]
print(alice-bob)

Solution (Python):
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)

Solution (Python):
n = int(input())
a = [int(s) for s in input().split()]
a.sort(reverse=True)
alice = sum(a[0:n:2])
bob = sum(a[1:n:2])

print(alice - bob)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N):
  if num % 2 == 0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1 - sum2)

Solution (Python):
i = input()
l = list(map(int, input().split()))

dl = list(sorted(l))
dl = list(reversed(dl))

ans = 0

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

print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
al = 0
bo = 0
for i in range(n):
    if i%2==0:
        al += a[i]
    else:
        bo += a[i]
print(al-bo)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))

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

Solution (Python):
N = int(input())
list1 = list(map(int,input().split()))

list1.sort(reverse=True)

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

print(alice - bob)

Solution (Python):
N=int(input())
a = list(map(int, input().split()))
b=sorted(a, reverse=True)
print(sum(b[0::2])-sum(b[1::2]))

Solution (Python):
n = int(input())
a = [int(i) for i in 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)

Solution (Python):
mycode = r'''









ctypedef long long LL
ctypedef LL[:] Arr


import numpy as np


import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.readline 


cdef LL a_int(): return int(readline())

def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

cdef LL N=a_int()
cdef Arr A = ints() 
A=np.sort(A)[::-1] 
print(np.sum(A[0::2]) - np.sum(A[1::2])) 

'''

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  
    import os
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode

Solution (Python):
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)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cnt = 0

a.sort(reverse=True)

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

print(cnt)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]

Alice=0
Bob=0

for j in range(N):
    if j%2==0:
        Alice+=max(A)
        A.remove(max(A))
    
    else:
        Bob+=max(A)
        A.remove(max(A))
 
    
print(Alice-Bob)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = 0
f = 0
for a in A:
  if f == 0:
    ans += a
  else:
    ans -= a
  f ^= 1
print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

A.sort(reverse = True)

alc = 0
bob = 0

N -= 1
end = int(N/2) + 1

if N % 2 == 0:
    f = 1
else:
    f = 0

for i in range(0, end):
    alc += A[2*i]
    if f == 1 and 2*i == N:
        break
    bob += A[2*i+1]

print(alc-bob)

Solution (Python):
def main():
    N = int(input())
    a = list(map(int,input().split()))
    Alice = 0
    Alice_j = True
    Bob = 0
    Bob_j = False
    a.sort(reverse = True )
    for i in range(N):
        if Alice_j == True:
            Alice += a[i]
            Alice_j = False
            Bob_j = True
        elif Bob_j == True:
            Bob += a[i]
            Bob_j = False
            Alice_j = True
    return Alice - Bob

print(main())

Solution (Python):
N = int(input())
Ai = list(map(int,input().split()))
Alice = 0
Bob = 0
Ai.append(0)

while Ai:
    Alice += max(Ai)
    Ai.remove(max(Ai))
    if not Ai:
        break
    Bob += max(Ai)
    Ai.remove(max(Ai))

print(Alice-Bob)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

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

Solution (Python):

from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)





def LI(): return list(map(int, sys.stdin.buffer.readline().split()))




def I(): return int(sys.stdin.buffer.readline())





def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()




def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')







def IR(n): return [I() for i in range(n)]







def LIR(n): return [LI() for i in range(n)]







def SR(n): return [S() for i in range(n)]







def LSR(n): return [LS() for i in range(n)]







def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    a = sorted(LI(), reverse=True)
    alice = 0
    for i in range(0, n, 2):
        alice += a[i]
    print(2 * alice - sum(a))


if __name__ == "__main__":
    main()

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

a.sort(reverse=True)
alice = []
bob = []


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

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

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

a = sorted(a, reverse=True)

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

print(x-y)

Solution (Python):
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

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

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

Solution (Python):
n, *a = map(int, open(0).read().split())
a = sorted(a)[::-1]
print(sum(a[0::2]) - sum(a[1::2]))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = sorted(list(mapint()), reverse=True)

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

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)

alice=0
bob=0
i=0
while a:
    if i%2==0:
        alice+=a.pop()
    else:
        bob+=a.pop()
    i+=1
print(alice-bob)

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
al = A[::2]
bo = A[1::2]
print(sum(al)-sum(bo))

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

arr.sort(reverse=True)

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

Solution (Python):
n=int(input())
a=list(map(int,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)

Solution (Python):
n = int(input())
al = list(map(int, input().split()))
al.sort(reverse=True)
ali = 0
bob = 0
for i,a in enumerate(al):
    if i%2 == 0: ali += a
    else: bob += a

print(ali-bob)

Solution (Python):



if __name__ == '__main__':
    n = int(input())
    a = sorted([int(i) for i in input().split()], reverse=True)

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

    print(alice - bob)

Solution (Python):
N = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)

Alice, Bob = 0, 0

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

print(Alice - Bob)

Solution (Python):
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)

Solution (Python):
n = int(input())
aa = list(sorted(map(int, input().split())))
print(abs(sum(aa[::2]) - sum(aa[1::2])))

Solution (Python):

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

Alice = 0
Bob = 0

a_list.sort(reverse=True)

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

print(Alice-Bob)

Solution (Python):
n = int(input())
a = [int(s) for s in input().split()]

a.sort()
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += a[n-1-i]
    elif i % 2 == 1:
        bob += a[n-1-i]

print(alice - bob)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))

l.append(0)
_n = int(len(l)/2)

a = 0
b = 0

l.sort(reverse=True)

for i in range(_n):
  a += l[i*2]
  b += l[i*2 + 1]

print(a-b)

Solution (Python):
N = int(input())
Card = list(map(int,input().split()))

Card.sort(reverse=True)

if len(Card)>=2:
    A = sum(Card[::2])
    B = sum(Card[1::2])
else:
    A = Card[0]
    B = 0

print(A-B)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
alice = 0
bob = 0
list.sort(a , reverse = True)
for i in range(N):
  if i % 2 == 0:
    alice += a[i]
  else:
    bob += a[i]
print(alice - bob)

Solution (Python):
N, *A = map(int, open(0).read().split())
A.sort(reverse=True)
print(sum(A[::2]) - sum(A[1::2]))

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

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

Solution (Python):
n=input()
a = sorted(list(map(int,input().split())))[::-1]
print(sum(a[::2])-sum(a[1::2]))

Solution (Python):

import sys
input=sys.stdin.readline

def main():
    cards=[]
    sorted_cards=[]
    n = int(input())
    cards=list(map(int,input().split()))
    sorted_cards=sorted(cards,reverse=True)
    alice=0
    bob=0

    for idx,card in enumerate(sorted_cards):
        if idx%2==0:
            alice+=card
        else:
            bob+=card
    print(alice-bob)

if __name__=="__main__":
    main()

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    a.sort(reverse=True)
    return sum(a[::2]) - sum(a[1::2])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    print(solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = sorted(a)
A = 0
B = 0
for i in range(n-1, -1, -1):
    if n%2 == 0:
        if i%2 == 0:
            B += s[i]
        else:
            A += s[i]
    else:
        if i%2 == 0:
            A += s[i]
        else:
            B += s[i]
print(A - B)

Solution (Python):
n = int(input())
x = sorted(map(int,input().split()))
x.reverse()
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

Solution (Python):
n = int(input())
x = sorted(map(int,input().split()))
x.reverse()
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
a.sort()

for i in range(len(a)):
    if i % 2 == 0:
        alice += a.pop()
    else:
        bob += a.pop()

print(alice - bob)

Solution (Python):

import sys
from typing import List


def fast_input():
    return sys.stdin.readline()[:-1]


def solve(cards: List[int]) -> int:
    sorted_cards = sorted(cards, reverse=True)
    alice = 0
    bob = 0
    for i, card in enumerate(sorted_cards):
        if i % 2 == 0:
            alice += card
        else:
            bob += card
    return alice - bob


def main():
    n = int(fast_input())
    a = list(map(int, fast_input().split()))
    result = solve(a)
    print(result)


main()

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0

a.sort(reverse = True)

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

print(ans)

Solution (Python):

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = 0
for i in range(N):
    ans = ans+A[i] if i%2==0 else ans-A[i]
print(ans)

Solution (Python):
N = int(input())
array = list(map(int, input().split()))
array.sort()
sum_1 = 0
sum_2 = 0

for i in range(N):
    if i % 2 == 0:
        sum_1 += array[-1]
        array.pop(-1)
        
    else:
        sum_2 += array[-1]
        array.pop(-1)
print(sum_1 - sum_2)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

arr.sort(reverse=True)
answer = [0, 0]
for index in range(len(arr)):
    answer[index % 2] += arr[index]
print(answer[0] - answer[1])

Solution (Python):
n = int(input())
a = sorted((map(int, input().split())))
a.reverse()
print(sum(a[0::2]) - sum(a[1::2]))

Solution (Python):
import math

N = input()
num_list = list(map(int,input().split(' ')))
i = 0
Bob = 0
Alice = 0
for n in sorted(num_list, reverse=True):
  i += 1
  if i % 2 == 1:
    Bob += n
  elif i % 2 == 0:
    Alice += n
ans = Bob - Alice
print(ans)

Solution (Python):
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)

Solution (Python):
n = int(input())
a = [int(x.strip()) for x in input().split()]
a = sorted(a, reverse=True)
alice,bob = 0,0
for i in range(n):
  if i % 2 == 0:
    alice += a[i]
  else:
    bob += a[i]
print(alice-bob)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    a = list(map(int, readline().split()))
    a.sort(reverse=True)

    x = sum(a[::2])
    y = sum(a[1::2])

    print(x - y)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
score_A = 0
score_B = 0
a.sort(reverse=True)
i = 1
for n in a:
  if i % 2 == 1:
    score_A += n
  elif i % 2 == 0:
    score_B += n
  
  i += 1


result = score_A - score_B
print(result)

Solution (Python):
N = int(input())
m = list(map(int,input().split()))
m = sorted(m,reverse=True)

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

Solution (Python):
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)

Solution (Python):
N = int(input(""))
a = input("").split(" ")
a = [int(aa) for aa in a]
ap = 0
bp = 0
temp = 0
for c in range(len(a)):
    if c % 2 == 0:
        temp = a.pop(a.index(max(a)))
        ap += temp
    else:
        temp = a.pop(a.index(max(a)))
        bp += temp
print(str(abs(ap-bp)))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
alice = []
bob = []

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

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

Solution (Python):
n=int(input())
s=list(map(int,input().split()))
s.sort(reverse=True)

alice=sum(s[::2])
bob=sum(s)-alice
print(alice-bob)

Solution (Python):
N = int(input())
a = sorted(map(int, input().split()))
 
print(abs(sum(a[1::2])-sum(a[::2])))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
s=0
for i in range(n):
  if n%2==0:
    if i%2==0:
      s+=a[i]
  else:
    if i%2!=0:
      s+=a[i]

print(sum(a)-s*2)

Solution (Python):


num = int(input())
str = input().split()
table = [int(i) for i in str]

table2 = sorted(table, reverse = True)
a_point = 0
b_point = 0

for i in range(num):
    if i % 2 == 0:
        a_point += table2[i]
    elif i % 2 == 1:
        b_point += table2[i]
print(a_point - b_point)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
alice = 0
bob = 0
a.sort()
i = 0
for x in reversed(a):
  if(i%2==0):
    alice += x
  else:
    bob += x
  i += 1
print(alice-bob)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
N = int(input())

Alice = []
Bob = []

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

if len(a) % 2 == 1:
    a.append(0)

while len(a) > 0:
    Alice.append(a.pop(0))
    Bob.append(a.pop(0))

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

Solution (Python):



def main():
    n = int(input())
    li = list(map(int, input().split()))
    li.sort(reverse=True)
    a = sum(li[::2])
    b = sum(li[1::2])
    ans = a - b
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
line = list(map(int, input().split()))
line.sort()
line.reverse()
A = 0
B = 0
for i in range(1,n+1):
  if i % 2 != 0:
    A += line[i-1]
  else:
    B += line[i-1]
print(A-B)