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

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

alice = 0
bob = 0
order = "A"
for e in sorted(a)[::-1]:
    if order == "A":
        alice += e
        order = "B"
    else:
        bob += e
        order = "A"

print(alice-bob)

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	a = LI()
	a.sort(reverse=True)
	a = np.array(a)
	print(np.sum(a[0::2]) - np.sum(a[1::2]))


if __name__ == '__main__':
	main()

Solution (Python):
input()
A = list(map(int, input().split()))
x = 0
y = 0
t = 0
while A:
	m = max(A)
	if t == 0:
		x += m
		t = 1
	else:
		y += m
		t = 0
	A.remove(m)
print(x-y)

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

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

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

a.sort()
Alice=0
Bob=0
while len(a)>=1:
    Alice+=a[-1]
    a.pop(-1)
    if len(a)>=1:
        Bob+=a[-1]
        a.pop(-1)

print(Alice-Bob)

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


alice = 0
bob = 0

for i in range(0,n,2):
    alice += a[i]

bob = sum(a)-alice
ans = alice-bob
print(ans)

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

alice = 0
bob = 0

for i in range(0,n,2):
    alice += a[i]

bob = sum(a)-alice
ans = alice-bob
print(ans)

Solution (Python):
n,a=open(0)
l=sorted(map(int,a.split()))
l1=l[0:][::2]
l2=l[1:][::2]
print (abs(sum(l1)-sum(l2)))

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

Solution (Python):
def myAnswer(N:int,A:list) -> int:
   Alice = 0
   Bob = 0
   A.sort(reverse=True)
   for n,a in enumerate(A):
      if (n%2 == 0):
         Alice += a
      else:
         Bob += a
   return Alice - Bob

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))

if __name__ == '__main__':
   main()

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

alice = 0
bob = 0
A = sorted(A)[::-1]
for i, a in enumerate(A):
    if i % 2 == 0:
        alice += a
    else:
        bob += a
print(alice - bob)

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

print(a-b)

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

Solution (Python):
N = int(input())
cards = list(map(int, 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]

difference = Alice - Bob
print(difference)

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

alice = 0
bob = 0
flag = 0
for i in range(N):
    if flag == 0:
        alice += a[N-(i+1)]
        flag = 1
    else:
        bob += a[N-(i+1)]
        flag = 0

print(alice - bob)

Solution (Python):
N = int(input())
a = map(int, input().split())
a = sorted(a, reverse=True)
i = 0
s = 0
for x in a:
    if i % 2 == 0:
        s += x
    else:
        s -= x
    i += 1
print(s)

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    n=int(input());l=sorted(list(map(int,input().split())),reverse=1)
    print(abs(sum(l)-2*sum(l[1::2])))

if __name__ == "__main__":
    main()

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

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

Solution (Python):
import numpy as np
if __name__ == "__main__":
    N = int(input())
    line = input().rstrip().split(' ')
    line = np.array(line).astype("int")
    line = np.sort(line)[::-1]
    a = 0
    b = 0
    
    for i in range(len(line)):
        if i % 2 ==0:
            a += line[i]
        else:
            b += line[i]
    print(a-b)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
Alice = []
Bob = []
for i in range(1,N+1):
    if i % 2 != 0:
        Alice.append(A[i-1])
    else:
        Bob.append(A[i-1])
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):


def main():
    n = int(input())
    A = list(map(int, input().split()))

    Alice = 0
    Bob = 0
    A_sorted = sorted(A)[::-1]

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys

lines = 2
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())

a_lst = [int(i) for i in inp[1].split()]

alice = 0
bob = 0

for idx, i in enumerate(sorted(a_lst, reverse=True)):
    if idx % 2 == 0:
        alice += i
        continue
    bob += i

print(alice - bob)

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

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
roundnum=0
alice=0
bob=0
def game():
    global roundnum
    global alice
    global bob
    if roundnum%2==0:
        alice+=a.pop()
    else:
        bob+=a.pop()
    roundnum+=1
        
while a:
    game()
    
print(alice-bob)

Solution (Python):

n = int(input())

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

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

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

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]
print(Alice - Bob)

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

a_list.sort(reverse = True)

a_point = 0
b_point = 0

for i in range(n):
  if i % 2 == 0:
    a_point += a_list[i]
  else:
    b_point += a_list[i]

print(a_point - b_point)

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

an = sorted(an, reverse=True)
alice = sum([an[i] for i in range(len(an)) if i % 2 == 0])
bob = sum([an[i] for i in range(len(an)) if i % 2 == 1])
print(alice - bob)

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

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

s2 = sorted(s, reverse=True)

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

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

a = sorted(a, reverse=True)

A = 0
B = 0

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

print(A-B)

Solution (Python):
n = int(input())
A = sorted(list(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(abs(alice - bob))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort()
alice = 0
bob = 0
ban = 0
while len(a) > 0:
    if ban % 2 == 0:
        alice += a.pop()
    else:
        bob += a.pop()
    ban += 1
print(alice - bob)

Solution (Python):

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

a.sort(reverse = True)

a_score, b_score = 0, 0

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

print(a_score - b_score)

Solution (Python):
url = "https://atcoder.jp/contests/abc088/tasks/abc088_b"

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


if __name__ == '__main__':
    main()

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

Alice = 0
Bob = 0

while A:
    Alice += A.pop()
    if A:
        Bob += A.pop()

print(Alice - Bob)

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

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

Solution (Python):
Alice = 0
Bob = 0
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)
S = sum(a)
s = 0
for i in range(0, N, 2):
  s = s + a[i]

print(s - (S - s))

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

alicePointList = a[::2]
bobPointList = a[1::2]

print(sum(alicePointList)-sum(bobPointList))

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

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

Solution (Python):

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

card = sorted(a, reverse=True)

alice = sum(card[0::2])
bob = sum(card[1::2])
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):
_, a = int(input()), 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)

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

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

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

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

Solution (Python):
n = int(input())
cardList = list(map(int,input().split()))
a = 0
b = 0
cardList.sort(reverse=True)
while len(cardList) > 0:
    if len(cardList) > 0:
        a += cardList.pop(0)
    if len(cardList) > 0:
        b += cardList.pop(0)
print(a-b)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
score_a = 0
score_b = 0

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

Solution (Python):
n = int(input())
a = list(map(int, 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):
def nyu():
    num1 = input()
    
    num2 = list(map(int,input().split()))
    num1 = int(num1)
    return num1,num2

def kansu(N,a):
    a_sum = 0
    b_sum = 0

    list.sort(a,reverse = True)
 
    
    for n in range(N):
        if n%2 == 0:
            a_sum += a[n]
        else:
            b_sum += a[n]
    
    print(a_sum - b_sum)
        
N,a = nyu()
kansu(N,a)

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

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

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


if __name__ == '__main__':
    main()

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

alice = []
bob = []

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

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

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

Alice_sum = 0
Bob_sum = 0
a.sort(reverse=True)
for i in range(0,len(a)):
    if i % 2 == 0:
        Alice_sum += a[i]
    else:
        Bob_sum += a[i]

print(Alice_sum - Bob_sum)

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

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

A = sorted(a)

ans = 0
for i in range(N):
  if i % 2 == 0:
    ans += A[-1]
  else:
    ans -= A[-1]
  A.pop()
print(ans)

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

Solution (Python):
alice=0
bob=0
n=int(input())
a=list(map(int,input().split()))
def delete():
    del a[a.index(Max)]
while n>=1:
    Max=max(a)
    alice=alice+Max
    n=n-1
    delete()
    if n>=1:
        Max=max(a)
        bob=bob+Max
        n=n-1
        delete()
else:
    print(alice-bob)

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = sorted(iil(),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)

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

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

Solution (Python):

import sys
import itertools
import fractions
import copy
import bisect
import math

from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter


N=3
M=3
i=0
j=0
k=0
n=3
r=1
a=[0]*5
b=[]
c=[]
N=int(input())







"1行1つの整数を入力を取得し、整数と取得する"


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

card_list=sorted(number_list, reverse=True)

for i in range(N//2):
    b.append(card_list[2*i])
    c.append(card_list[2*i+1])
if N%2 ==1:
    b.append(card_list[-1])
print(sum(b)-sum(c))
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

Solution (Python):


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

a = sorted(a, reverse=True)

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

diff = sum_a - sum_b
print(diff)

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

INF = float('inf')


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

    alice = 0
    bob = 0

    A = sorted(A, reverse=True)

    for _ in range(N):
        if len(A) != 0:
            alice += A.pop(0)
        if len(A) != 0:
            bob += A.pop(0)

    print(alice - bob)


if __name__ == '__main__':
    main()

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

INF = float('inf')


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

    alice = 0
    bob = 0

    for _ in range(N):
        if len(A) != 0:
            alice += A.pop(A.index(max(A)))
        if len(A) != 0:
            bob += A.pop(A.index(max(A)))

    print(alice - bob)


if __name__ == '__main__':
    main()

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

li.sort(reverse = True)


sum_A = 0
sum_B = 0

for i in range(0,n,2):
	sum_A += li[i]

for i in range(1,n,2):
	sum_B += li[i]


print(sum_A-sum_B)

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

a.sort(reverse = True)
alice,bob = 0,0
for i in range(N):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice-bob)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
e=[]
b=[]
turn=1
for i in range(n):
    if turn==1:
        e.append(a.pop(-1))
        turn-=1
    else:
        b.append(a.pop(-1))
        turn+=1
print(sum(e)-sum(b))

Solution (Python):
N = int(input())
a_li = sorted(list(map(int,input().split())),reverse=True)
Alice = sum(a_li[::2])
Bob = sum(a_li) - Alice
print(Alice - Bob)

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

bob   = 0
alice = 0

for i in range(len(new_arr)):
    if i % 2 ==0:
        alice += new_arr[i]
    elif i % 2 ==1:
        bob += new_arr[i]

print(alice-bob)

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

bob   = 0
alice = 0

for i in range(len(new_arr)):
    if i % 2 ==0:
        alice += new_arr[i]
    elif i % 2 ==1:
        bob += new_arr[i]

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

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

M = sorted(M,reverse=True)

alice = 0
bob = 0

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

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

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

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
Alice = 0
Bob = 0
while n > 0:
    max_Alice = max(a_list)
    s = str(max_Alice)
    a_list[a_list.index(max(a_list))] = 0
    Alice += int(s)
    n -= 1
    if n == 0:
        break
    else:
        max_Bob = max(a_list)
        t = str(max_Bob)
        a_list[a_list.index(max(a_list))] = 0
        Bob += int(t)
        n -= 1
print(Alice - Bob)

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
Alice = [0] * n
Bob = Alice[:]

A.sort(reverse = True)

for i in range(n):
    if i % 2 == 0:
        Alice[i] = A[i]
    else:
        Bob[i] = A[i]

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

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

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

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

alice, bob = 0, 0
for i in range(n):
    if i & 1:
        bob += a[i]
    else:
        alice += a[i]

print(alice-bob)

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

diff = 0
s = 1

while(len(c) > 0):
  diff = diff + (s * c.pop(c.index(max(c))) )
  s = s * -1

print(diff)

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

Solution (Python):
n = 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(a[::2]) - sum(a[1::2]))

Solution (Python):

import math
import itertools
import statistics

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

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

Solution (Python):



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


sorted_A_list = sorted(A_list)


Alice = 0
Bob = 0

if N % 2 == 0:
    
    Alice = sum([sorted_A_list[i] for i in range(N) if i % 2 != 0])
    Bob = sum([sorted_A_list[i] for i in range(N) if i % 2 == 0])
else:
    
    Alice = sum([sorted_A_list[i] for i in range(N) if i % 2 == 0])
    Bob = sum([sorted_A_list[i] for i in range(N) if i % 2 != 0])

print(Alice - Bob)

Solution (Python):
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


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


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n = I()
    a_list = LI()

    Alice = 0
    Bob = 0
    a_list.sort()
    while len(a_list) != 0:
        Alice += a_list.pop()
        if len(a_list) != 0:
            Bob += a_list.pop()

    print(Alice - Bob)
    pass


if __name__ == "__main__":
    main()

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

A.sort()
A.reverse()
Alice = sum(A[0::2])
Bob = sum(A[1::2])

print(Alice - Bob)

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

for i in range(N):
  if f == 0:
    Ali = Ali + a[0]
    del a[0]
    f = 1
  else:
    Bob = Bob + a[0]
    del a[0]
    f = 0
print(Ali-Bob)

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

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


a.sort(reverse=True)

sum1 = 0
sum2 = 0

for i in range(0,n,2):
    sum1 += a[i]

for i in range(1, n, 2):
    sum2 += a[i]

print(sum1 - sum2)

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

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

Solution (Python):

"""
Created on Thu Mar 26 18:51:52 2020

@author: 藤原聖士
"""

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

list.sort(a,reverse=True)

fugou=1
count=0

for i in range(N):
    count+=a[i]*fugou
    fugou*=-1

print (count)

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()))
ans=0
a.sort()

while n>0:
  ans+=a[n-1]
  n-=1
  if n==0:
    break
  ans-=a[n-1]
  n-=1
  
print(ans)

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

list = input().split()
list_int = [int(s) for s in list]
list_int.sort(reverse=True)

A = 0
B = 0

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

ans = A - B
print(ans)

Solution (Python):
N = int(input())
C = list(map(int, input().split()))
A = []
B = []
while C != [0] * N:
    a = max(C)
    A.append(a)
    for i in range(len(C)):
        if C[i] == a:
            C[i] = 0
            break
    a = max(C)
    B.append(a)
    for i in range(len(C)):
        if C[i] == a:
            C[i] = 0
            break
print(sum(A)-sum(B))

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

Solution (Python):
b = 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
A.sort(reverse=True)
for i, a in enumerate(A):
	if i%2 == 0: Alice += a
	else : Bob += a

print(Alice-Bob)

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

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

total_a = 0
total_b = 0

count = 0

while len(a) > 0:
    if count % 2 == 0:
        max_value = max(a)
        total_a += max_value
        a.remove(max_value)
        count += 1
    else:
        max_value = max(a)
        total_b += max_value
        a.remove(max_value)
        count += 1
    
print(total_a - total_b)

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

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):
def main():
    n = int(input())
    As = sorted(list(map(int, input().split())))[::-1]

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

    ans = alice - bob
    print(ans)


if __name__ == "__main__":
    main()

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

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)
	else:
		Bob+=max(a)
	a.pop(a.index(max(a)))

print(Alice-Bob)