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

ans = 0
a.sort()
a.reverse()

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

print(ans)

Solution (Python):
import sys
N = input()
N = int(N)
l = input().split()
l = list(map(int, l))

if N != len(l):
    print('Error')
    sys.exit()
Alice = []
Bob = []

while len(l) > 0:
    if len(l) > 0:
        saidai = max(l)
        Alice.append(saidai)
        l.remove(saidai)
    if len(l) > 0:
        saidai = max(l)
        Bob.append(saidai)
        l.remove(saidai)

Alice_num = 0
for i in range(0, len(Alice)):
    Alice_num += Alice[i]
Bob_num = 0
for i in range(0, len(Bob)):
    Bob_num += Bob[i]
kekka = Alice_num - Bob_num
print(kekka)

Solution (Python):


def solve():
    N = int(raw_input())
    cards = map(int, raw_input().split())

    points = [0, 0]
    for i in xrange(N):
        max_point = max(cards)
        points[i % 2] += max_point
        cards.remove(max_point)

    print points[0] - points[1]

if __name__ == "__main__":
    solve()

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
a.sort()
c=a[0::2]
e=sum(c)
d=a[1::2]
f=sum(d)
print(abs(f-e))

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

a.sort()
m = n % 2

alice = 0
bob = 0

while n > 0:
    if n % 2 == m:
        alice += a[-1]
    else:
        bob += a[-1]
    a.pop()
    n -= 1

print(alice - bob)

Solution (Python):
n = int(input())
a = input().strip().split()
a = [ int(a[i]) for i in range(len(a)) ]

a.sort(reverse=True)

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

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

total_sum = sum(a_list)
a_list = sorted(a_list,reverse=True)

a_sum = 0
for i in range(0,len(a_list),2):
    a_sum += a_list[i]

print(a_sum - total_sum + a_sum)

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

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

print(diff)

Solution (Python):
n=int(raw_input())
s=raw_input().split(' ')
l=[]
for i in range(0,n):
	l.append(int(s[i]))
l.sort()
l.reverse()
a=0
b=0
for i in range(0,n):
	if(i%2==0):
		a=a+l[i]
	else:
		b=b+l[i]

print a-b

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
sum_a = sum(a)
x_sum = 0
for x in range(0,len(a),2):
    x_sum += a[x]

y_sum = sum_a - x_sum

print(x_sum - y_sum)

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

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

Solution (Python):
n = input()
a = sorted(list(map(int, raw_input().split())), reverse=True)
print sum([a[i] for i in xrange(n) if not i % 2])-sum([a[i] for i in xrange(n) if i % 2])

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

b = sorted(a,reverse=True)
ans = sum([b[x] for x in range(N) if x % 2 ==0]) - sum([b[x] for x in range(N) if x % 2 ==1])

print(ans)

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

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

sumn = 0
summ = 0
for i in range(0,n,2):
    sumn += a[i]     
for i in range(1,n,2):
    summ += a[i]
print(sumn-summ)

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

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

print(abs(alice-bob))

Solution (Python):
n = int(input())
a = list(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]
print(alice-bob)

Solution (Python):
import sys

with sys.stdin as f:
    s_input = f.read()

    in_list = s_input.splitlines()
    n = int(in_list[0])
    a = in_list[1].split()
    a = [int(i) for i in a]

    a.sort(reverse=True)

    sc_a = 0
    sc_b = 0
    for alc in a[0::2]:
        sc_a += alc

    for bob in a[1::2]:
        sc_b += bob

    print(sc_a - sc_b)
        
sys.exit(0)

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

asum = 0
bsum = 0

for i in range(N) :
    ma = max(A)
    if i % 2 == 0:
        asum += ma
    else:
        bsum += ma
    A.remove(ma)

print(asum - bsum)

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

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


num = int(input())
str = input()

str_list = str.split()

list_up = list( map((lambda x:int(x)),str_list))


list_up.sort(reverse=True)
sum = 0
for (i, v) in enumerate(list_up):
  if(i % 2 == 0):
    sum += int(v)
  elif(i % 2 == 1):
    sum -= int(v)
print(sum)

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

Solution (Python):
n=int(input())
a=[int(k) for k in input().split()]
a.sort()
s=0
for i in range(len(a)):
    s+=(pow(-1,i)*a[len(a)-1-i])
print(abs(s))

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

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

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

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

print(alice - bob)

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

if __name__ == '__main__':
    main()

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


a.sort()
a.reverse()

tmp = int(len(a) / 2 + 0.5) - 1

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

def quicksort(array):
    if len(array) < 2:
        return(array)
    else:
        pivot = array[0]
        less = [i for i in array[1:] if i <= pivot]
        greater = [i for i in array[1:] if i > pivot]

        return quicksort(greater) + [pivot] + quicksort(less)


sorted_a = quicksort(a)
alice = []
bob = []
for i in range(len(sorted_a)):
    if i % 2 == 0:
        alice.append(sorted_a[i])
    else:
        bob.append(sorted_a[i])
print(sum(alice) - sum(bob))

Solution (Python):


o=0
zen = input()

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


if int(zen)%2 == 0:
    for i in range(int(int(zen)/2)):
        o += int(card1[int(zen)-int(i)*2-1])-int(card1[int(zen)-int(i)*2-2])


else:
    for i in range(int((int(zen)-1)/2)):
        o += int(card1[int(zen)-int(i)*2-1])-int(card1[int(zen)-int(i)*2-2])
    o += int(card1[0]) 
print(o)

Solution (Python):
N = int(input())
data = input().split()
data = data[:N]

for i in range(N):
	data[i] = int(data[i])

data.sort(reverse=True)

listA = []
listB = []
for i in range(N):
	if(i % 2 == 0):
		listA.append(data[i])
	else:
		listB.append(data[i])

print(sum(listA) - sum(listB))

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = sorted(LI(), reverse=True)
    b = 0
    c = 0
    for i in range(n):
        if i % 2 == 0:
            b += a[i]
        else:
            c += a[i]

    return b - c


print(main())

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

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

Solution (Python):
N=int(input()) 
a = list(map(int, input().split()))
sum=0
a.sort()
a.reverse()
if(N>2 and N%2 == 0):
  for i in range(0,N-1,2):
    sum=sum+a[i]-a[i+1]
if(N>2 and N%2 != 0):
  for i in range(0,N-1,2):
    sum=sum+a[i]-a[i+1]
  sum=sum+a[N-1]
elif(N==1):
  sum=a[0]
elif(N==2):
  sum=a[0]-a[1]
print(sum)

Solution (Python):
N=int(input())
A=input().split(" ")
A = list(map(int, A))
A.sort(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)
Alice = 0
Bob = 0
for i in range((n - 1) // 2 + 1):
    Alice = Alice + a[2 * i]
for i in range(n // 2):
    Bob = Bob + a[2 * i + 1]
gap = Alice - Bob
print(gap)

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):
import numpy as np
N = int(raw_input())
list = map(int,raw_input().split())
list = np.sort(list)[::-1]
list2 = np.array([1 if i % 2 == 0 else -1 for i in range(N)])
x = np.sum(list * list2)
print x

Solution (Python):
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    a_list = []
    input_raw = read_func().strip().split()
    for i in range(N):
       
        a_list.append(int(input_raw[i]))

    a_list.sort(reverse = True)

    alice_score = 0
    bob_score = 0
    for i in range(N):
        if i % 2 == 0:
            alice_score += a_list[i]
        else:
            bob_score += a_list[i]

    print alice_score - bob_score



if __name__ == '__main__':
    main()

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

revA = sorted(A, reverse=True)

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

print(alice - bob)

Solution (Python):
N = int(input())
nS = [0 for i in range(N)]
nV = [0 for i in range(N)]
nS  = input().rstrip().split(' ')

for i in range(N):
    nV[i] = int(nS[i])

nV = sorted(nV, reverse = True)

nA = 0
nB = 0


for i in range(N):
    Tmp = i % 2
    if Tmp == 0:
        nA += nV[i]
    else:
        nB += nV[i]
        
Ans = nA - nB

print(Ans)

Solution (Python):

N = int(raw_input())
a = map(int,raw_input().split())
a.sort()
a.reverse()
Bob = 0
Alice = 0
A = 0
B = 1
while A < N:
    Alice += a[A]
    A += 2
while B < N:
    Bob += a[B]
    B += 2
print Alice-Bob

Solution (Python):





if __name__ == '__main__':
    card_count = int(input())

    card_numbers = [int(i) for i in input().split()]
    card_numbers.sort(reverse=True)

    alice_score = 0
    bob_score = 0

    alice_cards = card_numbers[::2]
    bob_cards = card_numbers[1::2]

    for i in range(len(alice_cards)):
        alice_score += alice_cards[i]

    for j in range(len(bob_cards)):
        bob_score += bob_cards[j]

    diff = alice_score - bob_score
    print(diff)

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

Solution (Python):
n = int(input())
aSum = 0
bSum = 0
ans = 0
cards = [int(x) for x in input().split()]

for j in range(1,n+1):
    if j % 2 == 1:
        aSum += max(cards)
        cards.remove(max(cards))
    else:
        bSum += max(cards)
        cards.remove(max(cards))
ans = aSum - bSum
print(ans)

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    alice_sum = 0
    bob_sum = 0
    A.sort()
    A.reverse()
    for i in range(N):
        if i % 2 == 0:
            alice_sum += A[i]
        else:
            bob_sum += A[i]
    print(alice_sum - bob_sum)

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

sort_a = a[::-1]
Alice = sum(sort_a[0:N:2])
Bob = sum(sort_a[1:N:2])

print(Alice - Bob)

Solution (Python):


def main(N, a):
    alis_score = sum(a[0::2])
    bob_score = sum(a[1::2])

    print(alis_score - bob_score)

if __name__ == '__main__':
    N = int(input())
    a = list(map(int, (input().split())))
    main(N, sorted(a, reverse=True))

Solution (Python):
N = int(input()) 
L1 = input().split(" ")

L2 = list(map(int, L1))
A = []
B = []



for n in range(N - 1):
    A.append(max(L2))
    L2.remove(max(L2))
    
    if L2 == []:
        break
    B.append(max(L2))
    
    L2.remove(max(L2))
    if L2 == []:
        break
    n += 1



PA = sum(A)
PB = sum(B)
print(PA - PB)

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

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

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

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

sorteda = sorted(a)

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

print(Alice-Bob)

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

alice = 0
bob = 0


while(N !=0) :
    
        
        maxa = max(a)
        max_index = a.index(max(a))
        del a[max_index]

        alice = alice + maxa
        N = N -1

        if (N == 0):
            break
    
        
        
        maxa = max(a)
        max_index = a.index(max(a))
        del a[max_index]

        bob = bob + maxa
        N = N -1

print(alice - bob)

Solution (Python):
N = int(input())
a = [int(_) for _ in 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()) 
card = [int(i) for i in input().split()] 
card.sort(reverse=True)
alice = 0
bob = 0
for i in range(0,N):
    if(i&1):
        
        bob+=card[i]
    else:
        
        alice+=card[i]
ans = alice - bob
print(ans)

Solution (Python):


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

A = 0
B = 0
if n%2 == 0:
    r = int(n/2)
    for i in range(0,r):
        A += max(a)
        a.remove(max(a))
        B += max(a)
        a.remove(max(a))
else:
    r = int(n/2)
    for i in range(0,r):
        A += max(a)
        a.remove(max(a))
        B += max(a)
        a.remove(max(a))
    A += max(a)

print(A-B)

Solution (Python):

def solve():
    n = int(input())
    a = map(int, input().split())

    a = sorted(a)[::-1]

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

    print(alice - bob)

solve()

Solution (Python):
n = input()
a = raw_input().split(' ')
b = []
for x in a:
    b.append(int(x))
b.sort()
b.reverse()
w = 0
f = 1
for x in b:
    if f == 1:
        w += x
    else:
        w -= x
    f = 1 - f
print w

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

alice = 0
bob = 0

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

res = alice - bob
print(res)

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

Solution (Python):

import math

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

A,B =0,0

a.sort()

b = a[::-1]

S = math.floor(N/2)

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

Solution (Python):

moto = int(input())
num   = int((moto + 1 ) / 2)
retu    = input().split()
card = list( map((lambda x:int(x)),retu))
cardList = sorted(card, reverse=True)
Alice = 0
Bob = 0

for w in range(num):
    Alice = Alice + cardList[w*2]
    if moto > (w*2+1):
        Bob = Bob + cardList[w*2+1]

print(Alice - Bob)

Solution (Python):
n=int(input())
A=list(map(int,input().split(' ')))
A.sort()
a=0
b=0
i=0
while i < n:
    if i%2==0:
        a+= A[i]
    else:
        b += A[i]
    i += 1
print(abs(a-b))

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

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

ans = sum(a for a in A[::2]) - sum(a for a in A[1::2])

print(ans)

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

a.sort()
a.reverse()
b = []
c = []
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        c.append(a[i])
b_sum = 0
c_sum = 0
for i in b:
    b_sum += i
for i in c:
    c_sum += i

print(b_sum - c_sum)

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

Alice = []
Bob = []

while len(As):
    ma = max(As)
    Alice.append(ma)
    As.remove(ma)
    if len(As):
        mb = max(As)
        Bob.append(mb)
        As.remove(mb)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split(" ")))
A = sorted(A,reverse=True)
a_sum = 0
b_sum = 0
for i in range(len(A)):
    if i%2==0:
        a_sum+= A[i]
    else:
        b_sum += A[i]

print(a_sum-b_sum)

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

As.sort(reverse=True)

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

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

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

a.sort(reverse=True)

ans = 0
tmp = 1
for ai in a:
    ans += tmp * ai
    tmp *= -1

print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
A = 0
B = 0

a.sort()
while len(a) > 0:
    A += a.pop()

    if len(a) > 0:
        B += a.pop()

print(A-B)

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

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

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

for i in range(N):
    if((i % 2) == 0):
        alice += max(ls)
    else:
        bob += max(ls)
    ls[ls.index(max(ls))] = 0

out = alice - bob
print(out)

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

a.sort(reverse=True)

ans = sum(a[0::2]) - sum(a[1::2])

print(ans)

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

Solution (Python):




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


if __name__ == "__main__":
    n = int(input())
    a = input().split(" ")
    a_lst = []
    for i in range(n):
        a_lst.append(int(a[i]))
    a_lst.sort()
    a_lst.reverse()
    print(slove(n, a_lst))

Solution (Python):
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    diff = 0
    for i, ai in enumerate(reversed(a)):
        if i % 2 == 0:
            diff += ai
        else:
            diff -= ai
    print(diff)


if __name__ == '__main__':
    main()

Solution (Python):


import numpy as np 

import copy 
import math

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

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

Solution (Python):
n = int(input())
K = [int(i) for i in input().split()]
K.sort()
K.reverse()
A, B = [], []
for i in range(n):
    if i % 2 == 0:
        A.append(K[i])
    else:
        B.append(K[i])
print(sum(A) - sum(B))

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

cards = sorted(cards,reverse=True)
ali = 0
bob = 0
for i in range(maisu):
    if i%2 == 0:
        ali += cards[i]
    else:
        bob += cards[i]

print(str(ali-bob))

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

AL=0
BO=0

for i in range(N):
    if i%2==0:
        AL+=a.pop()
    else:
        BO+=a.pop()
print(AL-BO)

Solution (Python):

def main():
    N = int(input())
    S = list(map(int, input().split()))
    S = sorted(S, reverse=True)
    a = []
    b = []

    flg = 0
    for s in S:
        if flg == 0:
            a.append(s)
            flg = 1
        else:
            b.append(s)
            flg = 0

    print (sum(a) - sum(b))

if __name__ == "__main__":
    
    
    main()

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

print(abs(a-b))

Solution (Python):
n = int(input())
A = sorted([int(i) for i in input().split()])

alice = []
bob = []

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

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

Solution (Python):
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
As = Is()
As.sort(reverse=True)
alice = As[::2]
bob = As[1::2]
print(sum(alice)-sum(bob))

Solution (Python):
n = int(input())
d = [int(i) for i in input().split()]
a = 0
b = 0
d.sort()
for x in range(n):
    if(x%2==0):
        a+=d[n-1-x]
    else:
        b+=d[n-1-x]
print(str(a-b))

Solution (Python):

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

a.sort()
a.reverse()

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

print(alice-bob)

Solution (Python):
N=input()
a=map(int,raw_input().split())
b=sorted(a, key=lambda x:x,reverse=True)
ans=0
for ind, i in enumerate(b):
	if ind%2==0:
		ans+=i
	else:
		ans-=i
print ans

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

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

a.sort()
A=[]
B=[]
while(len(a)>0):
    A.append(a.pop())
    if len(a)==0: break
    B.append(a.pop())
print(sum(A)-sum(B))

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

alice=[]
bob=[]

if len(cards)%2==0:
    while len(cards)>1:
        alice.append(cards[0])
        del cards[0]
        bob.append(cards[0])
        del cards[0]
else:
    while len(cards)>1:
        alice.append(cards[0])
        del cards[0]
        bob.append(cards[0])
        del cards[0]

    alice.append(cards[0])

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

Solution (Python):
import numpy as np

N = int(input())
as_ = np.sort(np.array([int(a) for a in input().split()]))[::-1]

print("%d" % (np.sum(as_[0::2]) - np.sum(as_[1::2])))

Solution (Python):
N = int(input())
itemList = input().split(' ')
hoge = []
for i in itemList:
    hoge.append(int(i))
hoge.sort()
hoge.reverse()

A = 0
B = 0

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

print(A-B)

Solution (Python):
import random
import numpy
import sys

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

alice = []
bob = []
while not len(A)==0:
  A = sorted(A,reverse=True)
  alice.append(A.pop(0))
  if len(A)==0:
    break
  bob.append(A.pop(0))
print(sum(alice)-sum(bob))

Solution (Python):

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



alice = 0
bob = 0
for i in range(N//2):
    alice += A[i*2]
    bob += A[i*2 + 1]
if N%2!=0:
    alice += A[-1]


print(alice - bob)

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

Solution (Python):


import numpy as np

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

list.sort(A)

Alice=0


for i in range(len(A)):
    try:
        Alice+=A[-1-2*i] 
    except:
        pass

print(Alice-(sum(A)-Alice))

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

ai = input().split()

ai = list(map(int,ai))

ai.sort(reverse=True)

sum1 = 0;
sum2 = 0;

for i in range(N):
	if i%2 == 1:
		sum2+=ai[i]
	else:
		sum1 +=ai[i]

print(sum1-sum2)

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

a.sort(reverse=True)
res = 0
s = 1
for d in a:
  res += s * d
  s *= -1

print(res)

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

a.sort(reverse=True)
res = 0
s = 1
for d in a:
  res += s * d
  s *= -1

print(res)

Solution (Python):
n=int(input())
a=sorted([int(i) for i in input().split()], reverse=True)
print(sum([v for k,v in enumerate(a) if k % 2 == 0]) - sum([v for k,v in enumerate(a) if k % 2 != 0]))

Solution (Python):



import sys

def main():
    n = int(sys.stdin.readline())
    a = sorted(map(int, sys.stdin.readline().split()), reverse=True)
    s = [[], []]
    for i, b in enumerate(a):
        s[i % 2].append(b)
    print(sum(s[0]) - sum(s[1]))

if __name__ == '__main__':
    main()

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

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):
import math
import numpy as np
from operator import mul



















N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
div = 0

for i in range(N):
    div += ((-1)**i) * A[i]

print(div)

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

a.sort(reverse=True)

al = 0
bo = 0

if N % 2 == 1:
	N -= 1
	al += a[-1]

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

print(al-bo)

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

cards.sort(reverse=True)
cards
Alice,Bob = 0,0
flg = 0

while len(cards) != 0:
    if flg == 0: 
        Alice += cards.pop(0)
        flg = 1
    else:
        Bob += cards.pop(0)
        flg = 0
print(Alice-Bob)

Solution (Python):
from math import ceil
n = int(input())
a = map(int, input().split())
a = sorted(a,reverse=True)
ans = 0
for i,j in enumerate(a):
    if i % 2 == 0: ans += j
    else: ans -= j
print(ans)

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

B_Card_Game_for_Two()

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

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

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

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

print(alice-bob)

Solution (Python):


N = int(input())
a = []

for x in input().split(" "):
    a.append(int(x))

a.sort(reverse=True)

alice = 0
bob = 0

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

print(alice-bob)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
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())
cards = [int(i) for i in input().split()]
cards.sort(reverse=True)

diff = 0

for idx, i in enumerate(cards):
	if idx % 2 == 0:
		diff += i
	else:
		diff -= i

print(diff)

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

l = list(reversed(sorted(a)))

alice = 0
bob = 0
for i in range(0, len(l)):
	if i % 2 == 0:
		alice += l[i]
	else:
		bob += l[i]

print(alice-bob)

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

list_a = sorted(list_a, reverse=True)

Alice = 0
Bob = 0

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

print(Alice - Bob)

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