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:
#-*-coding:utf-8-*-

def main():
    #入力
    n = int(input())
    lists = list(map(int, input().split()))
    #入力をソートし降順にする
    lists.sort()
    lists.reverse()

    #アリスとボブの点数
    alice_sum = 0
    bob_sum = 0

    for i in range(n):
        #降順のリストの内偶数番目がアリスの得点になる
        #機数番目はボブの得点
        if i % 2 == 0:
            alice_sum += lists[i]
        else:
            bob_sum += lists[i]
    
    print('{}'.format(alice_sum - bob_sum))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

a = list(map(int,input().split()))
b = sorted(a,reverse=True)
Alice =[]
Bob =[]
for i in range(N):
    if (i+1)%2 !=0:
        Alice.append(b[i])
    else:
        Bob.append(b[i])

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

Submission status: Accepted

Solution code:
# cook your dish here
n=int(input())	
a = list(map(int,input().split()))

if n %2 !=0:
    a.append(0)
    n = n+1
    
a.sort()
b = a[::-1]

c=0
d=0


k = 0
while k != n:
   c += b[k]
   d += b[k+1]
   k = k +2
print(c-d)

Submission status: Accepted

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

num_list.sort()
num_list.reverse()

Alice = 0
Bob = 0
turn = True

while(True):
  if len(num_list) == 0:
    break
  
  if turn:
    Alice += num_list.pop(0)
  else:
    Bob += num_list.pop(0)
  turn = not turn
print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()], 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:
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
A.reverse()
d = 0
for a in A[::2]:
  d += a
for a in A[1::2]:
  d -= a
print(d)

Submission status: Accepted

Solution code:
code=int(input())
arr = list(map(int, input().split()))
sumone=0
for i in range(code):
    for j in range(i+1,code):
        if arr[i]<arr[j]:
            box=arr[j]
            arr[j]=arr[i]
            arr[i]=box
for i in range(code):
    if i%2==0:
        sumone+=arr[i]
    else:
        sumone-=arr[i]
print(sumone)

Submission status: Accepted

Solution code:
N = int(input())
a = input().split()
ans = 0
for i in range(0,N):
	for j in range(i,N):
		if int(a[i]) < int(a[j]):
			b = a[i]
			a[i] = a[j]
			a[j] = b
for i in range(0,N,2):
	ans += int(a[i])
for i in range(1,N,2):
	ans -= int(a[i])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
aa=0
bb=0
x=-1
while x>=-n:
    if x%2==0:
        bb+=a[x]
    else:
        aa+=a[x]
    x-=1
print(aa-bb)

Submission status: Accepted

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

Alice = A[0::2]
Bob = A[1::2]

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

Submission status: Accepted

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

list.sort(reverse=True);

A = 0;
B = 0;

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

for i in range(1,N,2):
	B += list[i]

print(A - B)

Submission status: Accepted

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

print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
alist = list(map(int, input().split(" ")))
alist.sort()
alist.reverse()
score_a = sum(alist[::2])
score_b = sum(alist[1::2])
print(score_a - score_b)

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

Submission status: Accepted

Solution code:
# ABC088 B Card Game for Two
def main():
    n = int(input().strip())
    a = [int(x) for x in input().split()]

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

    print(alice - bob)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
#入力
N = input()
A = input()
#入力値を取り出す
x = np.array(list(map(int,A.split( ))))
j = []
for i in range(len(x)):
    j = np.append(j,np.max(x))
    y = np.where(x == np.max(x))[0][0]
    x[y] = 0
print(int(np.sum(j[::2])-np.sum(j[1::2])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
a= sorted([int(j) for j in input().split()],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 = 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()))
a.sort()
print(sum(a[n-1::-2])-sum(a[n-2::-2]) if n!=1 else a[0])

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(raw_input())
a=map(int,raw_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(map(int,input().split()),reverse=True)
print(sum([a[i] * (-1)**i for i in range(N)]))

Submission status: Accepted

Solution code:
#coding: utf-8

def first_pop(l):
    if (len(l) <= 0):
        return 0
    else:
        return l.pop(0)

if __name__ == '__main__':

    n = int(input())
    a = sorted(map(int, (input().split())), reverse=True)
    alice, bob = 0, 0
    while len(a) > 0:
        alice += first_pop(a)
        bob += first_pop(a)

    print(alice - bob)

Submission status: Accepted

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

Alice = 0
Bob = 0

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

Submission status: Accepted

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

cards = sorted(a, reverse=True)
alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

Solution code:
_ = input()
xs = sorted([int(x) for x in input().split()], reverse=True)
print(abs(sum(xs[::2]) - sum(xs[1::2])))

Submission status: Accepted

Solution code:
d = '2 7 4'
d = input()
d = input()
d = [int(i) for i in d.split()]
d.sort()
s1 = 0
s2 = 0
i = len(d)-1
while(i>=0):
    s1 = s1 + d[i]
    if((i-1)>=0):
        s2 = s2 + d[i-1]
    i = i-2
print(s1-s2)

Submission status: Accepted

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

s_A = 0
s_B = 0
for i in range(N):
    if i % 2 == 0:
        s_A += a[i]
    elif i % 2 == 1:
        s_B += a[i]

print(s_A - s_B)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 15 11:27:37 2018

@author: Yuya
"""

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

A.sort()
A.reverse()

Alice = 0
Bob = 0

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

print(Alice-Bob)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
A.reverse()
s = 0
for n in range(N):
    if n % 2 ==0:
        s += A.pop(0)
    else:
        s -= A.pop(0)
print(s)

Submission status: Accepted

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

#1番目に大きいもの、3番目に大きいもの....の和から、2番目に大きいもの、4番目に大きいもの...を引く

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	n = int(input())
	a = sorted(list(map(int, re.split(" +", input()))), reverse=True)
	print(sum(a[::2]) - sum(a[1::2]))

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

Alice=0
Bob=0

A.sort()
A.reverse()

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 = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)
A, B = 0, 0
for idx in range(N):
  if idx % 2 == 0:
    A += cards[idx]
  else:
    B += cards[idx]
print(A - B)

Submission status: Accepted

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
Alice_point = 0
Bob_point = 0

numbers.sort(reverse=True)

while True:
    try:
        Alice_point += numbers[0]
        Bob_point += numbers[1]
        numbers.remove(numbers[0])
        numbers.remove(numbers[0])
    except IndexError:
        break

print(Alice_point - Bob_point)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
l1 = sorted(l,reverse = True)
l1
k = 0
for i in range(n):
    k += l1[i]*((-1)**i)
print(k)

Submission status: Accepted

Solution code:
N = int(input())
Li = list(map(int,input().split()))
Li = sorted(Li)
a = 0
b = 0
while True:
    a += Li.pop()
    if not Li:
        break
        
    b += Li.pop()
    if not Li:
        break

print(a - b)

Submission status: Accepted

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

cnt = int(input())
card_list = [int(i) for i in input().split()]

# 2人の得点
alice = 0
bob = 0

# 高得点順にカードを並べ替え
card_list.sort(reverse=True)

for i in range(cnt):
    # 0開始で偶数ならAlice、奇数ならBobに加点する
    if i % 2 == 0:
        alice += card_list[i]
    else:
        bob += card_list[i]
# 得点差を出力
print(alice - bob)

Submission status: Accepted

Solution code:
def ret_max_index(n, list):
    i = 0
    tmp = 0
    max = 0
    for i in range(n):
        if(max < list[i]):
            tmp = i
            max = list[i]
    return tmp

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

j = 0
k = 0
alice = 0
bob = 0
max = 0
lis_elem = len(lis)

for j in range(N):
    lis_elem = len(lis)
    max = lis[ret_max_index(lis_elem, lis)]
    #print("max:",max)
    del lis[ret_max_index(lis_elem, lis)]
    if(j%2 == 0):
        alice = alice + max
    elif(j%2 == 1):
        bob = bob + max

print(alice - bob)

Submission status: Accepted

Solution code:
def main():
    num_ans = int(input())
    card_list = list(map(int, input().split()))
    card_list.sort()
    card_list.reverse()
    print(sum(card_list) - sum(card_list[1::2]) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
card_num = int(input())
card_list = input().split()
card_list = list(map(int, card_list))
# print(card_list)
card_list.sort(reverse = True)
# print(card_list)

Alice = 0
Bob = 0
for i, j in enumerate(card_list):
    if (i + 1) % 2 == 0:
        Bob += j
    else:
        Alice += j

# print(Alice ,Bob)
diff = abs(Alice - Bob)
print(diff)

Submission status: Accepted

Solution code:
N = 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 = int(input())
A = sorted(list(int(i) for i in 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:
import numpy as np
_ = int(input())
arr = np.array(list(map(int, input().split())))

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

Submission status: Accepted

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

A = sorted(A, reverse=True)
print(sum(A[::2]) - sum(A[1::2]))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    cardlist = list(map(int, input().split()))
    cardlist.sort()

    alice_s, bob_s = 0, 0
    while cardlist != []:
        alice_s += cardlist.pop()
        if cardlist == []:
            break
        bob_s += cardlist.pop()
    ans = alice_s - bob_s
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
cardschar = input().split()
cards = []
for i in range(N):
    cards.append(int(cardschar[i]))

cards.sort()
cards.reverse()

Alice = 0
Bob = 0

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

print(Alice-Bob)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    b = input().split()
    a = [int(i) for i in b]
    if (N >= 1 and N <= 100):
        for i in a:
            if (i < 1 or i > 100):
                continue
    else:
        continue
    break
a.sort(reverse=True)

s = [0,0]
for i in range(len(a)):
    s[i%2] = a[i] + s[i%2]
print(s[0] - s[1])

Submission status: Accepted

Solution code:
N=int(input())
A=input()

A_list = A.split(" ")
A_int_list = list(map(int,A_list))

A_int_list.sort()
A_int_list.reverse()

alice=0
bob=0

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

print(alice-bob)

Submission status: Accepted

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

a.sort()
a.reverse()

alice = 0
bob = 0

a_num = len(a)

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

print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
alice,bob=0,0
cnt=0
for x in range(n):
    global alice
    global bob
    if cnt<n:
        alice+=a[cnt]
        cnt+=1
    if cnt<n:
        bob+=a[cnt]
        cnt+=1
print(abs(alice-bob))

Submission status: Accepted

Solution code:
n=int(input())
lst=list(map(int,input().split()))
al=0
bo=0
while True:
    m=max(lst)
    al+=m
    lst.remove(m)
    if len(lst)==0:
        break
    m=max(lst)
    bo+=m
    lst.remove(m)
    if len(lst)==0:
        break
print(al-bo)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input(''))
nums = sorted(map(int, input('').split()), reverse=True)
fp = sum(nums[::2])
sp = sum(nums[1::2])
print(fp - sp)

Submission status: Accepted

Solution code:

N = int(input())

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

A.sort()
A.reverse()

Alice = 0
Bob = 0

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

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int, input().split()))
A, B = 0, 0
while cards != []:
    A += cards.pop(max(zip(cards, range(len(cards))))[1])
    if cards == []:
        break
    B += cards.pop(max(zip(cards, range(len(cards))))[1])
print(A - B)

Submission status: Accepted

Solution code:
alice = 0
bob = 0
ignore= input()
cards = []
cards.extend(map(int,input().split()))
for i in sorted(cards,reverse=True)[0::2]:
    alice += i
for i in sorted(cards,reverse=True)[1::2]:
    bob += i
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
A.sort(reverse=True)
Alice = sum(A[::2])
Bob = sum(A[1::2])

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
alice = 0
bob = 0
n = int(input())

a = sorted(list(map(int, input().split(' '))), reverse=True)
for i in a[::2]: alice += i
for i in a[1::2]: bob += i

print(alice - bob)

Submission status: Accepted

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

for i in asrt[::2]: alice += i
for i in asrt[1::2]: bob += i
print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
ans = 0
for i in range(len(a)):
    if i % 2 == 1:
        ans -= a[i]
    else:
        ans += a[i]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
Alice = []
Bob = []
for idx, v in enumerate(a_list):
    if idx % 2 == 0:
        Alice.append(v)
    else:
        Bob.append(v)
print(sum(Alice) - sum(Bob))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, 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 = sorted(a, reverse=True)
i = 0
ans = 0

for num in a:
    if(i % 2 == 0):
        ans += num
    else:
        ans -= num
    i += 1

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,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, a, x, s = int(input()), sorted(list(map(int, input().split()))), 1, 0
while(a):
    s += x*a.pop()
    x *= -1
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
alice = 0
bob = 0

cards = list(map(int,input().split()))
cards = sorted(cards)

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

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
A_cards = []
B_cards = []
flag = 'A'
for card in A:
    if flag == 'A':
        flag = 'B'
        A_cards.append(card)
    elif flag == 'B':
        flag = 'A'
        B_cards.append(card)
print(sum(A_cards) - sum(B_cards))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a_line_map = map(int, input().split(' '))

#sorted_a_map <- a_line_map 降順ソート
sorted_a_map = sorted(a_line_map, reverse=True)
#diff_map <- sorted_a_map 奇数 -1倍
diff_map = (num if i%2==0 else -num for i,num in enumerate(sorted_a_map))
print(sum(diff_map))

Submission status: Accepted

Solution code:
N = int(input())
lines = input().split(' ')
lines = [int(x) for x in lines]
a_list = sorted(lines)
A = 0
B = 0


while len(a_list) > 0:
	A += a_list.pop()
	if len(a_list) > 0:
		B += a_list.pop()

print(A - B)

Submission status: Accepted

Solution code:
N = int(input())
a_line_map = map(int, input().split(' '))

sorted_a_map = sorted(a_line_map, reverse=True)
dif_gen = (-num if i%2==1 else num for i, num in enumerate(sorted_a_map))
print(sum(dif_gen))

Submission status: Accepted

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

Submission status: Accepted

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

sumA=0
sumB=0

for i in range(0,N,2):
    sumA+=list[i]
for j in range(1,N,2):
    sumB+=list[j]

print(sumA-sumB)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = sorted(a, reverse=True)
Alice = sum(l[::2])
Bob = sum(l[1::2])


print(Alice - Bob)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
a_list = sorted(list(map(int, input().split(' '))))

score_list = [0] * 2

available_cards = deque(a_list)

while len(available_cards) != 0:
    score_list[0] += available_cards.pop()
    try:
        score_list[1] += available_cards.pop()
    except:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
a.reverse()
bob = 0
i = 0
while 2*i + 1 < len(a):
    a[2*i + 1] = -a[2*i + 1]
    i += 1

print(sum(a))

Submission status: Accepted

Solution code:
input()
numbers = list(map(lambda x: int(x), input().split(" ")))
numbers.sort(reverse=True)
alice = 0
bob = 0
isAlice = True;
for number in numbers:
    if isAlice:
        alice += number
        isAlice = False
    else:
        bob += number
        isAlice = True

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
card = list(map(int,input().split()))
A = 0
B = 0
card.sort(reverse = True)
while True:
    A += card[0]
    card.pop(0)
    if not card:
        break
    B += card[0]
    card.pop(0)
    if not card:
        break
print(A - B)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    A.sort(reverse=True)
    alist = [x for i, x in enumerate(A) if i % 2 == 0]
    blist = [x for i, x in enumerate(A) if i % 2 != 0]
    print(sum(alist) - sum(blist))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = raw_input()
a = sorted(map(int,raw_input().split()), reverse=True)
print sum(map(lambda x:x[1],filter(lambda (i,x): i%2==0, enumerate(a)))) - sum(map(lambda x: x[1], filter(lambda (i,x): i%2!=0, enumerate(a))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def game(a, n):
    cards = sorted(a, reverse=True)
    alice = [cards[i] for i in range(n) if i % 2 == 0]
    bob = [cards[i] for i in range(n) if i % 2 != 0]
    return sum(alice) - sum(bob)


if __name__ == '__main__':
    n = int(input())
    a = map(int, input().split())
    print(game(a, n))

Submission status: Accepted

Solution code:
N = int(input())

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

a.sort()
ali = 0
bob = 0

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(int(i) for i in input().split())
a.sort(reverse = True)
A, B = 0, 0

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
number_list = list(map(int, input().split()))
sort_number_list = sorted(number_list, reverse=True)
 
Alice = 0
Bob = 0
for i, x in enumerate(sort_number_list):
  i += 1
  if i % 2 != 0:
    Alice += x
  else:
    Bob += x

print("{}".format(Alice - Bob))

Submission status: Accepted

Solution code:
def solve():
    N = int(input())

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

    sorted_cards = sorted(cards, reverse=True)

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

    print(Alice-Bob)


solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    a_sorted = sorted(a, reverse=True)

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

    print(alice - bob)

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(n):

    max_num = max(s)

    if i % 2 == 0:
        alice += max_num
    else:
        bob += max_num

    s.remove(max_num)

print(abs(alice - bob))

Submission status: Accepted

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

if n > 1:
    print(sum(cards[::2])-sum(cards[1::2]))
else:
    print(cards[0])

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


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

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

    return alice - bob


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
card=list(map(int,input().split()))
card.sort()
result=0
while len(card)>0:
   result+=card.pop()
   if len(card)>0:
       result-=card.pop()
print(result)