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

int_list.sort(reverse=True)
odd = int_list[::2]
even = int_list[1::2]
print(sum(odd)-sum(even))

Solution (Python):

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

a = sorted(a, reverse = True)

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

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

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

a.sort(reverse=True)
A=a[::2]
B=a[1::2]
print(sum(A)-sum(B))

Solution (Python):
import re
import sys
from collections import *
from functools import lru_cache
from heapq import *
from itertools import *

INF=float('inf')

sys.setrecursionlimit(2**31-1)

rfs=lambda:rl().split()
ri=lambda:int(rl())
ris=lambda:list(map(int,rfs()))
rl=lambda:next(sys.stdin)
rrs=lambda:list(map(str.strip,sys.stdin))
rs=lambda:rl().strip()
rt=lambda:sys.stdin.read()
rg=lambda:list(map(list,rrs()))

def n4(i,j):
    return [
                (i-1,j),
        (i,j+1),        (i,j-1),
                (i+1,j),
    ]

def n8(i,j):
    return [
        (i-1,j-1),(i-1,j),(i-1,j+1),
        (  i,j-1),        (  i,j+1),
        (i+1,j-1),(i+1,j),(i+1,j+1),
    ]

inb=lambda i,j,m,n:0<=i<m and 0<=j<n



N,a=ri(),ris()
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))

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

Solution (Python):

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

Alice = []
Bob = []
while len(an) > 0:
    Alice.append(max(an))
    del an[an.index(max(an))]
    if len(an) > 0:
        Bob.append(max(an))
        del an[an.index(max(an))]
    else:
        break

k = 0
j = 0
for i in range(len(Alice)):
    k += Alice[i]
for i in range(len(Bob)):
    j += Bob[i]

print(str(k-j))

Solution (Python):
n=int(input())
A=[int(x) for x in input().split()]
B=sorted(A)
Alice=[]
Bob=[]
while len(B)!=0 and len(B)!=1:
  Alice.append(B[-1])
  B.pop()
  Bob.append(B[-1])
  B.pop()
if len(B)==1:
  Alice.append(B[0])
  B.pop()
print(sum(Alice)-sum(Bob))

Solution (Python):
import math


def resolve():
    import sys
    input = sys.stdin.readline
    
    n = int(input().rstrip())
    a_list = [int(x) for x in input().rstrip().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)

if __name__ == "__main__":
    resolve()

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

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

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

Solution (Python):
n = int(input())
a = 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):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort(reverse=True)

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

    return


if __name__ == '__main__':
    main()

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=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 = [int(s) for s in input().split()]

A.sort(reverse=True)

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

print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
p1, p2 = 0, 0
for i in range(N):
	max_A = max(A)
	if i % 2 == 0:
		p1 += max_A
	else:
		p2 += max_A
	A.remove(max_A)
print(p1 - p2)

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

alice = 0
bob = 0
A.sort()

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

print(abs(alice - bob))

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

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

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

Solution (Python):
n,*x=map(int,open(0).read().split());a=0;t=1;x.sort()
while x:a+=t*x.pop();t*=-1
print(a)

Solution (Python):

N,*list1 = open(0).read().split()

N=int(N)



list1=[int(i) for i in list1]

list1.sort(reverse=True)



aaa=[]

bbb=[]


for i,n in enumerate(list1):
    if (i+1)%2 == 1:
        aaa.append(list1[i])
    else:
        bbb.append(list1[i])






print(sum(aaa)-sum(bbb))

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

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

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

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from math import ceil

n=ni()
a=nl()

sa = sorted(a)[::-1]
aa = []
bb = []
for i in range(n):
  if i%2==0:
    aa.append(sa[i])
  else:
    bb.append(sa[i])

print(sum(aa)-sum(bb))

Solution (Python):
n = int(input())
an = list(map(int,input().split()))
a = sorted(an, 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 math
n = input()
N = map(int, input().split())
N = sorted(list(N), reverse=True)

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

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
sumA = 0
sumB = 0
for i in range(1,N+1):
    m = max(a)
    if i%2 == 1:
        sumA += m
    else:
        sumB += m
    a.remove(m)

print(sumA-sumB)

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

Solution (Python):

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

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

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

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

Solution (Python):
n,*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()))
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(reverse=True)
pt=0
for i in a[::2]:
  pt+=i
for i in a[1::2]:
  pt-=i
print(pt)

Solution (Python):
n,s = int(raw_input()),map(int,raw_input().split())
s.sort(key = lambda x:-x)
print sum(s[0:n:2]) - sum(s[1:n:2])

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

Solution (Python):
N = int(input())
if N == 1:
  print(input())
else:
  A = 0
  B = 0
  a = list(map(int,input().split()))
  a.sort()
  a.reverse()
  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 = sorted([int(X) for X in 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)
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())
Ali = list(map(int,input().split()))

Ali.sort(reverse = True)

AP = BP = 0

for i in range(N):
  if i%2 == 0:
    AP += Ali[i]
  else:
    BP += Ali[i]

print(AP-BP)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
for i in range(N):
    if i % 2 == 0:
        A = max(a)
        Alice = Alice + A
        a.remove(A)
    else:
        A =max(a)
        Bob = Bob + A
        a.remove(A)
print(Alice - Bob)

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

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

a = list(map(int, a))
a.sort(reverse=True)
alice_n = a[::2]
bob_n = a[1::2]

print(sum(alice_n) - sum(bob_n))

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

alice_number=[]
for i in range(n):
    if i%2==1:
        continue
    alice_number.append(new_list[i])

bob_number=[]
for i in range(n):
    if i%2==0:
        continue
    bob_number.append(new_list[i])

result=sum(alice_number)-sum(bob_number)
print(result)

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

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

print(alice - bob)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
A = []
for i in a[::2]:
    A.append(i)
print(sum(A)*2-sum(a))

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

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

alice = 0
bob = 0

for n in range(N):
    if len(a) == 0:
        break
    card = max(a)
    alice += card
    a.remove(card)
    if len(a) == 0:
        break
    card = max(a)
    bob += card
    a.remove(card)

print(alice - bob)

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

alice = 0
bob = 0

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

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

Bob=0
Alice=0

a.sort(reverse=True)
for i in range(N):
    if i%2 == 1:
        Bob = Bob + a[i]
    else:
        Alice = Alice + a[i]
print(Alice-Bob)

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

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(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=list(map(int,input().split()))
a_sorted=sorted(a,reverse=True)
diff=0
if n%2==0:
  for i in range(n//2):
    diff+=a_sorted[2*i]-a_sorted[2*i+1]
  print(diff)
else:
  for i in range(n//2):
    diff+=a_sorted[2*i]-a_sorted[2*i+1]
  print(diff+a_sorted[-1])

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

a.sort(reverse=True)

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

print(ansA-ansB)

Solution (Python):
N =int(input())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
alice = l[0::2]
bob = l[1::2]
print(sum(alice) - sum(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(n):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]
print(alice - bob)

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

Alice_point = 0
Bob_point = 0
Alice_flag = 1
Bob_flag = 0
for _ in range(n):
    if Alice_flag:
        Alice_point+=max(numbers)
        numbers.remove(max(numbers))
        Alice_flag=0
        Bob_flag=1
    elif Bob_flag:
        Bob_point+=max(numbers)
        numbers.remove(max(numbers))
        Alice_flag=1
        Bob_flag=0

print(Alice_point-Bob_point)

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

Solution (Python):
N = int(input())
li = list(map(int,input().split()))
li.sort()
li = li[::-1]

Alice = li[0::2]
Bob = li[1::2]

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

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

Solution (Python):


N = int(input())
A = sorted([int(a) for a in input().split()], reverse=True)

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

print(ans)

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

A_sort = sorted(A, reverse=True)
Alice = [a for i, a in enumerate(A_sort) if i%2==0]
Bob = [a for i, a in enumerate(A_sort) if i%2==1]

ans = sum(Alice) - sum(Bob)

print(ans)

Solution (Python):
from sys import stdin

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

A.sort(reverse=True)

N=M=0

for i in range(0,len(A),2):
    N = N + A[i]

for i in range(1, len(A), 2):
    M = M + A[i]

print (N-M)

Solution (Python):
n = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)
alice = []
bob = []
for i in range(0, n, 2):
    alice.append(cards[i])
    try:
        bob.append(cards[i+1])
    except:
        break
print(sum(alice) - sum(bob))

Solution (Python):
n = int(input())
cards = [i for i in map(int, input().split())]
alice = []
bob = []
for i in range(n):
    if i % 2 == 0:
        alice.append(max(cards))
        cards.pop(cards.index(max(cards)))
    else:
        bob.append(max(cards))
        cards.pop(cards.index(max(cards)))
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):
N = int(input())
A = list(map(int, input().split()))

alice = 0
bob = 0

A_rev = sorted(A, reverse=True)

while True:
    if len(A_rev) != 0:
        alice += A_rev.pop(0)
    
    if len(A_rev) != 0:
        bob += A_rev.pop(0)
    
    if len(A_rev) == 0:
       break
 
print(alice - bob)

Solution (Python):
N = input()
MM = input().split()
list1 =[]
for i in MM:
  x = int(i)
  list1.append(x)
list1.sort(reverse = True)
total = 0
for i in range(len(list1)):
  if i%2 ==0:
    total += list1[i]
  else:
    total -= list1[i]
print(total)

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

num_lists.sort()
num_lists.reverse()
alice_num_lists = []
bob_num_lists = []

for i in range(n):
  if i%2 == 0:
    alice_num_lists.append(num_lists[i])
  else:
    bob_num_lists.append(num_lists[i])

alice_score = 0
bob_score = 0
for i in alice_num_lists:
  alice_score += i
for i in bob_num_lists:
  bob_score += i

print(alice_score - bob_score)

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

Solution (Python):
n = int(input())
array = list(map(int,input().split()))
a = b = 0
for i, m in enumerate(sorted(array, reverse=True)):
    if i == 0 or i % 2 == 0:
        a += m
    if i % 2 != 0:
        b += m
print(a-b)

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

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

a.sort(reverse=True)

score_a = a[::2]
score_b = a[1:][::2]

print(sum(score_a) - sum(score_b))

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

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


diff = sum(c[::2])-sum(c[1::2])
print(diff)

Solution (Python):
N=input()
N=int(N)
ls=[int(s) for s in input().split()]
ls=sorted(ls,reverse=True)
A=0
B=0
i=0
while i<N:
  if i%2==0:
    A=A+ls[i]
  if i%2==1:
    B=B+ls[i]
  i=i+1
print(A-B)

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

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

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

a = 0
b = 0
while len(L):
    a += L.pop(L.index(max(L)))
    if len(L) == 0: break;
    b += L.pop(L.index(max(L)))

print(abs(a-b))

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


sort_A = sorted(A,reverse=True)


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

print(Alice - Bob)

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

    else:
        bob+=a[i]
    c+=1
print(alice-bob)

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):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    a.sort(reverse=True)
    alice = sum(a[::2])
    bob = sum(a[1::2])
    print(alice - bob)


if __name__ == '__main__':
    main()

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


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N = int(input())
    a = sorted(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)


if __name__ == "__main__":
    main()

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

Solution (Python):
n = map( int, input())
a = list(map( int, input().split() ))
A_point = 0
B_point = 0
flag = 1

a.sort(reverse=True)

for point in a:
    if flag%2 == 1:
        A_point += point
        flag += 1
    elif flag%2 == 0:
        B_point += point
        flag += 1

print("{}".format(A_point-B_point))

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

Solution (Python):


n = int(input())

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

print(sum([((-1)**(i%2))*a for i, a in enumerate(l_a)]))

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

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 = list(map(int, input().split()))
a = sorted(a, reverse=True)
alice = 0
bob = 0
for i, el in enumerate(a):
    if i % 2 == 0:
        alice += el
    else:
        bob += el
print(alice - bob)

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

Solution (Python):
X = int(input())
A = list(map(int, input().split()))
list.sort(A, reverse=True)
B=0
C=0
ans = 0
for i,j in enumerate(A):
    if (i+1)%2 != 0:
        B+=j
    else :
        C+=j
ans = B-C
print(ans)

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 = list(map(int, input().split()))
A.sort(reverse=True)
Alice = 0
for i in range(0,N,2):
    Alice += A[i]
Bob = sum(A) - Alice
print(Alice - Bob)

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

print(ans)

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

print((alice_num)-(bob_num))

Solution (Python):
n = int(input())
data = input().split()

int_data = [int(int_data) for int_data in data]
int_data.sort(reverse=True)

Alice = 0
Bob = 0

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

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

a.sort()

alice = 0
bob = 0


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

print(abs(alice-bob))

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

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

AN.sort(reverse=True)

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

print (alice - bob)

Solution (Python):
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for i, j in enumerate(a):
    if i&1 is 0: ans += j
    else: ans -= j
print(ans)

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

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

Solution (Python):


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

Alice = 0
Bob = 0

for x in range(0, len(a), 2):
    Alice += a[x]

for x in range(1, len(a), 2):
    Bob += a[x]

print(Alice - Bob)

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

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

A.sort(reverse=True)

Alice = 0
Bob = 0

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

print(Alice - Bob)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    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]
        if i % 2 != 0: bob += A[i]
    print(alice - bob)

if __name__ == "__main__":
    main()

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

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

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

print(A-B)

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

Solution (Python):


N = int(input())
x = list(map(int,input().split()))
x = sorted(x, reverse=True)
a = 0
b = 0
ans = 0

if N % 2 == 0:
    for i in range(N//2):
        a += x[2*i]
        b += x[2*i + 1]
    ans = a-b
else:
    for i in range((N-1)//2):
        a +=  x[2*i]
        b +=  x[2*i + 1]
    ans = a+ x[-1] - b
    
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
asum=0
bsum=0
cnt=0
while True:
    asum+=max(A)
    A.remove(max(A))
    cnt+=1
    if cnt==N:
        break
    bsum+=max(A)
    A.remove(max(A))
    cnt+=1
    if cnt==N:
        break

print(asum-bsum)

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

a.sort(reverse=True)
if n%2 == 1:
    a.append(0)
    n += 1
ans = 0
for i in range(n//2):
    ans += a[2*i]
    ans -= a[2*i+1]
print(ans)

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

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

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

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

list.sort(a, reverse=True)
for i in range(math.ceil(n/2)):
	alice += a[i*2]
for i in range(math.floor(n/2)):
	Bob += a[i*2 + 1]
print(alice - Bob)

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

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

Solution (Python):

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

A.sort(reverse = True)

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

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

a.sort(reverse=True)

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

print(ans - ans2)

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

score.sort(reverse=True)
Alice = []
Bob = []
for i in range(len(score)):
  if i%2==0:
    Alice.append(score[i])
  else:
    Bob.append(score[i])
    
print(sum(Alice)-sum(Bob))

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

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

alice = 0
bob = 0

while len(a) != 0:
    alice += max(a)
    a.remove(max(a))
    if len(a) == 0:
        break
    bob += max(a)
    a.remove(max(a))

print(alice-bob)

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
for i in range(N):
    if i % 2 == 0:
        A = max(a)
        Alice = Alice + A
        a.remove(A)
    else:
        A =max(a)
        Bob = Bob + A
        a.remove(A)
print(Alice - Bob)

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

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

for i in range(N):
    ans=sum([a[i]*((-1)**i) for i in range(N)])
print(ans)