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

b = sorted(a, reverse=True)

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

Solution (Python):
N=int(input())
ls=input().split()
l=[ int(v) for v in ls ]

l.sort(reverse=True)

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

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

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

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

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

ali_sum = 0
bob_sum = 0

for index, card in enumerate(sorted(card_list)):
    if index % 2 == 1:
        ali_sum +=  card
    else:
        bob_sum += card

print(abs(ali_sum - bob_sum))

Solution (Python):
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

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

print(alice-bob)

Solution (Python):


num = int(input())
s = sorted(list(map(int,input().split())),reverse=True)
alice,bob = 0,0
for i,j in enumerate(s):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
print(alice - bob)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
cntA = 0
cntB = 0
flag = 0
for a in A:
    if flag == 0:
        cntA += a
        flag = 1
    else:
        cntB += a
        flag = 0
print(cntA-cntB)

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

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

for i in range(n):
    sum_a += max(a)
    a[a.index(max(a))] = 0
    sum_b += max(a)
    a[a.index(max(a))] = 0

print(sum_a - sum_b)

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

sorted_nums = sorted(nums, reverse=True)

a = 0
b = 0

def calSumOfDig(n):
    total = 0
    for i in n:
        total += i
    return total


ls = calSumOfDig(sorted_nums[0::2]) - calSumOfDig(sorted_nums[1::2])

print(ls)

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections








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



alice = 0
bob = 0

A.sort(reverse=True)
for i in range(0,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()))
s_a=sorted(a)[::-1]
print(sum(s_a[::2])-sum(s_a[1::2]))

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a, reverse=True)
    alice = 0
    bob = 0
    for i in range(n):
        if i % 2 == 0:
            alice += a_sort[i]
        else:
            bob += a_sort[i]
    res = alice - bob
    print(res)
if __name__ == '__main__':
    main()

Solution (Python):


import sys

















from heapq import heapify, heappush, heappop 












def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L = list(map(lambda x: -x, L))
    heapify(L)

    alice = 0
    bob = 0
    alice_turn = True
    while L:
        num = - heappop(L)
        if alice_turn:
            alice += num
        else:
            bob += num
        alice_turn = not alice_turn
    print(alice - bob)



if __name__ == "__main__":
    main()

Solution (Python):



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


alice,bob = 0,0
for i,j in enumerate(s):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
        
print(alice - bob)

Solution (Python):
N = int(input())
a = [0]*N
tmp = input().split()
for i in range(N):
    a[i] = int(tmp[i])

a.sort(reverse=True)
A = B = 0


for i in range(0,N//2):
    A += a[2*i]
    B += a[2*i+1]
if N%2 == 1:
    A += a[N-1]

print(A-B)

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

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

print(sumA-sumB)

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

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

score_a = 0
score_b = 0

while len(A):
	max_i = A.index(max(A))
	score_a += A.pop(max_i)

	if len(A):
		max_i = A.index(max(A))
		score_b += A.pop(max_i)

print(score_a - score_b)

Solution (Python):
N = int(input())
a = sorted(list(map(int, input().split())))[::-1]
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):
num = int(input())
alist = input().split(" ")
alist = list(map(int,alist))

def max_number(l):
    sum = max(l)
    l.remove(sum)
    return sum

def alice_bob(n,m):
    q = 0
    a = 0
    b = 0
    while q <= n-1:
        temp = max_number(m)
        a += temp
        temp = 0
        q += 1
        if q <= n-1:
            temp = max_number(m)
            b += temp
            temp = 0
            q += 1
    sub = a-b
    return sub

ans = alice_bob(num,alist)
print(ans)

Solution (Python):
input()
l=sorted(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()
for i in range(n):
    if i%2==0:
        alice += a[-1]
        a.pop()
    elif i%2==1:
        bob += a[-1]
        a.pop()
print(alice-bob)

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

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    ans = 0
    for i, num in enumerate(sorted(a)[::-1]):
        if i % 2 == 0:
            ans += num
        else:
            ans -= num
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)


if __name__ == "__main__":
    main()

Solution (Python):






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





a_s = sorted(a, reverse=True)
alice = sum(a_s[::2])
bob = sum(a_s[1::2])
print(alice-bob)

Solution (Python):
N = int(input())
a = [int(k) for k in input().split()]
a.sort(reverse = True)
sub = 0

for i in range(N//2):
    sub += a[2*i] - a[2*i +1]
if (N%2 == 1):
    sub += a[-1]

print(sub)

Solution (Python):

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

a.sort(reverse=True)
alice=a[::2]
alice=sum(alice)

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

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

a=sorted(a, reverse=True)
A=[]
B=[]

for i in range(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(map(int, input().split()), reverse=True)
alice = 0
bob = 0
for i, v in enumerate(a):
  if i & 1:
  	bob += v
  else:
    alice += v
 
print(alice - bob)

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

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

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

Solution (Python):
def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


N = ii()
a = li()

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

alice, bob = 0, 0

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

print(alice - bob)

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

a = sorted(a, reverse=True)

for i in range(0,N,2):
    Alice += a[i]
    if i == N - 1:
        continue
    Bob +=a[i + 1]

print(Alice - Bob)

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

card.sort(reverse=True)

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

print(alice - bob)

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

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

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
x = A[::2]
print(sum(x) - (sum(A) - sum(x)))

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

Solution (Python):
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a = LI()
a = sorted(a)

d = a

x = 0
y = 0
flag = 0
while len(d) != 0:
    if flag == 0:
        x += d.pop()
        flag = 1
    elif flag == 1:
        y += d.pop()
        flag = 0
print(x-y)

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

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

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

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())
Z = list(map(int, input().split()))
Z.sort(reverse=True)
A = sum([Z[i] if i % 2 == 0 else 0 for i in range(N)])
B = sum([Z[i] if i % 2 == 1 else 0 for i in range(N)])
print(A-B)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for e, i in enumerate(a):
    if e % 2 != 0:
        ans += i
    else:
        ans -= i

print (abs(ans))

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

print(abs(sum(A)-sum(B)))

Solution (Python):
N=int(input())
a=list(map(int, input().split()))
b=sorted(a,reverse=True)
pnt=0
for i in range(N):
  pnt+=b[i]*(1-(i%2)*2)
print(pnt)

Solution (Python):

N = int(input())
A = [int(a) for a in 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())
card = list(map(int,input().split()))
sorted_card = sorted(card,reverse=True)
Alice = 0
Bob = 0

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

print(Alice - Bob)

Solution (Python):
n = int(input())
cards = map(int, input().split(' '))
sorted_cards = sorted(cards,reverse=True)

alice_sum = 0
bob_sum = 0
for i in range(n):
    if i % 2 == 0:
        alice_sum += sorted_cards[i]
    else:
        bob_sum += sorted_cards[i]

print(alice_sum - bob_sum)

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    Alice = A[::-2]
    Bob = A[N-2::-2]
    print(sum(Alice)-sum(Bob))
resolve()

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())
c=sorted([int(i) for i in input().split()])[::-1]
a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(c[i])
    else:
        b.append(c[i])
print(sum(a)-sum(b))

Solution (Python):

n = int(input())
array = list(map(int, input().strip().split()))

alice_total = 0
bob_total = 0

for i in range(len(array)):
    if i % 2 == 0:
        max_value = max(array)
        max_index = array.index(max_value)
        alice_total += array.pop(max_index)
    else:
        max_value = max(array)
        max_index = array.index(max_value)
        bob_total += array.pop(max_index)

print(alice_total - bob_total)

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

A =sorted(A, reverse=True)
Alice = 0
Bob = 0

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

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

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

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

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

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

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

alice = 0
bob = 0

a.sort(reverse=True)

turn = "alice"

for p in a :
    if turn == "alice" :
        alice = alice + p
        turn = "bob"
    elif turn == "bob" :
        bob = bob + p
        turn = "alice"

print(str(alice - 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(len(a_list)):
    if i % 2 == 0:
        Alice += a_list[i]
    else:
        Bob += a_list[i]

print(Alice-Bob)

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(abs(sum(Alice) - sum(Bob)))

Solution (Python):
N=int(input())
a_input_list=input().split(' ')
a_num_list=[]
for a in a_input_list:
  a_num_list.append(int(a))

a_num_list.sort()
a_num_list.reverse()

bob=0
allice=0

counter=0
for a in a_num_list:
  if counter%2==0:
    allice+=a
  else:
    bob+=a
  counter+=1

print(allice-bob)

Solution (Python):
N=input()
a=list(map(int,input().split()))
a.sort(reverse = True)
Alice,Bob=0,0
while len(a) != 0:
  if len(a) != 0:
     Alice+=a.pop(0)
  if len(a) != 0:
     Bob += a.pop(0)
print(Alice-Bob)

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

for i in range(n):
    a = sorted(a,reverse = True)
    x.append(a[0])
    y.append(a[1])
    a[0],a[1] = 0,0

print(sum(x)-sum(y))

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

n = int(readline())
a = sorted(map(int, readline().split()))

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

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

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

alice = []
bob = []

a.sort(reverse=True)

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

ans = sum(alice) - sum(bob)

print(ans)

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

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

a = sorted(a, reverse=True)

Alice = 0
Bob = 0

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


print(Alice-Bob)

Solution (Python):

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

N = int(readline())
A = list(map(int, readline().split()))
A.sort(reverse=True)

alice = bob = 0

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

print(alice - bob)

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

k = -1
sum1 = 0
sum2 = 0
for i in A:
  if k==-1:
    sum1+=i
  else:
    sum2+=i
  k*=-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(len(a)):
  if i%2 ==0 :
    alice+=a[i]
  else:
    bob+=a[i]
print(alice-bob)

Solution (Python):
N = int(input())
a = [int(x) for x 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):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9 +7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


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





N = inputI()
l = inputIL()

l.sort(reverse=True)

A = l[::2]
B = l[1::2]

print(sum(A)-sum(B))

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

A.sort(reverse=True)
ali=0
bob=0

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

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

Solution (Python):

def inp():
    return(int(input()))



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


n = inp()

arr = inlt()

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

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

a = sorted(a, reverse=True)
ans = a[0]
m = 1
for i in range(1,n):
    m *= -1
    ans += m * a[i]

print(ans)

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

b=list(map(int, input().split()))
b.sort(reverse=True)
alice=0
bob=0
c=iter(b)
for i in c:
    alice+=i
    try:
    	bob+=next(c)
    except:
      break
print(alice-bob)

Solution (Python):
import math
from collections import deque
from collections import defaultdict

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

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

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

		if x==y:
			return

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

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

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

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

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

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

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

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

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

Solution (Python):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split()))) * (-1)
a.sort()
print(-1 * (sum(a[0::2]) - sum(a[1::2])))

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

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=sorted(a)
a=list(reversed(a))
ans=0
ans+=sum(a[0:N+1:2])-sum(a[1:N+1:2])
print(ans)

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

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

Alice=0
Bob=0
a.sort()

h=len(a)
for i in range(h):
    if len(a)>0:
        Alice+=a[-1]
        del a[-1]
        h-=1
    if len(a)>0:
        Bob+=a[-1]
        del a[-1]
        h-=1
print(Alice-Bob)

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

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

aliceSum = sum(cards[-1::-2])
bobSum = sum(cards[-2::-2])

print(aliceSum - bobSum)

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

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

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

Solution (Python):
def main():
    N=int(input())
    a=list(map(int,input().strip().split()))
    
    a.sort(reverse=True)
    
    alice=sum(a[n] for n in range(N) if n%2==0)
    bob=sum(a[n] for n in range(N) if n%2==1)
    return alice-bob

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

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

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

a.sort(reverse=True)

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

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    k = [int(i) for i in input().split()]
    a = 0
    b = 0
    k.sort(reverse=True)
    flag = True
    for i in k:
        if flag == True:
            a+=i
            flag=False
        else:
            b+=i
            flag=True
    print(a-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]"):
    alice = 0
    bob = 0
    loop = 0
    while(a):
        loop = loop + 1
        get = max(a)
        a.remove(get)
        if loop % 2:
            alice = alice + get
        else:
            bob = bob + get
    return(alice - bob)



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

if __name__ == '__main__':
    main()

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

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

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

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

diff = A - B
print(diff)

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

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

alice = []
bob = []

for tmp in range(num):
    if tmp % 2 == 0:
        alice.append(max(cards))
        cards.pop(cards.index(max(cards)))
        continue
    bob.append(max(cards))
    cards.pop(cards.index(max(cards)))

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

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

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

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

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

Solution (Python):
import numpy as np

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

Alice = np.array(Alice)
Bob = np.array(Bob)

ans = np.abs(np.sum(Alice) -np.sum(Bob))

print(ans)

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

a = [0]*n


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

alice = 0
bob = 0
m = 0

for i in range(0,n):
  if(i%2 == 0):
    m = max(b)
    alice = alice + m
    k = b.index(m)
    del b[k]
  else:
    m = max(b)
    bob = bob + m
    k = b.index(m)
    del b[k]
print(alice-bob)