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

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())
  
n=i()
a=intl()
a.sort()
alice=0
bob=0
for i in range(1,n+1):
	if i%2==1:
		alice+=a[-i]
	else:
		bob+=a[-i]
print(alice-bob)

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())
  
n=i()
a=intl()
a.sort()
alice=0
bob=0
for i in range(-1,-n-1,-1):
	if i%2==1:
		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)
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=True)

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

Solution (Python):
import sys
import math
import bisect

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

if __name__ == "__main__":
    main()

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

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

Solution (Python):
import numpy as np
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
for i in range(n):
    a_max = max(a)
    a.remove(a_max)
    if int(i)%2== 0:
        alice+=a_max
    else:
        bob += a_max
answer = alice - bob
print(answer)

Solution (Python):
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n= int(input())
a = li()
sa = sorted(a)
sa.reverse()
ans = 0
for i in range(n):
    if i%2==0:
        ans += sa[i]
    else:
        ans -= sa[i]
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
Alice = 0
Bob = 0
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()))

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()))
alice=0
bob=0
a=sorted(a,reverse=True)
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)

s = sum(a)
al = sum(a[::2])
bo = s - al
print(abs(al-bo))

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

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

Solution (Python):
from heapq import heapify, heappop
def main():
    card_num = int(input())
    cards = list(map(lambda x: -int(x), input().split()))
    heapify(cards)

    A_score = 0
    B_score = 0
    As_turn = True

    for i in range(card_num):
        card = - heappop(cards)
        if As_turn:
            A_score += card
        else:
            B_score += card
        As_turn = not As_turn

    diff = A_score - B_score
    print(diff)

main()

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
alice=sum(l[::2])
Bob=sum(l[1::2])

ans=alice-Bob

print(ans)

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

Alice = a[:n:2]
Bob = a[1:n:2]

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

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

A.sort(reverse=True)

t=0

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

print(t)

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

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

a.sort(reverse=True)

alice = 0
bob = 0

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

print(alice - bob)

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

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

print(al - bo)

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

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

Solution (Python):
input()
values = sorted(tuple(map(int, input().split(' '))), reverse=True)

pa = sum(values[::2])
pb = sum(values[1::2])

print(pa - pb)

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

a.sort()

even = sum(a[0::2])
odd = sum(a[1::2])

print(abs(even-odd))

Solution (Python):
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
A.sort(reverse=True)

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

print(res)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = 0
while len(A)>= 2:
  ans += A[0]-A[1]
  A = A[2:]
if len(A) == 1:
  ans += A[0]
print(ans)

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


Alice = 0
Bob = 0

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

print(Alice - Bob)

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

A = list(sorted(A, reverse=True))

ret = 0

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

print(ret)

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

Alice = 0
Bob = 0

A = list(sorted(A, reverse=True))

while True:
    if A != []:
        Alice += A.pop(0)
    else:
        break
    if A != []:
        Bob += A.pop(0)
    else:
        break

print(Alice-Bob)

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

Alice = 0
Bob = 0

A = list(sorted(A, reverse=True))

while True:
    if A != []:
        Alice += A.pop(0)
    else:
        break
    if A != []:
        Bob += A.pop(0)
    else:
        break

print(Alice-Bob)

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

a_score = 0
b_score = 0

A.sort(reverse=True)

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

print(a_score - b_score)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
x = sum(a[0::2])
y = sum(a[1::2])
print(abs(x - y))

Solution (Python):
N=int(input())
A= list(map(int,input().split()))
list.sort(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):
def draw_max_card(card_list):
    max_card = max(card_list)
    card_list.remove(max_card)
    return max_card

n = int(input())
card_list = list(map(int, input().split(" ")))
points_alice = 0
points_bob  = 0
for count in range(1, n + 1):
    if count % 2 != 0:
        points_alice += draw_max_card(card_list)
    else:
        points_bob += draw_max_card(card_list)

print(points_alice - points_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 = input()
A = [int(hoge) for hoge in input().split()]
A.sort(reverse=True)
Alice = A[::2]
Bob = A[1::2]
print(sum(Alice)-sum(Bob))

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

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

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

print(ans)

Solution (Python):
import numpy as np

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

a.sort()
a = a[::-1]

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

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

a=[(-1)**i*j for i,j in enumerate(a)]

print(sum(a))

Solution (Python):
input()
A = list(map(int, input().split()))
A.sort(reverse=True)
print(sum([A[i] * ((-1) ** (i % 2)) for i in range(len(A))]))

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

A.sort(reverse=True)
print(sum([A[i] for i in range(len(A)) if i % 2 == 0]) - sum([A[i] for i in range(len(A)) if i % 2 == 1]))

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

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string,decimal
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a = LI()
a.sort(reverse=True)

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

Solution (Python):
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0
a = 0
b = 0
n = iin()
x = [int(x) for x in input().split()]
x.sort(reverse=True)
for i in range(n):
    if i%2 :
        a = a + x[i]
    else:
        b = b + x[i]
print(b-a)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sort_a = sorted(a, reverse=True)
alice = [sort_a[i] for i in range(n) if i%2==0]
bob = [sort_a[i] for i in range(n) if i%2!=0]
point_alice = sum(alice)
point_bob = sum(bob)
print(point_alice - point_bob)

Solution (Python):
import sys
n = int(sys.stdin.readline())
a = [int(s) for s in sys.stdin.readline().split()]
a.sort(reverse=True)
a_sum = 0
b_sum = 0
for i in range(n):
    if i % 2 == 0:
        a_sum += a[i]
    else:
        b_sum += a[i]
print(a_sum - b_sum)

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

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

alice = 0
bob = 0
fnum = 0
snum = 0

for i in range(int((n + 1)/2)):
    fir = 0
    sec = 0
    for j in range(int(n - i * 2)):
        if int(a[j]) > fir:
            sec = fir

            fir = int(a[j])
        elif int(a[j]) > sec:
            sec = int(a[j])
    alice += fir
    bob += sec
    a.remove(str(fir))
    if sec == 0:
        break
    else:
        a.remove(str(sec))

print(alice - bob)

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

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

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())), reverse=True)
a = [(-1)**i * a_ for i, a_ in enumerate(a)]
print(sum(a))

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

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

print(alice-bob)

Solution (Python):
N = int(input())
A = list(reversed(sorted(list(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(Alice - Bob)

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

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

alice = 0
bob = 0

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

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

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

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

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

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

alice = 0
bob = 0

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

ans = alice - bob
print(ans)

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

Solution (Python):
n = input()
cards = list(map(int, input().split()))
sorted_cards = sorted(cards, reverse=True)
alice, bob = [], []
for index, card in enumerate(sorted_cards):
    if index % 2 == 0:
        alice.append(card)
    else:
        bob.append(card)
print(sum(alice) - sum(bob))

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

print(ans)

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):
def resolve():
  N = int(input())
  A = [int(i) for i in input().split()]
  
  A = sorted(A, reverse=True)
  alice = 0
  bob = 0
  for i in range(0, len(A), 2):
    alice += A[i]
    if i+1 < len(A):
      bob += A[i+1]

  print(alice - bob)
  
resolve()

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

Solution (Python):
import math
def main():
    n = int(input())
    cards = list(map(int, input().split()))
    alice_point = 0
    bob_point = 0

    cards.sort()
    for i in range(0, n):
        if i%2 == 0:
            alice_point += cards[i]
        else:
            bob_point += cards[i]

    print(abs(alice_point - bob_point))

if __name__ == '__main__':
    main()

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))




def resolve():
    N,=pin()
    A=lispin()
    A.sort()
    ans=0
    for i in range(N):
        t=A.pop()
        if i%2==0:ans+=t
        else: ans-=t
    print(ans)

resolve()

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 = sorted(list(map(int, input().split())))[::-1]
a_sum = 0
b_sum = 0

for i in range(N):
    if i % 2 == 0:
        a_sum += A_list[i]
    else:
        b_sum += A_list[i]
print(a_sum - b_sum)

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

a.sort(reverse = True)

Ali = 0
Bob = 0

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

Solution (Python):

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

Al = sum(a[::2])
Bo = sum(a[1::2])

print(Al-Bo)

Solution (Python):
import sys
import math
n = int(input())
li = list(map(int, input().split()))
li.sort(reverse=True)
alice = 0
bob = 0
for i in range(0, len(li) - 1, 2):
    alice += li[i]
    bob += li[i + 1]
if (len(li) % 2 != 0):
    alice+=li[-1]
print(alice-bob)

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

A_score = 0
B_Score = 0

a = sorted(a, reverse=True)

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):
n = int(input())
a_list = list(map(int,input().split()))
s_a_list = sorted(a_list)
alice = 0
bob = 0
while len(s_a_list)>1:
  alice += s_a_list.pop(-1)
  bob += s_a_list.pop(-1)
if len(s_a_list) != 0:
  alice += s_a_list.pop(-1)
print(alice-bob)

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

heapq.heapify(a)
i = 1
alice = 0
bob = 0
while i <= n:
  if i % 2 == 1:
    alice += heapq.heappop(a)*(-1)
  else:
    bob += heapq.heappop(a)*(-1)
  i += 1
print(alice - bob)

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

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
if len(a) % 2 != 0 :
    a.append(0)
a=sorted(a, reverse=True)
al=a[0::2]
print(sum(al)*2 - sum(a))

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.pop()
    else:
        Bob += A.pop()
print(Alice - Bob)

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

alice = []
bob = []

if n%2 == 0:
  while(len(a)>0):
    alice.append(a.pop())
    bob.append(a.pop())
else:
  alice.append(a.pop())
  while(len(a)>0):
    bob.append(a.pop())
    alice.append(a.pop())
print(sum(alice)-sum(bob))

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

i = 0
AliceScore = 0
BobScore = 0

while i <= n-1:
    if i % 2 == 0:
        AliceScore += org_list[i]
    else:
        BobScore += org_list[i]
    i += 1

print(AliceScore - BobScore)

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

ans = 0

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

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi

N = ri()
a = sorted(ri_(), reverse=True)
print(sum(a[0::2]) - sum(a[1::2]))

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

alice = 0
bob = 0

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

print(alice-bob)

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

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

srt_as = sorted(As, reverse=True)

Alice = 0
Bob = 0

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

print(Alice-Bob)

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

A = sorted(a, reverse=True)

Alice = 0
Bob = 0


for i in A[0::2]:
  Alice += i
  
for _ in A[1::2]:
  Bob += _
  
ans = Alice -Bob
  
print(ans)

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

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

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

if len(a) % 2 != 0:
  a.append(0)
  
a.sort()

for i in range(int(len(a) / 2)):
  total += a[2 * i] - a[2 * i + 1]

print(total * (-1))

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

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

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

print(a_point - b_point)

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

arr = list(map(int, input().split()))
arr.sort()
arr.reverse()

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

print(a_point - b_point)

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

alice = 0
bob = 0

i = 0
lim = n // 2 * 2

while i < lim:
    alice += a[i]
    bob += a[i+1]
    i += 2

if n % 2 == 1:
    alice += a[n-1]

print(alice-bob)

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

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

Solution (Python):
import sys
def main():
    
    N = input() 
    A = sorted(list(map(int,input().split())), reverse = True) 
    Alice = sum([ a for i,a in enumerate(A) if i%2 == 0 ])
    Bob = sum([ a for i,a in enumerate(A) if i%2 == 1 ])
    print(Alice-Bob)

if __name__ == "__main__":
    main()

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.pop(0)
    else:
        bob += a.pop(0)
print(alice-bob)

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

print(ca-cb)

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

card.sort(reverse=True)

asum = 0
bsum = 0
for i in range(n):
  if i%2==0:
    asum += card[i]
  else:
    bsum += card[i]

print(asum-bsum)

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

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

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

x = len(a)

Alice = 0
Bob = 0

for i in range(x):
    for j in range(x - 1 - i):
        if a[j] < a[j + 1]:
            tmp = a[j]
            a[j] = a[j + 1]
            a[j + 1] = tmp

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

   
z = Alice - Bob

print(z)

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

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

Solution (Python):
import numpy as np
N = int(input())
c = input().split()
card = np.array(c, dtype=np.int64)
alice = 0
bob = 0
card = np.sort(card)[::-1]


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

print(alice - bob)

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

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

Solution (Python):
def main():
    N = int(input())
    a = [i for i in map(int, input().split())]
    a = sorted(a, reverse=True)
    alice = sum([j for i, j in enumerate(a) if i % 2 == 0])
    bob = sum([j for i, j in enumerate(a) if i % 2 != 0])
    print(alice - bob)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
card_list = [int(n) for n in input().split()]

card_list = sorted(card_list, reverse=True)
point_a = sum(card_list[::2])
point_b = sum(card_list[1::2])
print(point_a - point_b)

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

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

card.sort(reverse = True)

a = 0

b = 0

turn  = 0

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

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

resolve()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
a = sorted(a)
for i, e in enumerate(a):
    if i % 2 == 0:
        A += e
    else:
        B += e
print(abs(A - B))

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
a = 0
b = 0
for i in range(n):
  if i % 2 == 0:
    a += max(l)
    l.remove(max(l))
  elif i % 2 == 1:
    b += max(l)
    l.remove(max(l))
print(a-b)

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

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
B = A[0::2]
b = sum(B)
C = A[1::2]
c = sum(C)
if b >= c:
  print(b-c)
else:
  print(c-b)

Solution (Python):
import math

N = input()
N = int(N)
list = input().split()
for i in range(N):
    list[i] = int(list[i])

list.sort(reverse=True)

listA=[]
listB=[]
for i in range(math.floor(N/2)):
    listA.append(list[2*i])
    listB.append(list[2*i + 1])

Asum = sum(listA)
Bsum = sum(listB)
if(N%2==1):
    Asum += list[N-1]

print(Asum - Bsum)

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

acnt =0
bcnt=0
a.sort(reverse=True)

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

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

acnt =0
bcnt=0
a.sort(reverse=True)

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

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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

A.sort(reverse=True)

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

ans = alice - bob
print(ans)

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

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

alice = []
bob = []


while len(a) > 0:
  alice.append(max(a))
  a.remove(max(a))
  if len(a) > 0:
    bob.append(max(a))
    a.remove(max(a))
  else:
    break
    
  
print(sum(alice)-sum(bob))

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

Solution (Python):
n = int(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 = [int(a) for a in input().split()]
A.sort(reverse=True)
print(sum(A[::2])-sum(A[1::2]))