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

a.sort()


alice = 0
bob = 0
flg = 0

while(len(a)>0):
    if flg == 0:
        alice += a.pop()
    elif flg ==1:
        bob += a.pop()
    flg = not(flg)

print(alice-bob)

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

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

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

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

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

a_p = 0
b_p = 0

for i in range(N):
    m = max(alist)
    if i%2 == 0:
        a_p += m
        alist[alist.index(m)] = 0
    else:
        b_p += m
        alist[alist.index(m)] = 0
print(a_p - b_p)

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

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

a_list = sorted(a_list)[::-1]

al = sum([a for i,a in enumerate(a_list) if i%2==0])
bo = sum([a for i,a in enumerate(a_list) if i%2==1])

print(al-bo)

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

Solution (Python):
import sys

input = sys.stdin.readline

n = int(input())

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

a.sort(reverse=True)

alice = 0
bob = 0

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

ans = alice - bob

print(ans)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
Alice = 0
Bob = 0

for i in range(N):
  max_val = max(a)
  max_idx = a.index(max_val)
  
  if i % 2 == 0:
    Alice += max_val
  else:
    Bob += max_val
  del a[max_idx]

print(Alice - Bob)

Solution (Python):
n = int(input())
num_list =list(map(int,input().split()))
num_list.sort(reverse=True)
bob = 0
alice = 0
for i,num in enumerate(num_list):
    if i%2 == 0:
        alice += num
    else:
        bob += num
print(alice-bob)

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):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
A = nl()

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):
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)






N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
a = sum(A[0::2])
b = sum(A[1::2])

print(a - b)

Solution (Python):
from sys import stdin

n = stdin.readline().rstrip()
arr = [int(x) for x in stdin.readline().rstrip().split()]

alice_score = 0
bob_score = 0

for i in range(len(arr)):
    max_num = max(arr)
    if(i%2!=0):
        
        alice_score += max_num
        arr.remove(max_num)
    else:
        bob_score += max_num
        arr.remove(max_num)

print(abs(alice_score - bob_score))

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


abc()

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
print(sum(a[0::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 = sorted(list(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()))
alice, bob = 0, 0

for i in range(N):
    m = max(A)
    A.remove(m)
    if i % 2 == 0:
        alice += m
    else:
        bob += m
print(alice - bob)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
total = sum(a)
a_score = 0
for i in range(0,len(a),2):
    a_score += a[i]
print(2*a_score - total)

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

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

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

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

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

while True:
    if len(LIST) == 0:
        break
    Alice = Alice + LIST.pop()
    if len(LIST) == 0:
        break
    Bob = Bob + LIST.pop()

print(Alice - Bob)

Solution (Python):
n = input()
list_num = [int(num) for num in input().split()]
 
list_num.sort(reverse=True)
a = sum(list_num[0::2])
b = sum(list_num[1::2])
 
print(a-b)

Solution (Python):
N=int(input())
cardmap=map(int,input().split())
card=list(cardmap)
card.sort(reverse=True)
Alist=card[0::2]
Blist=card[1::2]
Asum=sum(Alist)
Bsum=sum(Blist)
print(Asum-Bsum)

Solution (Python):
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    alist = list(map(int, input().split()))

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

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

Solution (Python):
N = int(input())
cards = [int(x) for x in input().split()]
ALICE = 0
BOB = 0
while cards:
  temp = max(cards)
  cards.remove(temp)
  ALICE+=temp
  if not(cards):
    break
  temp = max(cards)
  cards.remove(temp)
  BOB+=temp

print(ALICE - BOB)

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

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

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

a = sum(l[0::2])
b = sum(l[1::2])

print(a - 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):


from math import *
from itertools import *
from collections import *
from bisect import *


if __name__ == '__main__':
    input()
    lst = [int(x) for x in input().split()]
    lst.sort(reverse=True)
    n = sum(lst)
    na = sum(lst[::2])
    print(na-n+na)

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

list = input().split(" ")
num_list = []

for num in list:
    num_list.append(int(num))

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)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
alice = []
bob = []
while len(a) >= 1:
    alice.append(a.pop())
    if len(a) >= 1:
        bob.append(a.pop())
print(sum(alice) - sum(bob))

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")









N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
ac = 0
bc = 0

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

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=int(input())
al=list(map(int,input().split()))
al.sort(reverse=True)
alice=0
bob=0
flg=True
for a in al:
    if flg:
        alice+=a
    else:
        bob+=a
    flg=False if flg else True
print(alice-bob)

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

coef = 1
score = 0
while A:
  score += A.pop() * coef
  coef *= (-1)

print(score)

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

Alice=0
Bob=0
n=1

while n<=N:
  if n%2==1:
    Alice=Alice+max(A)
    A.remove(max(A))
    n=n+1
  else:
    Bob=Bob+max(A)
    A.remove(max(A))
    n=n+1
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):

import sys


def solve(N: int, a: "List[int]"):
    a.sort(reverse=True)
    print(sum(a[0::2])-sum(a[1::2]))
    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())
cards=sorted(list(map(int,input().split())),reverse=True)
Alice=sum(cards[::2])
Bib=sum(cards[1::2])
print(Alice-Bib)

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

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

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
list.sort(li, reverse = True)
switch = 1
Alice = 0
Bob = 0
for i in li:
    if switch == 1:
        Alice += i
        switch = 0
    else:
        Bob += i
        switch = 1
print(Alice - Bob)

Solution (Python):
import re  
import sys 


def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))


N = i_input()
A = l_input()

alice = 0
bob = 0

for i in range(N):
    biggest = max(A)
    if i % 2 == 0:
        alice += biggest
    else:
        bob += biggest
    A.remove(biggest)

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):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    a = list(int(_) for _ in 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)
    
if __name__ == '__main__':
    main()

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

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

Solution (Python):
n = int(input())
a_nums = []
tmp = input().split()
for i in range(n):
    a_nums.append(int(tmp[i]))

a_nums.sort(reverse=True)

num_sum = 0
for i in range(n):
    if i%2 == 0:
        num_sum = num_sum+a_nums[i]
    else:
        pass


sum_up = 0
for i in range(n):
    sum_up = sum_up + a_nums[i]

print(num_sum - sum_up + num_sum)

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

a.sort(reverse = True)
L = [0, 0]
f = 0
for i in a:
  L[f] += i
  f = 1 - f

print(L[0] - L[1])

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
Alice = 0
Bob = 0
card = 0
for i in range(N):
    if A == []:
        break
    card = max(A)
    if card == 0:
        break
    else:
        Alice += card
        A.remove(card)
    if A == []:
        break
    card = max(A)
    if card == 0:
        break
    else:
      Bob += card
      A.remove(card)
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):
i = int(input())
card = list(map(int,input().split(' ')))
card.sort(reverse=True)

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))
    A.sort()
    Alice = 0
    Bob = 0
    turn = True
    for _ in range(N):
        if turn:
            Alice += A.pop()
            turn = False
        else:
            Bob += A.pop()
            turn = True
            
    print(abs(Alice - Bob))

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

a.sort(reverse=True)

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

Solution (Python):
N = int(input())
alice = 0
bob = 0
a = [int(i) for i in input().split()] 
while len(a) != 0:
    alice += max(a)
    a.remove(max(a))
    while len(a) != 0:
        bob += max(a)
        a.remove(max(a))
        break
print(alice - bob)

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

lst.sort(reverse = True)

A = 0
for i in range(0,N,2):
  A += lst[i]
B = 0
for j in range(1,N,2):
  B += lst[j]
print (A-B)

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

Solution (Python):

N = input()

lst_A = input().split()

A_sum = 0
B_sum = 0

for i in range(len(lst_A)):
    lst_A[i] = int(lst_A[i])

lst_A.append(-1)

lst_A.sort(reverse=True)

while 1:
    if lst_A[0] == -1:
        break
    A_sum += lst_A[0]
    del lst_A[0]
    if lst_A[0] == -1:
        break
    B_sum += lst_A[0]
    del lst_A[0]

ans = A_sum - B_sum
print(ans)

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

a.sort(reverse=True)

ans1 = a[::2]
ans2 = a[1::2]

print(sum(ans1)-sum(ans2))

Solution (Python):
def solve(A):
    A = sorted(A, reverse=True)
    return sum(A[::2])-sum(A[1::2])

N = int(input())

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

Solution (Python):

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

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

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

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):
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())
Als = []

x = input().split(" ")

for i in range(N):
    Als.append(int(x[i]))

Als.sort(reverse = False)

Alice = 0
Bob = 0


for i in range(N):
    now = Als.pop()
    if i%2 == 0:
        Alice += now
    else:
        Bob += now

print(Alice - Bob)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
alice = 0
bob = 0
n = 0
while len(a) > 0:
    if n == 0:
        alice += a.pop()
        n = 1
    else:
        bob += a.pop()
        n = 0
print(alice - bob)

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

even = sum(a[0::2])
odd = sum(a[1::2])
print(abs(even - odd))

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

alice = 0
bob = 0

a.sort(reverse=True)

for i, num in enumerate(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)

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

print(total)

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

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

    A_list = sorted(A_list, reverse=True)

    odd_A_list = A_list[::2]
    even_A_list = A_list[1::2]

    print(sum(odd_A_list)-sum(even_A_list))

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

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

Solution (Python):
n = int(input())
list = input().split()
list = [int(i) for i in list]

list = sorted(list)[::-1]
alice = list[::2]
bob = list[1::2]
print(sum(alice)-sum(bob))

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

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

a.sort(reverse=True)

a_ = []
b_ = []
for i,j in enumerate(a):
    if i%2 == 0:
        a_.append(j)
    else:
        b_.append(j)
        
print(sum(a_)-sum(b_))

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

import sys


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    a = 0
    b = 0
    for i, v in enumerate(A):
        if i % 2 == 0:
            a += v
        else:
            b += v
    ret = a - b
    print(ret)
    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 = [int(i) for i in input().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()
alice = []
bob = []
for i in range(N):
    if i%2 == 0:
        alice.append(a.pop())
    else:
        bob.append(a.pop())

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

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

sort_a = sorted(a, reverse=True)

cnt = 0
Alice = 0
Bob = 0
for i in sort_a:
    if cnt % 2 == 0:
        Alice += i
    else:
        Bob += i
    cnt += 1

print(Alice - Bob)

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

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

A.sort()
A.reverse()

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)

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

num_list = sorted([ int(v) for v in input().split() ])

a_sum, b_sum = 0, 0

for i in range(n):
  if i % 2 == 0:
    a_sum += num_list[i]
  else:
    b_sum += num_list[i]

print(abs(a_sum-b_sum))

Solution (Python):



import sys

input = sys.stdin.readline

def main():
    _ = input()
    A = [int(e) for e in input().split()]
    A.sort(reverse=True)
    sum_a = 0
    sum_b = 0
    for i, e in enumerate(A):
        if i % 2 == 0:
            sum_a += e
        else:
            sum_b += e
    print(sum_a - sum_b)

main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
A = []
B = []
if n % 2 == 0:
    while len(a) > 0:
        A.append(max(a))
        a.remove(max(a))
        B.append(max(a))
        a.remove(max(a))
else:
    while len(a) > 1:
        A.append(max(a))
        a.remove(max(a))
        B.append(max(a))
        a.remove(max(a))
    A.append(max(a))
print(sum(A) - sum(B))

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
alice_list=[]
bob_list=[]
a.sort()
if n%2==0:
    for x in range(0,n):
        if x%2==1:
            alice_list.append(a[x])
        else:
            bob_list.append(a[x])
else:
    for x in range(0,n):
        if x%2==1:
            bob_list.append(a[x])
        else:
            alice_list.append(a[x])

alice_sum=sum(alice_list)
bob_sum=sum(bob_list)
ans=alice_sum-bob_sum


print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
Ali=0
Bob=0
a.sort()
ab_flag=0
while len(a)!=0:
    if ab_flag==0:
        Ali += a.pop()
        ab_flag=1
    else:
        Bob += a.pop()
        ab_flag=0
print(Ali-Bob)

Solution (Python):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint

import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    
    x = root(x)
    y = root(y)
    if x == y:
        return
    
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  
        return x
    else:
        node[x] = root(node[x])  
        return node[x]
def dfs(v):
    
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  
            continue
        if visited[v2] == True:  
            continue
        dfs(v2)


n = II()
a = sorted(LI(), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

Solution (Python):
n = int(input())
dat_a = list(map(int, input().split()))
dat_a.sort()
a = 0
b = 0
while True:
    if len(dat_a) ==0:
        break
    a += dat_a.pop()

    if len(dat_a) ==0:
        break
    b += dat_a.pop()
print(a-b)

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

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

Solution (Python):

N = input()
L = list(map(int,input().split()))
L.sort()
L.reverse()

cnt = 0

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

print(cnt)

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

a.sort(reverse=True)

ans = 0

while len(a) > 0:
    ans += a.pop(0)
    if len(a) == 0:
        break
    ans -= a.pop(0)

print(ans)

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
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
Alice = sum(sorted(data)[0::2])
Bob   = sum(sorted(data)[1::2])
print(max(Alice,Bob)-min(Alice,Bob))

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

Solution (Python):
numS = int(input())
num1 = [int(i) for i in input().split()]
num1.sort(reverse=True)

numA = []
numB = []

for index1 in range(numS ):
    if index1%2 == 0:
        numA.append(num1[index1])
    else:
        numB.append(num1[index1])

print(str(sum(numA) - sum(numB)))

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    alist = intina()

    alist.sort(reverse=True)

    alice = 0
    bob = 0

    for i, a in enumerate(alist):
        if i & 1:
            bob += a
        else:
            alice += a

    print(alice - bob)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a.sort()
a_decending = a[::-1]
Alice = 0
Bob = 0

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

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

Solution (Python):

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


a=b=0


l.sort()
l.reverse()

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


print(a-b)