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):
input()
a = sorted(map(int, input().split()))[::-1]
print(sum(a[::2])-sum(a[1::2]))

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

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

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()] 
a.sort()
a = a[::-1]

Alice = 0
Bob = 0

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

print(Alice - Bob)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
alice = 0
bob = 0
for i in range(1,n+1):
  if i%2==1:
    alice += max(a)
    a.remove(max(a))
  else:
    bob += max(a)
    a.remove(max(a))
    
print(alice-bob)

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

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

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

Solution (Python):
from collections import deque
 
N = int(input())
a = deque(sorted([int(i) for i in input().split()]))
 
sub = 0
for i in range(N):
    if i % 2 == 0:
        sub += a.pop()
    else:
        sub -= a.pop()
 
print(sub)

Solution (Python):

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

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

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

Solution (Python):
def examB():
    N = I()
    A = LI(); A.sort(reverse = True)
    cur = 0
    for i,j in enumerate(A):
        cur +=j*((-1)**i)
    print(cur)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

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

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

alice = 0
for i in range(len(a)):
    if i % 2 == 0:
        
        alice += a[-i-1]
print(2*alice - sum_)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
Alice=[0,0]
Bob=[0,0]
for i in a:
  if Alice[1]==Bob[1]:
    Alice[0]+=i
    Alice[1]+=1
  else:
    Bob[0]+=i
    Bob[1]+=1
print(Alice[0]-Bob[0])

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

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

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

Solution (Python):

a = int(input())  
b = input()  
b = map(int, b.split())  
b = sorted(b)  
b = b[::-1]  
c = b[::2]  
c_number = len(c)
d = b[1::2]  
d_number = len(d)
c_sum = 0
d_sum = 0
for i in range(c_number):  
    c_sum += c[i] 

for g in range(d_number):
    d_sum += d[g]  

print(c_sum - d_sum)

Solution (Python):

a = int(input())  
b = input()  
b = map(int, b.split())
b = sorted(b)
b = b[::-1]
c = b[::2]
c_number = len(c)
d = b[1::2]
d_number = len(d)
c_sum = 0
d_sum = 0
for i in range(c_number):
    c_sum += c[i]

for g in range(d_number):
    d_sum += d[g]

print(c_sum - d_sum)

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

print(al - bo)

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

Solution (Python):
from sys import stdin
from itertools import combinations

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort(reverse=True)

ali = 0
bob = 0

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

print(ali-bob)

Solution (Python):
n=int(input())
a=list(input().split(" "))
a=list(map(int,a))
a.sort(reverse=True)
alic=[]
bob=[]
for i in range(0,n):
    if i==0 or i%2==0:
        alic.append(a[i])
    else:
        bob.append(a[i])
print(sum(alic)-sum(bob))

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

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):
def card_game_for_two():
    input() 
    cards = sorted(list(map(int, input().split())), reverse=True)

    score_diff = sum(cards[::2]) - sum(cards[1::2])

    print(score_diff)

card_game_for_two()

Solution (Python):
N = int(input())
As = map(int, input().split())
sorted_As = sorted(As, reverse=True)
alice_sum = 0
bob_sum = 0
for i, a in enumerate(sorted_As):
    if (i+1) % 2 == 1:
        alice_sum += a
    else:
        bob_sum += a
print(alice_sum - bob_sum)

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

a.sort(reverse=True)

alice = 0
bob = 0

for idx, val in enumerate(a):
    if idx % 2 == 0:
        alice += val
    else:
        bob += val

print(alice - bob)

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

Alice = 0
Bob = 0

for i in range(N):
    maxa = max(a)
    a.remove(maxa)
    if i % 2 == 0:
        Alice += maxa
    else:
        Bob += maxa

ans = Alice - Bob
print(ans)

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

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

alice_score = sum(cards[::2])
bob_score = sum(cards[1::2])

print(alice_score - bob_score)

Solution (Python):
input()
a = list(reversed(sorted([int(i) for i in input().split()])))
print(sum(a[::2]) - sum(a[1::2]))

Solution (Python):
def buttle(a):
    alice = 0
    bob = 0

    a.sort(reverse=True)
    for i in range(len(a)):
        if i % 2 != 0:
            continue
        alice += a[i]
        if len(a) > i+1:
            bob += a[i+1]
    return alice - bob

n = int(input())
a = [int(x) for x in input().split()]
print(buttle(a))

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

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

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

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

print(alice_p - bob_p)

Solution (Python):

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

a.sort(reverse = True)

score_Alice = sum(a[0::2])
score_Bob = sum(a[1::2])

print(score_Alice - score_Bob)

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

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

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

Alice, Bob = 0, 0

for i in range(N):
  if i % 2 == 0:
    Alice += a.pop(a.index(max(a)))
  else:
    Bob += a.pop(a.index(max(a)))
    
ans = abs(Alice - Bob)

print(ans)

Solution (Python):


n=int(input())
a=list(map(int,input().split()))
A=0
B=0
for i in range(n):
    if i%2==0:
        A+=max(a)
        a.remove(max(a))
    else:
        B+=max(a)
        a.remove(max(a))
print(A-B)

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    a = list(map(int, readline().split()))
    a = sorted(a)[::-1]

    A, B = 0, 0
    sa, sb = 0, 1
    for i in range(N):
        sa += (-1)**i
        sb += (-1)**(i+1)
        A += sa * a[i]
        B += sb * a[i]

    print(A-B)


main()

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
couA = 0
couB = 0
for i in range(0,len(a),2):
    couA +=a[i]
for j in range(1,len(a),2):
    couB +=a[j]
print(couA-couB)

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

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

Solution (Python):
n = int(input())
list_a = list(map(int, input().split()))
list_a.sort(reverse=True)
list_alice = [a for i, a in enumerate(list_a) if i % 2 == 0]
list_bob = [a for i, a in enumerate(list_a) if i % 2 != 0]
print(sum(list_alice) - sum(list_bob))

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

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

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

print(s-d)

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

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

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

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):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

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

main()

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort(reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

Solution (Python):


import sys








def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    a.sort(reverse=1)
    alice, bob = 0, 0
    for i in range(n):
        if i % 2 == 0:
            alice += a[i]
        else:
            bob += a[i]
    ans = alice - bob
    print(ans)


if __name__ == "__main__":
    
    main()

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
Alice =0
Bob = 0
A.sort()
A.reverse()
for i in range(0,N,2):
  Alice +=A[i]
Bob =sum(A)-Alice
print(Alice-Bob)

Solution (Python):
def main():
    N = int(input())
    a = list(map(lambda i: int(i), input().split()))
    a.sort()
    alice = []
    bob = []
    for i in range(len(a)):
        if i % 2 == 0:
            alice.append(a[len(a) - 1 - i])
        else:
            bob.append(a[len(a) - 1 - i])
    print(sum(alice) - sum(bob))

main()

Solution (Python):
N = int(input())
NN = [int(i) for i in input().split()]
NN_sort = sorted(NN, reverse=True)
A_score = sum([NN_sort[i] for i in range(0, N, 2)])
B_score = sum([NN_sort[i] for i in range(1, N, 2)])
print(A_score-B_score)

Solution (Python):


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    a.sort(reverse=True)

    A = 0
    B = 0

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

    print(A - B)

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("{}".format(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=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
print(sum(a[::2])-sum(a[1::2]))

Solution (Python):


n = int(input())
a = [int(i) for i in input().split()]
junban = True
Alice = Bob = 0

while a:
    if junban:
        Alice += max(a)
        a.remove(max(a))
        junban = False
    else:
        Bob += max(a)
        a.remove(max(a))
        junban = True

print(Alice -Bob)

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

a.sort(reverse=True)

x=0
p_alice=0
p_bob=0

while (x < n):
    if(x%2==0):
        p_alice += a[x]
    else:
        p_bob += a[x]
    x+=1

print(p_alice-p_bob)

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

a.sort(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)
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()
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 = sorted(A)
alice = 0
bob = 0
i = 0
for a in A[::-1]:
    if i%2==0: alice += a
    else: bob += a
    i+=1

print(alice-bob)

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

alice = 0
bob = 0
for i in range(N):
  if i % 2 == 0:
    alice += alist.pop(alist.index(max(alist)))
  else:
    bob += alist.pop(alist.index(max(alist)))
    
print(alice-bob)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
A=many_int()

A=sorted(A,reverse=True)

Alice=A[::2]
Bob=A[1:][::2]

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

Solution (Python):
N = int(input())
a_list = [int(num) for num in input().split()]
a_list.sort(reverse=True)

alice = 0
bob = 0

for i, num in enumerate(a_list, 1):
  if i % 2:
    alice = alice + num
  else:
    bob = bob + num
print(alice-bob)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
alice, bob = 0, 0
while len(a) > 0:
    alice += max(a)
    a.remove(max(a))
    if len(a) > 0:
        bob += max(a)
        a.remove(max(a))
    else:
        break
ans = alice - bob
print(ans)

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

Solution (Python):
n=int(input())
a=sorted(map(int,input().split()),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())
a = list(int(x) for x in input().split())
a_s = sorted(a, reverse = True)

al = 0
bo = 0
for i in range(n):
    if i % 2 == 0:
        al += a_s[i]
    else:
        bo += a_s[i]

print(al-bo)

Solution (Python):
n = int(input())
Alice = 0
Bob = 0
card = list(map(int,input().split(' ')))
card.sort(reverse=True)
for i in range(n):
    num = card[i]
    if(i%2==0):
        Alice+=num
    else:
        Bob+=num

print((Alice-Bob))

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

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 = list(map(int,input().split()))
if len(a)%2 != 0:
    a.append(0)
    N += 1
alice = []
bob = []
for i in range(int(N/2)):
    alice.append(a.pop(a.index(max(a))))
    bob.append(a.pop(a.index(max(a))))
print(sum(alice)-sum(bob))

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

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



score1 = []
score2 = []

while len(a) > 0:
    pick = max(a)
    score1.append(pick)
    a.remove(pick)
    if len(a) == 0:
        break
    
    pick = max(a)
    score2.append(pick)
    a.remove(pick)
    


print(sum(score1) - sum(score2))

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = sum(a)
for i in range(n):
    if i%2 == 1:
        ans -= 2*a[i]
print(ans)

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

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

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

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

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 = list(map(int, input().split()))


a.sort(reverse=True)


A_total = 0
B_total = 0

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

print(A_total - B_total)

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

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

count = 0
allice_total = 0
bob_total = 0
for a in a_list:
    if count % 2 == 0:
        allice_total += a
    else:
        bob_total += a
    count += 1

print(allice_total - bob_total)

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 = list(map(int, input().split()))
r = sorted(a, reverse=True)
ans = 0
for i in range(N):
  if i % 2 == 0:
    ans += r[i]
  else:
    ans -= r[i]
print(ans)

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

Solution (Python):
n, *a = map(int, open(0).read().split())
a.sort(reverse=True)

alice = 0
bob = 0

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

ans = alice - bob

print(ans)

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())
num = list(map(int, input().split()))
num.sort(reverse=True)
print(sum(num[0::2])-sum(num[1::2]))

Solution (Python):

N = int(input())



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


 
turn = 0 
Alice = 0
Bob = 0
Dif = 0


top = [0,0]
while (1):
  flag = N
  top = [0,0]
  
  
  for i in range(N): 
    if A[i] > top[0]:
      top[0] = A[i]
      top[1] = i
    elif A[i] == 0:
      flag -= 1
  
  
  if turn == 0:
    turn = 1
    Alice += top[0]
    A[top[1]] = 0
    
  elif turn == 1:
    turn = 0
    Bob += top[0]
    A[top[1]] = 0
    
  
  
  
  if flag <= 1:
    
    break


 




print(Alice-Bob)

Solution (Python):

N, *a = map(int, open(0).read().split())
a = sorted(a)[::-1]

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

Solution (Python):
import numpy as np
n= int(input())
a_list = sorted(list(map(int, input().split())),reverse=True)
a_array = np.array(a_list)
alice = a_array[::2]
bob = a_array[1::2]
print(sum(alice)-sum(bob))

Solution (Python):
n = int(input())
a = sorted(map(int,input().split()))[::-1]
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(n):
    if i%2 == 0:
        alice += list1[i]
    else:
        bob += list1[i]

print(alice-bob)

Solution (Python):
n = int(input())
a = sorted([int(i) for i in input().split()],reverse=True)
A = [a[0]]
B = []
for i in range(1,n):
  if i % 2 == 0:
    A.append(a[i])
  else:
    B.append(a[i])
print(sum(A)-sum(B))

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())
ls = list(map(int, input().split()))
ls.sort(reverse=True)
alice_point = 0
bob_point = 0

for i in range(n):
  if i % 2 == 0:
    alice_point += ls[i]
  else:
    bob_point += ls[i]

difference = alice_point - bob_point
print(difference)

Solution (Python):
x = input()
y = list(map(int,input().split()))
a = 0
b = 0
for i, yi in enumerate(sorted(y, reverse=True)):
  if i%2 == 0:
    a += yi
  else:
    b += yi
print(a-b)

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

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

Solution (Python):



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)

Solution (Python):
import numpy as np

n=int(input())
a_list=list(map(int,input().split()))
a_list_2=sorted(a_list,reverse=True)
a=np.array(a_list_2,dtype='uint8')

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()))
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)

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

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

c.sort(reverse=True)

alice = sum([c[i] for i in range(len(c)) if i%2==0])

print(2*alice-sum(c))

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

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

for i in range(N):
  if i%2==0:
    result += x[i]
  elif i%2!=0:
    result -= x[i]
  
print(result)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
point = 0
calc = True
for i in a:
    if calc:
        calc = False
        point += i
    else:
        calc = True
        point -= i

print(point)

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

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

a = sorted(a, reverse=True)
scr_a = 0
scr_b = 0

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

print(scr_a - scr_b)

Solution (Python):
n = int(input())
s = sorted(list(map(int, input().split())), reverse=True)
A = 0
B = 0
for e, i in enumerate(s):
  if e%2==0:
    A += i
  else:
    B += i
print(A-B)

Solution (Python):
N = int(input())
Alice_total = 0
Bob_total = 0
card_list = input().split()
card_list = [int(n) for n in card_list]
card_list.sort(reverse =True)

for i in range(0,N,2):
    Alice_total += card_list[i]

for i in range(1,N,2):
    Bob_total += card_list[i]

print(Alice_total - Bob_total)

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
alice = sum(A[::2])
bob = sum(A[1::2])
print(alice-bob)

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

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

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

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

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

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

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

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 = list(map(int, input().split()))
sorted_a = list(reversed(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)

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

s = sorted(s, reverse=True)

Alice = 0
Bob = 0

for i, x in enumerate(s):
  if i%2==0:
    Alice+=x
  else:
    Bob+=x
    
print(str(Alice-Bob))

Solution (Python):
import heapq

N = int(input())
A = [-int(x) for x in input().split()]
ans=0
j=-1
heapq.heapify(A)

for i in range(N):
    ans +=heapq.heappop(A)*j
    j*=-1
    
print(ans)

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

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

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

Solution (Python):
n=int(input())
a=sorted([int(_) for _ in input().split()], key=lambda x: -x)
print(sum(a[::2])-sum(a[1::2]))

Solution (Python):
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]
ans = alice - bob
print(ans)

Solution (Python):



def main():



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




if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]
A.sort(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)

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=input()
c=sorted(list(map(int,input().split())))[::-1]
n=0
for i in c[0::2]:
  n+=i
for i in c[1::2]:
  n-=i
print(n)