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



Sample input:
2
3 1


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

alice = sum(l[::2])
bob = sum(l[1::2])

print(alice-bob)

Submission status: Accepted

Solution code:
n = input()
nums = sorted(list(map(int, input().split())), reverse=True)
result = 0
for i, v in enumerate(nums):
    result += (1 if i % 2 == 0 else -1) * v
print(result)

Submission status: Accepted

Solution code:
n = int(input())
line = input().split(" ")
a = []
alice = 0
bob = 0

for i in line:
    a.append(int(i))

a.sort(reverse = True)

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

print(alice - bob)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int, input().split()))
a, b=0, 0
for k, v in enumerate(sorted(arr, reverse=True)):
  if k%2==0:
    a+=v
  else:
    b+=v
print(a-b)

Submission status: Accepted

Solution code:
#encoding:utf-8

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

A.sort(reverse=True)
answer = 0
alice = 0
bob = 0
for i in range(len(A)):
    if i % 2 == 0:
        alice += A[i]
    else:
        bob += A[i]

print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
b=0
c=0
if n%2==0:
    for i in range(n//2):
        b+=a[2*i]
        c+=a[2*i+1]
else:
    for i in range(n//2):
        b+=a[2*i]
        c+=a[2*i+1]
    b+=a[n-1]
if b>c:
    print(b-c)
else:
    print(c-a)

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int,input().split()))
alice,bob = 0, 0
for i in range(N):
    choice = cards.pop(cards.index(max(cards)))
    if i % 2 == 0:
        alice += choice
    else:
        bob += choice
print(alice-bob)

Submission status: Accepted

Solution code:
tmp = int(input())
num = sorted(list(map(int,input().split())),reverse=True)
bob = 0
mary = 0
for i in range(tmp):
  if i%2 == 0:
    mary += num[i]
  else:
    bob += num[i]
print(str(mary -bob))

Submission status: Accepted

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

a_sort = sorted(a)[::-1]
Alice = 0
Bob = 0
for i in range(0,N):
	if i%2 == 0:
		Alice += a_sort[i]
	if i%2 == 1:
		Bob += a_sort[i]

print(Alice-Bob)

Submission status: Accepted

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

alice = 0
bob = 0
is_alice_turn = True
while 0 < len(a):
    if is_alice_turn:
        alice += a[len(a) - 1]
    else:
        bob += a[len(a) - 1]
    a.pop(len(a) - 1)
    is_alice_turn = not is_alice_turn
print(alice - bob)

Submission status: Accepted

Solution code:
def main(N,xs):
    # type: (int, List[int]) -> None
    xs.sort(reverse=True)
    alice = xs[0::2]
    bob = xs[1::2]
    print(sum(alice)-sum(bob))
    return

if __name__ == '__main__':
    N = int(input())
    xs = list(map(int,input().split()))
    main(N,xs)

Submission status: Accepted

Solution code:
def main(N,xs):
    # type: (int, List[int]) -> None
    xs.sort()
    xs.reverse() # 降順
    alice = 0
    bob = 0
    for i,x in enumerate(xs):
        if i % 2 == 0:
            alice += x
        else:
            bob += x
    print(alice-bob)
    return

if __name__ == '__main__':
    N = int(input())
    xs = list(map(int,input().split()))
    main(N,xs)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
s = []
d = []
for i in range(0,n,2):
    s.append(a[i])
for j in range(1,n,2):
    d.append(a[j])
print(sum(s)-sum(d))

Submission status: Accepted

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

print(sum(ali)-sum(bob))

Submission status: Accepted

Solution code:
count = int(input())
array = sorted(list(map(int, input().split())), reverse=True)
r = 0
i = 0
while i < count:
    if (i % 2) < 1:
        r += array[i]
    else:
        r -= array[i]
    i += 1
    
print(r)

Submission status: Accepted

Solution code:
N = int(input())
value = sorted(list(map(int,input().split())))[::-1]
print(sum(value[::2]) - sum(value[1::2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
value = sorted(list(map(int,input().split())),reverse=True)
print(np.sum(value[::2]) - np.sum(value[1::2]))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
value = np.sort(list(map(int,input().split())))[::-1]
print(np.sum(value[::2]) - np.sum(value[1::2]))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
value = list(map(int,input().split()))
value=np.sort(value)[::-1]
#print(N,value)
a = np.sum(value[::2])
b = np.sum(value[1::2])
print(a-b)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
alice, bob = 0,0
for i in range(int(N/2)):
    alice += max(a)
    a.remove(max(a))
    bob += max(a)
    a.remove(max(a))
if(N%2)==1:
    alice+=max(a)
print(alice-bob)

Submission status: Accepted

Solution code:
alice = 0
bob= 0

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

for i in range(N):
    max_num = max(a)
    if i % 2 == 0:
        alice += max_num
    else:
        bob += max_num
    a.remove(max_num)

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0
for i in range(0, N):
    m = max(A)
    if i % 2 == 0: 
        alice += m
    else:
        bob += m
    A.remove(m)
print(alice-bob)

Submission status: Accepted

Solution code:
### coding: UTF-8
 
#import math
#import random as rd
#import numpy as np
 
 
n=int(input())
line=list(map(int,input().split( )))
 
line=sorted(line)
 
#print(line)
 
s=sum([line[-(i+1)] for i in range(n) if i%2==0])-sum([line[-(i+1)] for i in range(n) if i%2!=0])
 
print(s)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=y=0
while True:
  if len(a)>0:
    x+=a.pop()
  else:
    break
  if len(a)>0:
    y+=a.pop()
  else:
    break
print(x-y)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Alice = []
Bob = []

while(As):
    Alice.append(max(As))
    As.remove(max(As))
    if not As:
        break
    Bob.append(max(As))
    As.remove(max(As))

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

Submission status: Accepted

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

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 != 0])
print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
cards = (list)(map(int, input().split()))

cards = sorted(cards, reverse=True)

print(2*sum(cards[0::2]) - sum(cards))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
for i in range(N):
    m = max(a)
    x = a.index(m)
    if i % 2 == 0:
        A += m
    else:
        B += m
    a[x] = 0
print(A - B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
input()
cards = np.array(list(input().split()), dtype=int)

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

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

Submission status: Accepted

Solution code:
a=int(input())
b=[int(i) for i in input().split()]
c=sorted(b)
#print(c)
d=sum(c[0::2])
e=sum(c[1::2])
print(abs(e-d))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
l=sorted([int(_) for _ in input().split()])[::-1]
print(sum(l[::2])-sum(l[1::2]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
print(alice - bob)

Submission status: Accepted

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

alice = 0
bob = 0

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

for i in range(1, n, 2):
    bob += l[i]

print(alice - bob)

Submission status: Accepted

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

sort_list = sorted(a)
rev_list = list(reversed(sort_list))

alice_sum = 0
bob_sum = 0

alice = rev_list[::2]
bob = rev_list[1::2]

for i in alice:
    alice_sum += i
for i in bob:
    bob_sum += i

ans = alice_sum - bob_sum

print(ans)

Submission status: Accepted

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

sum = 0
i = 0
while len(a_list) > 0:
    number = a_list.pop(a_list.index(max(a_list)))
    if i % 2 == 0:
        sum += number
    else:
        sum -= number
    i += 1
print(sum)

Submission status: Accepted

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

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


def il():
    return list(map(int, input().split()))


N = int(input())
A = sorted(il())[::-1]
print(sum(A[::2]) - sum(A[1::2]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
num = [int(i) for i in input().split()]
num.sort(reverse=True)
a, b = 0, 0

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

print(a-b)

Submission status: Accepted

Solution code:
#Beginner 088 B-Card Game for Two

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

for t in range(N):
    for i in range(N-t):
        if A[t]<A[t+i]:
            b=A[t+i]
            A[t+i]=A[t]
            A[t]=b
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
card = list(map(int,input().split()))
card.sort(reverse=True)
alice_turn = 1
alice = 0
bob = 0
for n in card:
  if alice_turn == 1:
    alice += n
    alice_turn = 0
  else:
    bob += n
    alice_turn = 1
print(alice-bob)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
alice=0
bob=0
#降順ソート
a.sort()
a.reverse()

for i in range(int(n/2)):
        alice+=int(a[2*i])
        bob+=int(a[2*i+1])
if n%2==1:
        alice+=int(a[n-1])

ans=alice-bob
print(ans)

Submission status: Accepted

Solution code:
#入力
N = int(input())
a_i = list(map(int, input().split()))


#順番にリスト内の最大値を抜き出し、それぞれのリストに順に格納

#それぞれのリストを作成
Alice_list = []
Bob_list = []

while True:

    #最大値を特定し要素番号を抜き出す
    max_idx = a_i.index(max(a_i))

    #最大値の値を抜き出し、リストからその値を削除
    Alice_list.append(a_i[max_idx])
    a_i.remove(a_i[max_idx])

    #リスト内が空になったら処理終了
    if len(a_i)==0:
        break
        
        
    #最大値を特定し要素番号を抜き出す
    max_idx = a_i.index(max(a_i))

    #最大値の値を抜き出し、リストからその値を削除
    Bob_list.append(a_i[max_idx])
    a_i.remove(a_i[max_idx])

    #リスト内が空になったら処理終了
    if len(a_i)==0:
        break
    
#Aliceの合計
Alice_sum = sum(Alice_list)

#Bobの合計
Bob_sum = sum(Bob_list)

#2人の差
Alice_Bob = Alice_sum - Bob_sum

#出力
print(Alice_Bob)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
A = sorted(A,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))

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest088-B
#  TODO https://atcoder.jp/contests/abc088/tasks/abc088_b
def calcAlice(cardList):
	cardMany = len(cardList)
	alicePoint = 0
	checkRange = range(0,cardMany,+2)
	for i in checkRange:
		alicePoint = alicePoint + cardList[i]
	return alicePoint

def calcBob(cardList):
	cardMany = len(cardList)
	bobPoint = 0
	checkRange = range(1,cardMany,+2)
	for i in checkRange:
		bobPoint = bobPoint + cardList[i]
	return bobPoint

def  diffTwoScore(allCards,cardsNumberGivenList):
	cardNumberSortedList=sorted(cardsNumberGivenList,reverse=True)
	getScoreForAlice = calcAlice(cardNumberSortedList)
	getScoreForBob = calcBob(cardNumberSortedList)
	diffPoint = getScoreForAlice - getScoreForBob
	answer = diffPoint
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	cardsNumberRawList = list(map(int,input().strip().split(' ')))
	solution=diffTwoScore(N,cardsNumberRawList)
	print("{}".format(solution))

Submission status: Accepted

Solution code:
N = int(input())

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

Alice = 0
Bob = 0
count=0
B = []
for i in A:
    B.append(i)

for i in range(len(B)):
    if(count==0):
        Alice+=max(B)
        count=1
        index = B.index(max(B))
        B[index] = 0
    else:
        Bob+=max(B)
        count=0
        index = B.index(max(B))
        B[index] = 0

print(Alice - Bob)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    aa = sorted(map(int, input().split()), reverse=True)
    print(sum(aa[0::2]) - sum(aa[1::2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    sn = input()
    sa = input().split(' ')
    a = [int(s) for s in sa]

    a.sort()
    a.reverse()
    na = 0
    nb = 0
    for n in a[0::2]:
        na += n
    for n in a[1::2]:
        nb += n

    print(na - nb)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def abc088_b():
    _ = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    print(sum(a[::2]) - sum(a[1::2]))


abc088_b()

Submission status: Accepted

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

print(alice - bob)

Submission status: Accepted

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

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

print(Alice-Bob)

Submission status: Accepted

Solution code:
N = int(input())
le = list(map(int, input().split()))

player = [0,0]
turn = 0
count = 0

while(1):
    count+=1
    mx = max(le)
    player[turn]+=mx
    le.remove(mx)
    if count==N:
        break
    if turn==0:
        turn=1
    else:
        turn=0


print(player[0]-player[1])

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a = sorted(a, reverse=True)
Alice = a[::2]
Bob = a[1::2]
print(sum(Alice)-sum(Bob))

Submission status: Accepted

Solution code:
N=int(input())

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

a,b=0,0

for i in range(N):
    if((i+1)%2!=0):
        a+=x_list[i]
    else:
        b+=x_list[i]

print(a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
dat = list(input().split())

dat = list(map(int,dat))

dat.sort(reverse=True)

asum = 0
bsum = 0

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

Submission status: Accepted

Solution code:
N = int(input())
cards_num = [int(x) for x in input().split(' ')]

cards_num.sort(reverse=True)

bob = []
alice = []

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

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

Submission status: Accepted

Solution code:
N=int(input())
a=input().strip().split(" ")
a=[int(i) for i in a]
kisuu=0
guusu=0

a.sort(reverse=True)

for i in range(N):
    if(i%2==1):
       kisuu+=a[i]
    else:
        guusu+=a[i]

print(abs(kisuu-guusu))

Submission status: Accepted

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

a.sort(reverse=True)
score_of_alice, score_of_bob = 0, 0
for i in range(n):
    score = a.pop(0)
    if i % 2 == 0:
        score_of_alice += score
    else:
        score_of_bob += score

print(score_of_alice - score_of_bob)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = 0
b = 0

l = sorted(l, reverse=True)
for i in range(n):
    if i%2 == 0:
        a += l[i]
    else:
        b += l[i]
print(a-b)

Submission status: Accepted

Solution code:
n = input()
cards = sorted(list(map(int, input().split())))[::-1]
alice = cards[0::2]
bob = cards[1::2]
print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
N = int(input())
cards = [int(i) for i in input().split()]
cards.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = input()
A = list(map(int, input().split(" ")))
A.sort(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)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
alice, bob = 0, 0
for i in range(n):
    temp_max = max(a)
    a.remove(temp_max)
    if i % 2 == 0:
        alice += temp_max
    else:
        bob += temp_max
print(alice - bob)

Submission status: Accepted

Solution code:
times = int(input())
ans = 0
type = 1
num = list(map(int,input().split(" ")))
num.sort(reverse=True)
for i in num:
    if type % 2:
        ans += i
    else:
        ans -= i
    type += 1
    
print(ans)

Submission status: Accepted

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

list_a.sort()

sum_of_diff = 0

while list_a:
	tmp_a = list_a.pop()
	try:
		tmp_b = list_a.pop()
	except:
		tmp_b = 0
	sum_of_diff += tmp_a - tmp_b

print(sum_of_diff)

Submission status: Accepted

Solution code:
(lambda _, L: print(sum(L[0::2]) - sum(L[1::2])))(input(), sorted([int(i) for i in input().split()], reverse=True))

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
a = [int(m) for m in a]

a.sort(reverse=True)

ali = []
bli = []

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(x) for x in input().split()]
alice = bob = 0
for i, a in enumerate(sorted(a_list, reverse=True)):
    if i % 2 == 0:
        alice += a
    else:
        bob += a
print(alice - bob)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int,input().split()))

c = sorted(b,reverse = True)
d = c[0::2]
e = c[1::2]

print(sum(d) - sum(e))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()] 
a.sort()
#print(a)
ans=0
flag=1
for i in range(n):
  ans+=(-1)**(i%2)*int(a[-1-i])
print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()] 
a.sort()
#print(a)
ans=0
flag=1
for i in range(n):
  ans+=flag*int(a[-1-i])
  flag=-1*flag
print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()] 
a.sort()
#print(a)
ans=0
for i in range(n):
  ans+=(-1)**i*int(a[-1-i])

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Card Game for Two
input()
print(sum(i if p % 2 == 0 else -i for p, i in enumerate(sorted(list(map(int, input().split())), reverse=True))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(int(i) for i in input().split()) 

a.sort(reverse = True) ##sortとreveseの一括操作

A = 0
B = 0

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

print(A-B)

Submission status: Accepted

Solution code:
N = int(input()) 

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

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

Submission status: Accepted

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

a.sort(reverse=True)
score_of_alice = score_of_bob = 0
for i, a_i in enumerate(a):
    if i % 2 == 0:
        score_of_alice += a_i
    else:
        score_of_bob += a_i

print(score_of_alice - score_of_bob)

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
A = 0
B = 0
while True:
  A += max(ar)
  ar.remove(max(ar))
  if len(ar) == 0:
      break
  B += max(ar)
  ar.remove(max(ar))
  if len(ar) == 0:
      break
print(A - B)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]

xs = sorted(A, reverse=True)

result = sum(xs[0::2]) - sum(xs[1::2])

print(result)

Submission status: Accepted

Solution code:
N = int(input())
card_list = list(map(int,input().split()))
card_list.sort(reverse=True)
Alice_list = []
Bob_list = []

for i in range(N):
    if i%2 == 0:
        Alice_list.append(card_list[i])
    else:
        Bob_list.append(card_list[i])

print(sum(Alice_list)-sum(Bob_list))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0

a.sort()
a.reverse()

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

print(A-B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

    alice, bob = 0, 0

    for i in range(n//2):
        dum = max(vals)
        alice += dum
        del vals[vals.index(dum)]

        dum = max(vals)
        bob += dum
        del vals[vals.index(dum)]

    if vals:
        alice += vals[0]

    print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(n + 1):
    max_index = a.index(max(a))

    if i % 2 == 0:
        alice += max(a)

    else:
        bob += max(a)

    a[max_index] = 0

print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
a = list( sorted(map( int, input().split())))[::-1]
A_B = 0
B = 1

for i in a:
	A_B += i * B 
	B *= -1
    
print(A_B)

Submission status: Accepted

Solution code:
N = int(input())


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

A_B = 0
B = 1

for i in a:
	A_B += i * B 
	B *= -1
    
print(A_B)

Submission status: Accepted

Solution code:
N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
a.reverse()
Alice_Bob = 0
Bob = 1

for i in a:
	Alice_Bob += i * Bob  
	Bob *= -1
    
print(Alice_Bob)

Submission status: Accepted

Solution code:
N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
a.reverse()
Alice = 0
Bob = 0
a.append(0)
a.append(0)

for i in range(N//2 + 1):
	Alice += int(a[2 * i])  
	Bob += int(a[2 * i + 1])
    
print(Alice -Bob)

Submission status: Accepted

Solution code:
N = input()
a = map(int, raw_input().split())
a.sort()
a.reverse()
alice = sum([a[i] for i in range(N) if i % 2 == 0])
bob = sum([a[i] for i in range(N) if i % 2 != 0])
print alice - bob

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
alice = 0
for i in range((n - 1) // 2 + 1):
    alice += a[- (2 * i + 1)]
print(2 * alice - sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
a = [int(i) for i in input().split()]
a = sorted(a)
alice = 0
bob = 0
for i in range(len(a)):
    if i % 2 == 0:
        alice += a[-i-1]
    else:
        bob += a[-i- 1]
print(alice-bob)

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse = True)
sum_alice = sum(a[0::2])
sum_bob = sum(a[1::2])
print(sum_alice - sum_bob)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
List=list(map(int,input().split()))
List.sort(key=lambda x:x)
n=0
Alice=0
Bob=0
while n<=N-1:
  if n%2==0:
    Alice+=List[N-1-n]
  else     :
    Bob+=List[N-1-n]
  n+=1
print(Alice-Bob)

Submission status: Accepted

Solution code:
n = int(input())
card = list(map(int,input().split()))
card = sorted(card,reverse=True)
alice = 0
bob = 0


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

print(alice-bob)

Submission status: Accepted

Solution code:
def card_game():
    n = int(input())
    a_li = [int(i) for i in input().split()]
    ans = 0
    turn_switch = True

    li = sorted(a_li, reverse=True)

    for i in li:
        if turn_switch:
            ans += i
            turn_switch = False
        else:
            ans -= i
            turn_switch = True

    return ans


if __name__ == '__main__':
    print(card_game())

Submission status: Accepted

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

card.sort(reverse = True)
for i in range(n):
    if i % 2 == 0:
        alice += card[i]
    else:
        bob += card[i]
print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a[0:n:2]) - sum(a[1:n:2]))