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

A.sort()
print(sum(A[::-2])-sum(A[-2::-2]))

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

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

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



print(abs(b-c))

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):
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)

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

print( "{}".format( abs( even-odd ) ) )

Solution (Python):

N = int(input())
a = sorted(list(map(int, input().split())))
Alice_list = []
Bob_list = []
for i in range(1, N+1):
    if i%2==1:     
        Alice_list.append(a[-i])
    else:
        Bob_list.append(a[-i])
print(sum(Alice_list)-sum(Bob_list))

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

data = sorted(data, key=int, reverse=True)

alice_total=0
bob_total=0


for i in range(0, n):
    if i % 2 == 0:
        alice_total = alice_total + int(data[i])
    else:
        bob_total = bob_total + int(data[i])

print(alice_total - bob_total)

Solution (Python):
N=int(input())
card=sorted(list(map(int,input().split())),reverse=True)
A=sum([i for x,i in enumerate(card) if x%2])
B=sum([i for x,i in enumerate(card) if not x%2])
print(abs(A-B))

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

A.sort(reverse = True)
Alice =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 = a[::-1]
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):
card_n = int(input())
card_collection = list(map(int, input().split()))

scores = {"alice" : 0, "bob" :0}
card_collection.sort(reverse = True)
for i, card in enumerate(card_collection):
    if i % 2 == 0:
        scores['alice'] += card
    else:
        scores['bob'] += card
print(scores["alice"] - scores["bob"])

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

Solution (Python):
N = input()
alist = list(map(int, input().split()))
alist.sort(reverse = True)
AliSc = 0
BobSc = 0

while alist != []:
    AliSc += alist[0]
    del alist[0]
    if alist != []:
        BobSc += alist[0]
        del alist[0]
    else:
        break

print(AliSc - BobSc)

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

list=sorted(list)[::-1]
A=0
B=0

for i in range(0,len(list)):
  if i%2==0:
    A=A+list[i]
  else:
    B=B+list[i]
    
print(A-B)

Solution (Python):



import sys





def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(allCards, eachCards):
    eachCardSort = sorted(eachCards, reverse=True)
    AlicesTotal = 0
    BobsTotal = 0
    for j in range(0, allCards, +1):
        if j % 2 == 0:
            AlicesTotal = AlicesTotal + eachCardSort[j]
        else:
            BobsTotal = BobsTotal + eachCardSort[j]
    
    return AlicesTotal - BobsTotal


if __name__ == "__main__":
    N = II()
    AN = LI()
    print("{}".format(solver(N, AN)))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
Alice = 0
Bob = 0
A = sorted(A, reverse = True)
for i, a in enumerate(A):
    if i %2 == 0:
        Alice += a
    else:
        Bob += a

print(Alice - Bob)

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

a_sum = 0
b_sum = 0

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

print(a_sum - b_sum)

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):
n = int(input())
*A, = map(int, input().split())
A.sort(reverse=True)
turn = 0
x, y = 0, 0
for a in A:
    if turn == 0:
        x += a
    else:
        y += a
    turn = (turn+1) % 2
print(x-y)

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

Solution (Python):
N=int(input())
A=sorted(list(map(int,input().split())))[::-1]
B=[A[i] for i in range(len(A)) if i %2 == 0 ] 
C=[A[i] for i in range(len(A)) if i %2 != 0 ] 

print(sum(B)-sum(C))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
greatest = 0
m = 0
g = N

while g > 0:
  for i in range(N):
    if a[i]>greatest:
      greatest = a[i]
      m = i
  Alice += greatest
  a[m] = 0
  greatest = 0

  for i in range(N):
    if a[i]>greatest:
      greatest = a[i]
      m = i
  Bob += greatest
  a[m] = 0
  greatest = 0
  g = g - 2

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
input=sys.stdin.readline
















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

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())
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()))
na=sorted(a,reverse=True)
Alice=0
Bob=0

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

print(Alice-Bob)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
alice = []
bob = []
a.sort(reverse=True)
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):
input()

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

Solution (Python):
input()

AT = 0
Nob = 0
count = 0
for i in reversed(sorted(list(map(int, input().split())))):
    if(count % 2 == 0):
        AT += i
    else:
        Nob += i
    count += 1
print(AT-Nob)

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

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

a.sort(reverse=True)
isa = True
ali = 0
bob = 0
for t in a:
    if (isa):
        ali += t
    else:
        bob += t
    isa = not isa

print(ali - bob)

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

a.sort(reverse=True)

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

Solution (Python):


import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

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

alice=0
bob=0

a.sort()

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

Solution (Python):
N = int(input())
l = [int(x) for x in 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 = int(input())
x = input().split()
y = []
for i in x:
  y.append(int(i))
y.sort(reverse=True)
a = 0
b = 0
for i in range(0, n):
  if i % 2 == 0:
    a += int(y[i])
  else:
    b += int(y[i])
print(a - b)

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

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

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

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

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())
la = list(map(int, input().split()))
larev = sorted(la, reverse=True)

A = sum(larev[0::2])
B = sum(larev[1::2])

print(A - B)

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

Ans = 0
flag = True
for i in A_:
    if flag:
        Ans += i
        flag = False
    else:
        Ans -= i
        flag = True
print(Ans)

Solution (Python):



import sys





def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(cardCount, cardNumberList):
    result = 0
    cardNumberList.sort(reverse=True)
    
    
    AlicesCard = 0
    for j in range(0, cardCount, +2):
        
        AlicesCard = AlicesCard + cardNumberList[j]
    BobsCard = 0
    for j in range(1, cardCount, +2):
        
        BobsCard = BobsCard + cardNumberList[j]
    result = abs(AlicesCard-BobsCard)
    return result


if __name__ == "__main__":
    N = II()
    AI = LI()
    print("{}".format(solver(N, AI)))

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
A=a[0::2]
B=a[1::2]
print(sum(A)-sum(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):
from heapq import heappop, heappush, heapify
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  A = list(x for x in map(int, readline().split()))
  heapify(A)
  Alice = 0
  Bob = 0
  for i in range(N):
    if i%2==0:
      Alice += heappop(A)
    else:
      Bob += heappop(A)
  ans = abs(Alice-Bob)
  print(ans)
  
  
if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
cards_list = list(map(int,input().split()))
cards_list.sort()
cards_list.reverse()
sum_alice = 0
sum_bob = 0
turn = 0

for val in cards_list:
    if turn == 0:
        sum_alice += val
        turn = 1
    else:
        sum_bob += val
        turn = 0

print(sum_alice-sum_bob)

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

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

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse=True)
a = []
b = []

for i in range(n):
  if i%2 == 0:
    a.append(li[i])
  else:
    b.append(li[i])

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

Solution (Python):


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

Alice = 0
Bob = 0

Turn = 0
for a in sorted(A, reverse=True):
    if Turn == 0:
        Alice += a
        Turn =1
    else:
        Bob += a
        Turn = 0
print(Alice-Bob)

Solution (Python):
import numpy as np
N=int(input())
a=[int(x) for x in input().split()]
A=0
B=0
while 1:
    A+=max(a)
    loc=np.argmax(a)
    a.pop(loc)
    if a==[]:break
    B+=max(a)
    loc=np.argmax(a)
    a.pop(loc)
    if a==[]:break
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 = input()
nums = sorted(list(map(int,input().split())),reverse=True)
print(sum(nums[0::2]) - sum(nums[1::2]))

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

if __name__ == '__main__':
  main()

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

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()))
a_min = min(a)
alice = 0
bob = 0
while max(a) != 0:
    alice += max(a)
    for i in range(len(a)):
        if a[i] == max(a):
            a[i] = 0
            break
    bob += max(a)
    for i in range(len(a)):
        if a[i] == max(a):
            a[i] = 0
            break
if alice > bob:
    print(alice-bob)
else:
    print(bob-alice)

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

while True:
    if len(cards) == 0:
        break
    a += max(cards)
    cards.remove(max(cards))

    if len(cards) == 0:
        break
    b += max(cards)
    cards.remove(max(cards))

print(a - b)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
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())
data = list(map(int,input().split()))
data = sorted(data, reverse=True)
alice = 0
bob = 0
for i,var in enumerate(data):
    if i%2 == 0:    
        alice += var
    else:    
        bob += var
print(alice-bob)

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

Solution (Python):

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

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

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

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ap = 0
bp = 0
a.sort()
flag = 1
for i in range(n):
  if flag == 1:
    ap += a.pop()
  else:
    bp += a.pop()
  flag *= -1
print(ap-bp)

Solution (Python):

import io

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

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

alice = 0
for i in range(n):
    if i%2==0:
        alice+=a_inputs[i]
print(2*alice-sum(a_inputs))

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

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

alice = a[0::2]
bob = a[1::2]

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

Solution (Python):

n = int(input())
card = list(map(int,input().split()))
card.sort(reverse = True)
A,B = 0,0
for i,j in enumerate(card):
    if i % 2 == 0:
        A += j
    else:
        B += j

print(A-B)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
a.sort(reverse=True)
alc = 0
bob = 0
for i in range(n):
    if not i % 2:
        alc += a[i]
    else:
        bob += a[i]
print(alc - bob)

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

Solution (Python):

import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    b = sorted(a, reverse=True) 
    
    Alice = 0
    Bob = 0


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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
a.sort()
ans=0
k=1
for i in a:
  ans+=k*i
  k*=-1
if ans<0:
  ans*=-1
print(ans)

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().rstrip())
a = sorted([int(i) for i in input().rstrip().split(' ')], reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

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

sortedList = sorted(a,reverse=True)



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

print(ans)

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

a_i_list = list(map(int, input().split(" ")))

a_i_list_sorted = sorted(a_i_list, reverse=True)

alice_sum = 0
bob_sum = 0

for index, val in enumerate(a_i_list_sorted):
  if index % 2 == 0:
    alice_sum += val
  else:
    bob_sum += val

print(alice_sum - bob_sum)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 

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

    a.sort(reverse=True)
    ans = 0
    for i in range(len(a)):
        ans += a[i]*(-1)**i
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort(reverse=True)
    Alice = 0
    Bob = 0
    for i in range(len(A)):
        if i % 2 == 0:
            Alice += A[i]
        else:
            Bob += A[i]
    print(Alice - Bob)
main()

Solution (Python):
N=int(input())
C=list(map(int,input().split()))
D=sorted(C,reverse=True)
A=[]
B=[]
for (i,d) in enumerate(D):
    if i%2==0:
        A.append(d)
    else:
        B.append(d)
print(abs(sum(A)-sum(B)))

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
_DEC = lambda x: x-1
MIIZ = lambda: list(map(_DEC, MII()))

def main():
    n = II()
    aa = MII()
    aa.sort(reverse=True)
    alice = aa[0::2]
    bob = aa[1::2]
    print(sum(alice)-sum(bob))

if __name__ == '__main__':
    main()

Solution (Python):
if __name__ == "__main__":
    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()))

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

a.sort(reverse=True)

M = 0
m = 0

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

for i in range(1,N,2):
    m += a[i]

print(M-m)

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 = [int(s) for s in input().split()]
a.sort(reverse = True)
print(sum(a[0::2]) - sum(a[1::2]))

Solution (Python):

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

alice = 0
bob = 0

while len(a) > 0:
    alice += a.pop(0)
    if len(a) > 0:
        bob += a.pop(0)

print(alice - bob)

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

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


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

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

Solution (Python):
n = int(input())
alice = 0
bob = 0
cards = [int(val) for val in input().split()]

cards = sorted(cards, reverse=True)

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

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

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

Solution (Python):
N = input()
a = sorted(map(int, input().split()))[::-1]
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[i])
  else:
    bob.append(a[i])

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

Solution (Python):
n=int(input())
a=[0]*n
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())
arrA = list(map(int,input().split()))

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

Alice = sum(arrA[0::2])
Bob = sum(arrA[1::2])

ans = Alice-Bob

print(ans)

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

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 =alice+a[i]
	if i%2==1:
		bob = bob+a[i]
ans = alice-bob
print(ans)

Solution (Python):
import math 
N = int(input())
L = list(map(int, input().split()))

L = sorted(L, reverse=True)

Alice = 0
Bob = 0
count = 0

for i in range (0, len(L)):
	if count == 0:
		Alice+=L[i]
		count=1
	else:
		Bob+=L[i]
		count=0

print(Alice-Bob)

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

def resolve():
    N = int(input())
    S = list(map(int, input().split(" ")))
    S.sort(reverse=True)
    print(sum(S[0::2]) - sum(S[1::2]))


if '__main__' == __name__:
    resolve()

Solution (Python):


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

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    a.sort(reverse=True)
    print(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)]  
    solve(N, a)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = sorted(list(map(int,input().split())))[::-1]

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
s=[]
t=[]
s.append(a[0::2])
t.append(a[1::2])

print(sum(s[0])-sum(t[0]))

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

Solution (Python):
N = int(input())
a_input = map(int, input().split())
a = list(a_input)
alice = 0
bob = 0
for i in range(len(a)):
    max_i = 0
    max_a = 0
    for j in range(N):
        if a[j] > max_a:
            max_a = a[j]
            max_i = j
    if i%2 == 0:
        alice = alice + max_a
    else:
        bob = bob + max_a
    a[max_i] = 0
print(alice-bob)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort()
alice = 0
bob = 0
cnt = 0
for i in a:
    if cnt%2==0:
        alice += i
    else:
        bob += i
    cnt += 1

print(abs(alice-bob))

Solution (Python):
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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

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

A, B = 0, 0

for i in range(N//2):
    A += a.pop()
    B += a.pop()

if N % 2 == 1:
    A += a.pop()

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

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

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

a.sort(reverse=True)

Alice_point = 0
Bob_point = 0

for i, value in enumerate(a):
    if i % 2 == 0:
        Alice_point += value
    else:
        Bob_point += value

print(Alice_point - Bob_point)

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

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

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

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 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 = list()
Bob = list()
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):
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


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

    N = ii()
    A = sorted(il())[::-1]
    print(sum(A[::2]) - sum(A[1::2]))


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
alice = []
bob = []
for i,v in enumerate(A):
    if i%2==0:
        alice.append(v)
    else:
        bob.append(v)
print(sum(alice)-sum(bob))