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

print(abs(ans))

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

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

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

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

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

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

ary = sorted(ary, reverse=True)
scores = [0, 0]
turn = 0
while len(ary) > 0:
    s = ary.pop(0)
    scores[turn] += s
    turn = (turn + 1) % 2

diff = scores[0] - scores[1]
print(diff)

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

Solution (Python):
n=int(input())
Aseq=input().split()
A=[]
for i in range(n):
    A.append(int(Aseq[i]))
A.sort(reverse=True)
AA=A[0::2]
AB=A[1::2]
print(sum(AA)-sum(AB))

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

alice = 0
bob = 0

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

print (alice - bob)

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

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

print(Alice-Bob)

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

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

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

Solution (Python):
import sys


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

    a.sort()
    a.reverse()

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


if __name__ == "__main__":
    resolve()

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

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

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

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

Solution (Python):

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

alice = []
bob = []
alice_total = 0
bob_total = 0
ans = 0

if n%2 == 0:
    for i in range(int(n/2)):
        alice.append(a[2*i])
        bob.append(a[2*i + 1])
elif n!=1:
    for j in range(int((n - 1)/2)):
        alice.append(a[2*j])
        bob.append(a[2*j + 1])
    alice.append(a[n - 1])
else:
    alice = a

alice_total = sum(alice)
bob_total = sum(bob)
ans = alice_total - bob_total

print(ans)

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

a_desc = sorted(a, reverse=True)
ans = sum(a_desc[::2]) - sum(a_desc[1::2])
print(ans)

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

cards = sorted(cards, reverse=True)

Alice = 0
Bob = 0

for i, card in enumerate(cards):
    if i % 2 ==0:
        Alice += card
    else :
        Bob += card
        
print(Alice - Bob)

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

Solution (Python):
input()
li = list(map(int, input().split()))
li.sort(reverse=True)
alice = sum([i for index,i in enumerate(li) if index % 2 == 0])
ans = alice * 2 - sum(li)
print(ans)

Solution (Python):
def resolve():
    input()
    num = list(map(int, input().split()))
    num.sort(reverse=True)
    count = 1
    alice = 0
    bob = 0
    for val in num :
        if count % 2 == 0:
            bob += val
        else:
            alice += val
        count += 1
    print(alice - bob if alice >= bob else bob - alice)

if __name__ == '__main__':
        resolve()

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

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

card.sort(reverse=True)
alice = []
bob = []

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

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

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

aa = sorted(a,reverse=True)
Alice = 0
Bob = 0

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

print(Alice-Bob)

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

num = [int(i) for i in input().split()]
nums = sorted(num,reverse = True)
print(sum(nums[::2]) - sum(nums[1::2]))

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

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

sortList = sorted(a,reverse=True)

alice = []
bob = []

for i in range(n):
    if i % 2 ==0:
      alice.append(sortList[i])
    if i % 2 != 0:
      bob.append(sortList[i])
        
        
print(sum(alice)-sum(bob))

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

Solution (Python):
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 = sum(a[i] for i in range(len(a)) if i % 2 ==0)
bob = sum(a[i] for i in range(len(a)) if i % 2 ==1)

print(alice - bob)

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().strip().split(' ')))
sorted_a = sorted(a, reverse=True)

Alice = 0
Bob = 0
while not sorted_a == []:
  Alice += sorted_a[0]
  sorted_a.pop(0)
  if sorted_a == []:
    break
  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)
ans=0
op=1
for i in range(n):
    ans+=op*a[i]
    op*=(-1)
print(ans)

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

p = 0
q = 0

a = sorted(a, reverse=True)

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

print(p - q)

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

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

Alice_sum = 0
Bob_sum = 0

if N % 2 == 0:
    Alice_sum = sum(A[1::2])
    Bob_sum = sum(A[0::2])
else:
    Alice_sum = sum(A[0::2])
    Bob_sum = sum(A[1::2])

result = Alice_sum - Bob_sum

print(result)

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

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

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

a.sort(reverse=True)

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

print(alice - bob)

Solution (Python):
import heapq

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

heapq.heapify(a)

x = 0
y = 0

for i in range(len(a)):
    if i % 2 == 0:
        x += heapq.heappop(a)
    else:
        y += heapq.heappop(a)

print(abs(x - y))

Solution (Python):
n = int(input())
import collections
dat = list(map(int, input().split()))
dat.sort(reverse=True)
dat = collections.deque(dat)
resa , resb = 0,0

while len(dat) != 0:
    resa += dat.popleft()
    if len(dat) ==0:
        break
    resb += dat.popleft()

print(resa - resb)

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

print(Alice-Bob)

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

alice=0
bob=0

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

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

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

Solution (Python):
n = int(input())
a_lis = list(map(int, input().split()))
a_lis.sort(reverse=True)
alice = True
al_lis = []
bo_lis = []
for i in a_lis:
    if alice:
        al_lis.append(i)
    else:
        bo_lis.append(i)
    alice = not alice
print(sum(al_lis) - sum(bo_lis))

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)
print(sum([a[i] for i in range(n) if i%2 == 0])-sum([a[i] for i in range(n) if i%2!=0]))

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

print(ans)

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

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

alice = 0
bob = 0
is_bob_turn = 0

for _ in range(len(a)):
  if not is_bob_turn:
    is_bob_turn = 1
    alice += max(a)
    del a[a.index(max(a))]
  else:
    is_bob_turn = 0
    bob += max(a)
    del a[a.index(max(a))]
print(alice-bob)

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

Solution (Python):


N = int(input())
A = input().split(" ")
Alice = []
Bob = []

max = 0
mnum = 0
turn = 0
for i in range(N):
  A[i] = int(A[i])
  if(max < A[i]):
    max = A[i]
    mnum = i

Alice.append(max)
A.pop(mnum)
turn = 1

N = N -1

for i in range(N):
  max = 0
  mnum = 0
  for j in range(N):
    if(max < A[j]):
      max = A[j]
      mnum = j
  if(turn == 0):
    Alice.append(max)
    A.pop(mnum)
    turn = 1
  elif(turn == 1):
    Bob.append(max)
    A.pop(mnum)
    turn = 0
  N = N - 1

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

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

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

a = 0
b = 0

A = list(reversed(sorted(A)))

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

Solution (Python):
N = (int)(input())
array = []
array_ = input().split()
for i in range(N):
    array.append((int)(array_[i]))
array.sort(reverse=True)
sum = 0
for i in range(N):
    sum = sum + array[i] * (-1)**i

print(sum)

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

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort(reverse=True)
    alice = sum([v for i, v in enumerate(a_list) if i % 2 == 0])
    bob = sum([v for i, v in enumerate(a_list) if i % 2 == 1])
    print(alice - bob)

if __name__ == '__main__':
    main()

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

lst.sort(reverse = True)

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

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    A.reverse()
    ans = 0
    for i in range(0, N-1, 2):
        ans += A[i] - A[i+1]
    if N % 2 == 1:
        ans += A[-1]
    return ans

print(solve())

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


for i in range(N//2):
  s+=A[2*i]-A[2*i+1]
if N%2==1:
  s+=A[N-1]
print(s)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n % 2 == 0:
  A = sum(a[1::2])
  B = sum(a[::2])
else:
  A = sum(a[::2])
  B = sum(a[1::2])

print(A-B)

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

one =[]
two =[]
count = 0
if N%2 ==0:
  while count <= N-1:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
else:
  while count <= N-2:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
  one.append(max(B))
  B.remove(max(B))

print(sum(one)-sum(two))

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

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


if __name__ == '__main__':
    main()

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


sortList = sorted(A, reverse=True)


alice = []
bob = []


for i in range(len(sortList)):
        if i % 2 == 0:
                alice.append(sortList[i])
        if i % 2 != 0:
                bob.append(sortList[i])

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

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

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

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse = True)
i = 0
a = 0
b = 0
while i < n: 
    a = a +l[i]
    i += 2
i = 1
while i < n:
    b = b +l[i]
    i += 2
print(a -b)

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

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

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

print(Alice - Bob)

Solution (Python):
n = int(input())
lis = [int(x) for x in input().split(" ")]
lis.sort(reverse=True)
lis_Alice = []
lis_Bob = []

if n % 2 == 0:
  for a in range(0, n, 2):
    lis_Alice.append(lis[a])
  for b in range(1, n+1, 2):
    lis_Bob.append(lis[b])
else:
  for a in range(0, n+1, 2):
    lis_Alice.append(lis[a])
  for b in range(1, n, 2):
    lis_Bob.append(lis[b]) 

print(sum(lis_Alice) - sum(lis_Bob))

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

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

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

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

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

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

Solution (Python):
import math

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


s = 0
for i, n in enumerate(data):
    s = s + int(math.pow((-1),(i%2)))*n
print(s)

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

Solution (Python):
n=int(input())
l=sorted(list(map(int,input().split())),reverse=True)
ANS=0
for i,v in enumerate(l):
  if i % 2 == 0:
    ANS += v
  else:
    ANS -= v
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)
print(sum(A[0:len(A):2])-sum(A[1:len(A):2]))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A_sort=sorted(A)
Alice=[]
Bob=[]
if N%2==0:
    for i in range(int(N/2)):
        Alice.append(A_sort[2*i+1])
        Bob.append(A_sort[2*i])
else:
    for i in range(int(N/2+1)):
        Alice.append(A_sort[2*i])
    for i in range(int(N/2)):
        Bob.append(A_sort[2*i+1])
Alice_sum=sum(Alice)
Bob_sum=sum(Bob)
ans=Alice_sum-Bob_sum
print(ans)

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

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

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

cards=numpy.sort(a)
alice=sum(cards[::-2])
bob=sum(cards[-2::-2])
ans=alice-bob
print(ans)

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

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

is_alice_turn = True

alice_point = 0
bob_point = 0

while len(A) != 0:
    picked_num = max(A)
    if is_alice_turn:
        alice_point += picked_num
    else:
        bob_point += picked_num

    A.remove(picked_num)
    is_alice_turn = not is_alice_turn

print(alice_point - bob_point)

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

Solution (Python):
import math
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):




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


if __name__ == "__main__":
    main()

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

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

N = int(input())
list_a = [int(x) for x in input().split()]


list_a.sort(reverse = True)

Alice = 0
Bob = 0

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

print(Alice-Bob)

Solution (Python):
n=int(input())
*a,=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()))
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())
lst = list(map(int, input().split()))
alice = []
bob = []
lst.sort(reverse=True)
for i in range(N):
    if i%2 == 0:
        alice.append(lst[i])
    else:
        bob.append(lst[i])

dif = sum(alice) - sum(bob)
print(dif)

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

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

sum=0
turn=0
for i in card:
	if turn ==0:
		sum += i
		turn = 1
	else:
		sum -= i
		turn =0
print(sum)

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

sum=0
turn=0
for i in card:
	if turn ==0:
		sum += i
		turn = 1
	else:
		sum -= i
		turn =0
print(sum)

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

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

data = sorted(L, reverse=True)
count_A = 0
count_B = 0

for i, d in enumerate(data):
    if i%2 == 0:
        count_A += d
    else:
        count_B += d
        
print(count_A - count_B)

Solution (Python):
num=int(input())
values=[int(str) for str in input().split()]

values=sorted(values,reverse=True)


sumA=0
sumB=0
for i,val in enumerate(values):
    if i%2==0:
        sumA+=val
    else:
        sumB+=val

print(sumA-sumB)

Solution (Python):
def main(n,a):
    
    a.sort(reverse = True)
    
    alis = a[0::2]
    bob = a[1::2]
    return sum(alis) - sum(bob)

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

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

Solution (Python):
N = int(input())
ans_Alice = 0
ans_Bob = 0

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

a_new = sorted(a, reverse = True)


for i in range(0, N, 2):
	ans_Alice += a_new[i]
	
for j in range(1, N, 2):
	ans_Bob += a_new[j]


print(str(ans_Alice - ans_Bob))

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
A_total = 0
B_total = 0
A_current = 0
B_current = 0
count = 0
while not len(a) == 0:
  if count%2 == 0:
    A_current = max(a)
    a.remove(A_current)
    A_total += A_current
    count += 1
  else:
    B_current = max(a)
    a.remove(B_current)
    B_total += B_current
    count += 1

print(A_total - B_total)

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

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

for i in range(1, N, 2):
    points_bob += A[i]

print(points_alice - points_bob)

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

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

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

a = 0
b = 0

for i, num in enumerate(l):
    if i % 2 == 0:
        a += num
    else:
        b += num

print(a-b)

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

ary = sorted(ary, reverse=True)
scores = [0, 0]
turn = 0
while len(ary) > 0:
    s = ary.pop(0)
    scores[turn] += s
    turn = (turn + 1) % 2

diff = scores[0] - scores[1]
print(diff)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
alice = bob = 0
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=sorted([int(x) for x in input().split()],reverse=True)

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

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

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

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)

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)
Alice = 0
Bob = 0
for i in range(len(a)):
    if i % 2 == 0:
        Alice += a[i]
    else:
        Bob += a[i]
print(Alice-Bob)

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

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

Solution (Python):
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]
        else:
            Bob += A[i]

    print(Alice - Bob)


if __name__ == "__main__":
    main()

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

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

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==0:
    pick_bob=max(A)
    Bob+=pick_bob
    A.remove(pick_bob)
  else:
    pick_alice=max(A)
    Alice+=pick_alice
    A.remove(pick_alice)
    
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):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    A=LIST()
    A=sorted(A,reverse=True)
    al=len(A)
    alice=0
    bob=0
    for i in range(al//2):
        alice+=A[2*i]
        bob+=A[2*i+1]
    if al%2==1:
        alice+=A[-1]
    print(alice-bob)    
if __name__ == '__main__':
    do()

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

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

alice, bob = [],  []

card = sorted(card)
for i, _ in enumerate(range(n)):
    if i % 2 == 0:
        alice.append(card.pop())
    else:
        bob.append(card.pop())
        
print(sum(alice) - sum(bob))

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

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

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

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

points = [0,0]
i = 0
while AS:
  point = max(AS)
  points[i] += point
  AS.remove(point)
  i = 1-i
print(points[0]-points[1])

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

a.sort()
a.reverse()

t = 'A'
alice = []
bob = []
while(True):
    if t == 'A':
        t = 'B'
        x = a.pop(0)
        alice.append(x)
    elif t == 'B':
        t = 'A'
        x = a.pop(0)
        bob.append(x)

    if len(a) == 0:
        break

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

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

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

a = 0
b = 0

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

print(a - b)

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

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

Solution (Python):
from functools import reduce 
from operator import add
 
n = int(input())
arr = list(map(int, input().split()))
 
pt_a = 0
pt_b = 0
 
arr.sort(reverse=True)
 
for ind, num in enumerate(arr):
  if ind % 2 == 0:
    pt_a += num
  else:
    pt_b += num
 
print(pt_a - pt_b)

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

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

Solution (Python):
def main(n, a):
    a.sort()
    ans = 0

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

    print(ans)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    main(n, a)