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())
li=list(input().split(" "))
for g in range(n):
    li[g]=int(li[g])
ali=0
bob=0
li.sort()
li.reverse()
for i in range(n):
    if i%2==0:
        ali+=li[i]
    else:
        bob+=li[i]
print(abs(ali-bob))

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


Alice = 0
Bob = 0

A.sort(reverse=True)

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

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

A=B=I=0
for i in a:
    if I %2:B+=i
    else:A+=i
    I+=1

print(A-B)

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

A=B=I=0
for i in a:
    if I %2:B+=i
    else:A+=i
    I+=1

print(A-B)

Solution (Python):
"""
Created on Wed Jan  1 17:06:59 2020
"""

n = int(input())
l = list(map(int, input().split()))
l.sort()
l.reverse()
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())
li=list(map(int,input().split()))

li_sorted=sorted(li, reverse=True)
sum=0
for i in range(N):
    if i%2==1:
        sum+=-1*li_sorted[i]
    else:
        sum+=li_sorted[i]
        
print(sum)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=True)
x = []
y = []
for i in range(len(a)):
    if i%2==0:
        x.append(a[i])
    else:
        y.append(a[i])
print(sum(x)-sum(y))

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:
        ans -= a[i]
    else:
        ans += a[i]
print(ans)

Solution (Python):
n=int(input())
a=list(reversed(sorted([int(i) for i in input().split()])))
sum=0
for i in range(n):
  if i%2==0:
    sum += a[i]
  else:
    sum -= a[i]
print(sum)

Solution (Python):
n=int(input())
cards=sorted(map(int, input().split()), reverse=True)
a=1
b=0
Alice=0
Bob=0
for i in cards:
    if a == 1 and b == 0:
       Alice+=i
       a=0
       b=1
    elif a == 0 and b == 1:
       Bob+=i
       a=1
       b=0
print(Alice-Bob)

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

ans = alice-bob
print(ans)

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

a_i.sort(reverse = True)

L_a = []
L_b = []

for i in range(0, N, 2):
    L_a.append(a_i[i])

for i in range(1, N, 2):
    L_b.append(a_i[i])

print(sum(L_a) - sum(L_b))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=0
y=0
for i in range(0,n,2):
    x+=a[i]
for i in range(1,n,2):
    y+=a[i]

print(abs(x-y))

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

Solution (Python):
def get(S):
    return list(map(S, input().split()))

[N] = get(int)
A = get(int)
A = sorted(A)

Alice = sum(A[-1::-2])
Bob = sum(A[-2::-2])

print(Alice - Bob)

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

Solution (Python):

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

Solution (Python):

import sys


def main():
  n = int(input())
  card = sorted(list(map(int, input().split(' '))), reverse=True)
  A = []
  B = []
  
  for i in range(n):
    if i % 2 == 0:
      A.append(card[i])
    
    else:
      B.append(card[i])
      
  print(sum(A) - sum(B))
  
  return 0


if __name__ == '__main__':
  main()

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

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    A = sc.intarr()

    new = sorted(A, reverse=True)
    alice = 0

    for i in range(0, N):
        if i % 2 == 0:
            alice += new[i]
        else:
            alice -= new[i]

    print(alice)


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  
    while b:
        a, b = b, a % b
    return a


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


main()

Solution (Python):
num = input()
nums = [int(x) for x  in input().split()]
nums = sorted(nums, reverse=True)
alice = sum(nums[::2])
bob = sum(nums[1::2])
print(alice-bob)

Solution (Python):

N = int(input())

cards = [data for i, data in enumerate(sorted(map(int, input().split(" ")), reverse=True))]
print(sum(cards[0::2]) - sum(cards[1::2]))

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

sortedList = sorted(li, reverse=True)

alice = 0
bob = 0
turn = 1

while(len(sortedList)):
  if turn % 2 == 1:
    alice += sortedList.pop(0)
  else:
    bob += sortedList.pop(0)
  
  turn += 1

print(alice - bob)

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

alice = 0
bob = 0
for n, a in enumerate(sorted(a_list, reverse=True)):
    if n % 2 == 0:
        alice += a
    else:
        bob += a

print(alice-bob)

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    a.sort(reverse=True)
    return sum(a[::2]) - sum(a[1::2])

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
SA = sorted(A,reverse=True)
ALI =0
BOB=0
for i in range(0,N,2):
    ALI += int(SA[i])
for n in range(1,N,2):
    BOB += int(SA[n])
ans = ALI - BOB
print(ans)

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

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

print(abs(A-B))

Solution (Python):
num = int(input())
num_list = [int(i) for i in input().split()]


num_list.sort(reverse = True)

senkou = 0
koukou = 0
for i in range(num):
    if i % 2 == 0:
        senkou += num_list[i]
    else:
        koukou += num_list[i]

result = senkou - koukou
print(result)

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())
num_list = list(map(int, input().split()))
num_list.sort(reverse=True)
result = 0
for i in range(0, len(num_list), 2):
    result += num_list[i]

for i in range(1, len(num_list), 2):
    result -= num_list[i]

print(result)

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

Solution (Python):


n=int(input())

A=[int(i) for i in 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)

"""
2
3 1

2

3
2 7 4

5

4
20 18 2 18

18
"""

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A_res = 0
B_res = 0
for i in range(N):
    if i % 2 == 1:
        A_res += max(A)
    else:
        B_res += max(A)
    del A[A.index(max(A))]

print(B_res - A_res)

Solution (Python):
N = int(input())
a = list(map(int ,input().split()))
A = 0
B = 0
for i in range(N) :
    A += max(list(a))
    a.remove(max(list(a)))
    a.append(0)
    B += max(list(a))
    a.remove(max(list(a)))
    a.append(0)



print(A - B)

Solution (Python):
n = int(input())
x = input()
a = sorted([int(i) for i in x.split()])[::-1]
alice = sum([i for n,i in enumerate(a) if n%2==0])
bob = sum([i for n,i in enumerate(a) if n%2!=0])
print(alice-bob)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
alice = 0
bob = 0

l.sort(reverse = True)

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

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

Alice = [a[i] for i in range(0, len(a), 2)]

Bob = [a[i] for i in range(1, len(a), 2)]

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

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

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

Solution (Python):
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().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()))

NewA = sorted(A, reverse=True)

Alice = 0
Bob = 0 

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


print((Alice)-(Bob))

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

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

A = 0
B = 0
idx = 0
for card in cards:
    if idx % 2 == 0:
        A += card
    else:
        B += card
    idx += 1
result = A - B
print(result)

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

alice = 0
bob = 0

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

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

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

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

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

a.sort(reverse=True)
b = a[::2]
c = a[1::2]

print(sum(b) - sum(c))

Solution (Python):
n = int (input())
list_num= [int(i) for i in input().split()]
list_num = sorted(list_num, reverse=True)
num_a = list_num[::2]
num_b = list_num[1::2]
print(sum(num_a)-sum(num_b))

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

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

a_sorted_list = sorted(a_list, reverse=True)

score_Alice = 0
score_Bob = 0

for i in range(N):
  if i % 2 == 0:
    score_Alice += a_sorted_list[i]
  else:
    score_Bob += a_sorted_list[i]

print(score_Alice - score_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= list(map(int,input().split()))
An_list.sort()
An_list.reverse()

Alice=0
Bob=0

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

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

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

if A > B:
  print(A-B)
else:
  print(B-A)

Solution (Python):
N = int(input())
li = list(map(int, input().split()))
lili = sorted(li)
lili.reverse()
score = 0
isA = 1
for i in lili:
    if isA % 2 == 1:
        score += i
    else:
        score -= i
    isA += 1
print(score)

Solution (Python):

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

Solution (Python):

N = int(input())
a = 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())
List = list(map(int,input().split()))
A = []
B = []
List = sorted(List,reverse=True)
for i in range(len(List)):
  if i%2 == 0:
    A.append(List[i])
  else:
    B.append(List[i])
Answer = sum(A) - sum(B)
print(Answer)

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
B = []
for i in range(0,N,2):
  B.append(A[i])
print(abs((sum(A)-sum(B))-sum(B)))

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

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

alice=0
bob=0
for _ in range(N):
    alice += max(ans)
    ans.remove(max(ans))
    if len(ans) == 0:
        break
    bob += max(ans)
    ans.remove(max(ans))
    if len(ans) == 0:
        break

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(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)
print(sum(a[::2])-sum(a[1::2]))

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    suma = 0
    sumb = 0
    fixL = sorted(a, reverse=True)
    for i in range(N):
        if i % 2 == 0:
            suma += fixL[i]
        else:
            sumb += fixL[i]
    print(suma - sumb)
    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())
line = sorted(list(map(int,input().split())),reverse = True)
alice = 0
bob = 0
if n % 2 == 0:
  for i in range(0,n-1,2):
    alice += line[i]
  for j in range(1,n,2):
    bob += line[j]
else:
  for i in range(0,n,2):
    alice += line[i]
  for j in range(1,n-1,2):
    bob += line[j]
  
print(alice - bob)

Solution (Python):


n = int(input())

nums = list(map(int,input().split(' ')))
nums = sorted(nums, reverse=True)
diff = 0
for i in range(n):
  if i % 2 == 0:
    diff += nums[i]
  else:
    diff -= nums[i]
print(diff)

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

alice = []
bob = []
i = 2
while True:
    mx = max(a)
    if i % 2 == 0:
        alice.append(mx)
    else:
        bob.append(mx)
    a.remove(mx)
    i+=1
    if len(a) == 0:
        break

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

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)
        del a[a.index(max(a))]
    else :
        bob += max(a)
        del a[a.index(max(a))]
print(alice - bob)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
ab = [0, 0]
is_alice = True
while len(A) != 0:
    now = A.pop()
    if is_alice:
        ab[0] += now
        is_alice = False
    else:
        ab[1] += now
        is_alice = True
print(ab[0] - ab[1])

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

Alice = 0
Bob = 0

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

print(Alice - Bob)

Solution (Python):
n=input().rstrip()
n=int(n)
a=input().split()
k=0
li=[]
while k<n:
    b=int(a[k])
    li.append(b)
    k+=1
c=tuple(sorted(li,reverse=True))
h=0
sb=0
while 2*h+1<=n-1:
    sb+=c[2*h+1]
    h+=1
h=0
sa=0
while 2*h<=n-1:
    sa+=c[2*h]
    h+=1
d=sa-sb
print(d)

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

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



alice = []
bob = []
a_sorted = sorted(a)


while len(a_sorted) != 0:
    max = a_sorted.pop()
    
    alice.append(max)
    if(len(a_sorted) != 0):
        max = a_sorted.pop()
        bob.append(max)



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

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

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

print(ans)

Solution (Python):
import heapq
n = int(input())
A = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(A)


al = []
bo = []
for i in range(n):
  if i % 2 == 0:
    al.append(heapq.heappop(A)*(-1))
  else:
    bo.append(heapq.heappop(A)*(-1))
print(sum(al)-sum(bo))

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

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

print(a-b)

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

number = iter(number_list)

a = 0
b = 0

for i in range(int(n)):
    if i % 2 == 0:
        a += int(next(number))
    else:
        b += int(next(number))

print(a-b)

Solution (Python):
n=int(input())
alice=[]
bob=[]
l=list(map(int,input().split()))
while len(l)>0:
    alice.append(max(l))
    l.remove(max(l))
    if len(l)>0:
        bob.append(max(l))
        l.remove(max(l))

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

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

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

Solution (Python):


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

alice = 0
bob = 0


a.sort(reverse=True)

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

print(alice - bob)

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

sumA=0
sumB=0

while lists!=[]:
    a=max(lists)
    sumA=sumA+a
    lists.remove(a)
    if lists!=[]:    
        b=max(lists)
        sumB=sumB+b
        lists.remove(b)

d=sumA-sumB
print(d)

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

Solution (Python):
n=input()
l=list(map(int,input().split()))
l.sort()
ans=0
while l:
    ans+=l.pop()
    if l:
        ans-=l.pop()
print(ans)

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

a_list.sort(reverse=True)

Alice = 0
Bob = 0
for num,i in enumerate(a_list):
    if (num+1)%2 != 0:
        Alice+=i
    else:
        Bob+=i
        
print(Alice - Bob)

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

Alice = 0
Bob = 0

ls_b = sorted(ls_a, reverse=True)

for i in range(n):
    if i % 2 == 0:
        Alice += ls_b[i]
    elif i % 2 == 1:
        Bob += ls_b[i]

print(Alice - Bob)

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

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

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

Solution (Python):
N = int(input())
lst = [int(i) for i in input().split()]
a = 0
b = 0
for i in range(N):
    if i % 2 == 0:
        a += max(lst)
    else:
        b += max(lst)
    lst.remove(max(lst))
print(a - b)

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

Alice = sum(A[::2])
Bob = sum(A[1::2])

ans = Alice - Bob
print(ans)

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

Alice = 0
Bob = 0
cou = 1

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

print(Alice - Bob)

Solution (Python):
dbflag=""

def debug(*args):
  if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
  if ""!=dbflag:return _INDATA.readline()
  else: return input()


result = 0

N = int(readline())


A = [int(i) for i in readline().split(' ')]



import numpy as np
ndary=np.array(A,dtype=int)

ndary.sort()
d = ndary[::-1]
for i in range(0,N):
  if i%2==0:
    result += d[i]
  else:
    result -= d[i]

print(result)

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

Solution (Python):
N=input()

Ai = sorted(list(map(int,input().split())))

alice = 0
bob = 0

while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

print(alice - bob)

Solution (Python):
N=input()

Ai = sorted(list(map(int,input().split())))

alice = 0
bob = 0

while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

print(alice - bob)

Solution (Python):
N=input()

Ai = sorted(list(map(int,input().split())))

alice = 0
bob = 0




while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

print(alice - bob)

Solution (Python):
N=input()

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

alice = 0
bob = 0

Ai.sort()


while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

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

while(True):
    a.sort()
    alice += a.pop(-1)
    if a == []:
        break
    a.sort()
    bob += a.pop(-1)
    if a == []:
        break

print(alice-bob)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
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
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

a.sort(reverse=True)
print(2*sum([x for i, x in enumerate(a) if i % 2 == 0])-sum(a))

Solution (Python):

n = int(input())
a = [int(i) for i in 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]

ans = alice - bob
print(ans)

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

l = sorted([int(i) for i in input().split()],reverse = True)

alice = [i for idx,i in enumerate(l) if idx % 2 == 0]
bob = [i for idx,i in enumerate(l) if idx % 2 == 1]

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

Solution (Python):

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

new_a = sorted(a)

A = []
B = []

while len(new_a) != 0:
    if len(new_a) != 0:
        A.append(new_a.pop())
    else:
        break

    if len(new_a) != 0:
        B.append(new_a.pop())
    else:
        break
        

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

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

count = 0
A = 0
B = 0

while count < N+1 and len(a) >0: 
	m = max(a)
	A += m
	a.remove(m)  
	if len(a) > 0:
		m = max(a)
		B += m
		a.remove(m)
	count +=1

print(A - B)

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

alice = 0
bob = 0
an.sort()
an.reverse()
for i,v in enumerate(an):
    if i % 2 ==0:
        alice += v
    else:
        bob += v

print(alice - bob)

Solution (Python):


import numpy
import scipy

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


A_sort = sorted(A, reverse=True)


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

print(alice - bob)

Solution (Python):
import sys

def main():
    n, *a = map(int, sys.stdin.read().split())
    a.sort(reverse=True)
    alice = sum(a[::2])
    bob = sum(a[1::2])
    print(alice - bob)

if __name__ == "__main__":
    main()

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

a = sorted(a, reverse=True)

Alice = 0
for i in range(0, len(a), 2):
    Alice += a[i]
    
Bob = 0
for i in range(1, len(a), 2):
    Bob += a[i]
    
print(Alice - Bob)

Solution (Python):
input()
A = list(map(int,input().split()))
A.sort(reverse=1)
Alice = sum(A[::2])
Bob = sum(A[1::2])
print(Alice-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())
aa = [int(i) for i in input().split()]

aa = sorted(aa)

a, b, is_a = 0, 0, True
while len(aa) != 0:
    if is_a:
        a += aa.pop(-1)
        is_a = False
    else:
        b += aa.pop(-1)
        is_a = True

print(a-b)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
Alice = 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):
num = []
A = 0
B = 0
count = int(input())
list = input().split()
for i in range(count):
    num.append(int(list[i]))
num = sorted(num, reverse = True)

while num != []:
    A += num.pop(0)
    if num != []:
        B += num.pop(0)

print(A - B)

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

Solution (Python):


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

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(0,len(a_list) + 1,2):
    if i < len(a_list):
        Alice = Alice + a_list[i]
    else:
        break

for j in range(1,len(a_list) + 1,2):
    if j < len(a_list):
        Bob = Bob + a_list[j]
    else:
        break

diff = Alice - Bob

print(diff)

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

Solution (Python):
n=int(input())
a = [int(i) for i in input().split()] 
A=0
B=0
C=0
k=0
for i in range(n):
  if i%2==0:
    k=max(a)
    A += k
    del a[a.index(k)]
  else :
    k=max(a)      
    B += k
    del a[a.index(k)]   
  
C=A-B          
print(C)

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

Solution (Python):

N = int(input())
a_list = [int(e) for e in input().split()]

a_list.sort(reverse=True)
Alice_point = sum(a_list[0::2])
Bob_point = sum(a_list[1::2])
print(Alice_point - Bob_point)

Solution (Python):

import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

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