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=list(map(int,input().split()))
A=0
B=0
if N%2==0:
  for i in range(int(N/2)):
    A=A+max(a)
    a.remove(max(a))
    B=B+max(a)
    a.remove(max(a))
else:
  for i in range(int(N/2)+1):
    a.append(0)
    A=A+max(a)
    a.remove(max(a))
    B=B+max(a)
    a.remove(max(a))
  
print(A-B)

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):
    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()))
if len(a)%2 != 0:
    a.append(0)
    N += 1
alice = []
bob = []
for i in range(int(N/2)):
    alice.append(a.pop(a.index(max(a))))
    bob.append(a.pop(a.index(max(a))))
print(sum(alice)-sum(bob))

Submission status: Accepted

Solution code:
n = int(input())

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

#print(a)

score1 = []
score2 = []

while len(a) > 0:
    pick = max(a)
    score1.append(pick)
    a.remove(pick)
    if len(a) == 0:
        break
    
    pick = max(a)
    score2.append(pick)
    a.remove(pick)
    
#print(score1)
#print(score2)
print(sum(score1) - sum(score2))

Submission status: Accepted

Solution code:
N = int(input())
a = sorted(map(int, 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(reverse=True)
ans = sum(a)
for i in range(n):
    if i%2 == 1:
        ans -= 2*a[i]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x = int(input())
y = [int(i) for i in input().split()]
y.sort(reverse=True)
a = 0
b = 0
for i in range(1, x+1):
    if (i % 2) != 0:
        a += y[i-1]
    else:
        b += y[i-1]
print(a-b)

Submission status: Accepted

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

a = 0
b = 0

for i in range(1,x+1):
  if (i % 2) != 0:
    a += y[i-1]
  else:
    b += y[i-1]

print(a-b)

Submission status: Accepted

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

# a[i]を降順にソート
a.sort(reverse=True)

# A_total = Aliceの点数、B_total = Bobの点数
A_total = 0
B_total = 0

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

print(A_total - B_total)

Submission status: Accepted

Solution code:
N = int(input())

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

count = 0
allice_total = 0
bob_total = 0
for a in a_list:
    if count % 2 == 0:
        allice_total += a
    else:
        bob_total += a
    count += 1

print(allice_total - bob_total)

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(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()))
r = sorted(a, reverse=True)
ans = 0
for i in range(N):
  if i % 2 == 0:
    ans += r[i]
  else:
    ans -= r[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a.sort(reverse=True)

alice = 0
bob = 0

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

ans = alice - bob

print(ans)

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

Submission status: Accepted

Solution code:
#input
N = int(input())
#B = int(input())
#C = int(input())
#X = int(input())
A = list(map(int,input().split()))
#b = int(input())
#N,A,B = map(int,input().split())
 
turn = 0 # 0:Alice,1:Bob
Alice = 0
Bob = 0
Dif = 0
#flag = 0

top = [0,0]
while (1):
  flag = N
  top = [0,0]
  
  #seeking the top
  for i in range(N): #loop for N
    if A[i] > top[0]:
      top[0] = A[i]
      top[1] = i
    elif A[i] == 0:
      flag -= 1
  
  #point
  if turn == 0:
    turn = 1
    Alice += top[0]
    A[top[1]] = 0
    #print('Alice')
  elif turn == 1:
    turn = 0
    Bob += top[0]
    A[top[1]] = 0
    #print('Bob')
  
  #print(flag)
  #all pointed
  if flag <= 1:
    #print(flag)
    break

#judge
 
#print('result')
#print('Alice = '+str(Alice))
#print('Bob = '+str(Bob))
#print('Alice-Bob = '+str(Alice-Bob))
print(Alice-Bob)

Submission status: Accepted

Solution code:
#2019/10/25
N, *a = map(int, open(0).read().split())
a = sorted(a)[::-1]
# print(N, a)
print(sum(a[::2])-sum(a[1::2]))

Submission status: Accepted

Solution code:
import numpy as np
n= int(input())
a_list = sorted(list(map(int, input().split())),reverse=True)
a_array = np.array(a_list)
alice = a_array[::2]
bob = a_array[1::2]
print(sum(alice)-sum(bob))

Submission status: Accepted

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

Submission status: Accepted

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

list1.sort(reverse=True)

alice = 0
bob = 0

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

print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()],reverse=True)
A = [a[0]]
B = []
for i in range(1,n):
  if i % 2 == 0:
    A.append(a[i])
  else:
    B.append(a[i])
print(sum(A)-sum(B))

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int, input().split()))
ls.sort(reverse=True)
alice_point = 0
bob_point = 0

for i in range(n):
  if i % 2 == 0:
    alice_point += ls[i]
  else:
    bob_point += ls[i]

difference = alice_point - bob_point
print(difference)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
card = [int(i) for i in input().split()]

Alice = 0
Bob = 0
flag = True

card.sort(reverse = True)
for i in card:
  if flag == True:
    Alice += i
    flag = False
  else:
    Bob += i
    flag = True
  
print(Alice - Bob)

Submission status: Accepted

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

# Nの入力
N = int(input())

# a1,a2 ~ aNまでの入力
a = list(map(int,input().split()))

# aの配列を降順にソートする
a.sort(reverse = True)

# aclie合計　と　bob合計
alice = sum(a[::2])
bob = sum(a[1::2])

# 出力
print(alice-bob)

Submission status: Accepted

Solution code:
import numpy as np

n=int(input())
a_list=list(map(int,input().split()))
a_list_2=sorted(a_list,reverse=True)
a=np.array(a_list_2,dtype='uint8')

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

a.sort(reverse=True)

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

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

print(r)

Submission status: Accepted

Solution code:
n=int(input())

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

c.sort(reverse=True)

alice = sum([c[i] for i in range(len(c)) if i%2==0])

print(2*alice-sum(c))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  if i%2==0:
    result += x[i]
  elif i%2!=0:
    result -= x[i]
  
print(result)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
point = 0
calc = True
for i in a:
    if calc:
        calc = False
        point += i
    else:
        calc = True
        point -= i

print(point)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()), 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()
a=a[::-1]
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 = [int(i) for i in input().split()]

a = sorted(a, reverse=True)
scr_a = 0
scr_b = 0

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

print(scr_a - scr_b)

Submission status: Accepted

Solution code:
n = int(input())
s = sorted(list(map(int, input().split())), reverse=True)
A = 0
B = 0
for e, i in enumerate(s):
  if e%2==0:
    A += i
  else:
    B += i
print(A-B)

Submission status: Accepted

Solution code:
N = int(input())
Alice_total = 0
Bob_total = 0
card_list = input().split()
card_list = [int(n) for n in card_list]
card_list.sort(reverse =True)

for i in range(0,N,2):
    Alice_total += card_list[i]

for i in range(1,N,2):
    Bob_total += card_list[i]

print(Alice_total - Bob_total)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
A=sum(a[0::2])#リストの奇数項をとる
B=sum(a[1::2])
print(A-B)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
alice = sum(A[::2])
bob = sum(A[1::2])
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = map(int,input().split())
A = list(a)
A.sort(reverse = True)
ans = 0
_ans = 0
for i in range(N):
  _i = i * 2
  if _i <= N-1 :
    ans += A[_i]
for _q in range(N):
  _ii = _q * 2 +1    
  if _ii <= N-1:
    _ans -= A[_ii]
print(ans + _ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
odds = sum(a[1::2])
even = sum(a[0::2])
if odds >= even:
    print(odds-even)
else:
    print(even-odds)

Submission status: Accepted

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

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

Submission status: Accepted

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

s = sorted(s, reverse=True)

Alice = 0
Bob = 0

for i, x in enumerate(s):
  if i%2==0:
    Alice+=x
  else:
    Bob+=x
    
print(str(Alice-Bob))

Submission status: Accepted

Solution code:
import heapq

N = int(input())
A = [-int(x) for x in input().split()]
ans=0
j=-1
heapq.heapify(A)

for i in range(N):
    ans +=heapq.heappop(A)*j
    j*=-1
    
print(ans)

Submission status: Accepted

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

ans = sum(li[::2]) - sum(li[1::2])
print(ans)

Submission status: Accepted

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

a.sort()
a.reverse()

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())
a=sorted([int(_) for _ in input().split()], key=lambda x: -x)
print(sum(a[::2])-sum(a[1::2]))

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

Submission status: Accepted

Solution code:



def main():



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




if __name__ == "__main__":
    main()

Submission status: Accepted

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

a=0
b=0
for i in range(len(A)):
	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)
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=input()
c=sorted(list(map(int,input().split())))[::-1]
n=0
for i in c[0::2]:
  n+=i
for i in c[1::2]:
  n-=i
print(n)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort(reverse=True)
    print(sum(a[0::2]) - sum(a[1::2]))


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
n = input()
li = list(map(int,input().split()))
li.sort(reverse=True)
Alice = 0
Bob = 0
count = 1
for i in li:
    if count % 2:
        Alice += i
        count += 1
    else:
        Bob += i
        count += 1
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]

difference = alice - bob

print(difference)

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

result = 0
while len(a_n)>0:
    result +=a_n.pop()
    if len(a_n)>0:
        result  -=a_n.pop()
print(result)

Submission status: Accepted

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


def solve(N: int, a: "List[int]"):
    alice, bob = [0] * 2
    for i, v in enumerate(reversed(sorted(a))):
        if i % 2 == 0:
            alice += v 
        else:
            bob += v
    print(alice - bob)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ls = [int(s) for s in input().split()]
ls = sorted(ls,reverse=True)
alice = 0
bob = 0
for i in range(N):
  if i%2==0:
    alice += ls[i]
  else:
    bob += ls[i]
print(alice-bob)

Submission status: Accepted

Solution code:
N=int(input())
ls=sorted([int(s) for s in input().split()],reverse=True)
print(sum([ls[i]*((-1)**i) for i in range(N)]))

Submission status: Accepted

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

a_p = 0
b_p = 0

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

print(a_p - b_p)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
tot = sum(A)
cnt = 0
for i in range(0,N,2):
    cnt += A[i]
print(2*cnt-tot)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    cards = string_to_int(inputs[0])
    cards.sort(reverse=True)
    count_a = 0
    count_b = 0
    turn_a = True
    for card in cards:
        if turn_a:
            count_a += card
        else:
            count_b += card
        turn_a = not turn_a
    return count_a - count_b


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A = sorted(A, reverse=True)
a = 0
b = 0
for i in range(N):
    if i%2==0:
        a+=A[i]
    else:
        b += A[i]
print(a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc088/tasks/abc088_b
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:
# https://atcoder.jp/contests/abc088/tasks/abc088_b
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

alice = 0
bob = 0
for i in range(n//2 + 1):
    if len(a) > 0:
        alice += a.pop(0)
    if len(a) > 0:
        bob += a.pop(0)

print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
alice_cards = []
bob_cards = []
all_cards = list(map(int, input().split()))
all_cards.sort()
while len(all_cards) > 0:
    alice_cards.append(all_cards.pop(-1))
    if len(all_cards) == 0:
        break
    else:
        bob_cards.append(all_cards.pop(-1))
print(sum(alice_cards) - sum(bob_cards))

Submission status: Accepted

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

turn = 0
alice = 0
bob = 0

for i in range(n):
    turn += 1
    if turn%2 != 0:
        alice += max(a_list)
        
    else:
        bob += max(a_list)
    a_list.remove(max(a_list))

print(alice - bob)

Submission status: Accepted

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

a=sorted(a,reverse=True)
b=0
c=0

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


print(b-c)

Submission status: Accepted

Solution code:
def bb088():
    n = int(input())
    an = list(map(int, input().split()))
    an.sort()

    a = 0
    b = 0
    for i in range(n-1, -1, -2):
        a += an[i]
        if i-1 >= 0:
            b += an[i-1]

    print(a-b)

bb088()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()

alice = 0
bob = 0
is_alice = True
for n in sorted(map(int, input().split()), reverse=True):
    if is_alice:
        alice += n
    else:
        bob += n
    is_alice = not is_alice

print(alice - bob)

Submission status: Accepted

Solution code:
N,*a = map(int,open(0).read().split())
a.sort(reverse=True)
al = 0
b = 0
for i in range(N):
    if i%2 == 0:
        al += a[0]
        del a[0]
    else:
        b += a[0]
        del a[0]
print(al-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
alice = []
bob = []

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

difference = abs(sum(alice) - sum(bob))
print(difference)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(abs(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)
b=a[0::2]
c=a[1::2]
print(sum(b)-sum(c))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
A = []
B = []
while True:
  A.append(max(a))
  a.remove(max(a))
  if len(a) == 0:
    break
  B.append(max(a))
  a.remove(max(a))
  if len(a) == 0:
    break
print(sum(A)-sum(B))

Submission status: Accepted

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

alice = 0
bob = 0

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

print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split())) 
li.sort(reverse = True)
a,b = 0,0
while li:
    a += li.pop(0)
    if len(li) == 0:
        break
    b += li.pop(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:
n = int(input())
a = sorted(map(int,input().split()))[::-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

c_L.sort(reverse=True)

alice,bob = 0,0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

#ai=a[i-1]とした
A=0
S=0
a.sort(reverse=True)
for i in range(N):
    S+=a[i]
    if i%2==0:
        A+=a[i]
print(abs(S-2*A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
t=list(map(int,input().split()))
t.sort(reverse=True)
a=0
b=0
d=0
e=0
if len(t)%2==0:
  for i in range(0,len(t),2):
    d+=t[i]
    e+=t[i+1]
  print(d-e)
else:
  for j in range(0,len(t),2):
    d+=t[j]
  for l in range(1,len(t),2):
    e+=t[l]
  print(d-e)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int , input().split()), 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=0
B=0
for i, a_ in enumerate(sorted(a,reverse=True)):
  if i%2==0:
    A=A+a_
  else:
    B=B+a_
print(A-B)

Submission status: Accepted

Solution code:
N = int(input())
c = list(map(int, input().split()))
c.sort(reverse = True)
A = []
B = []
n = 0
for i in c:
    if n % 2 == 0:
        A.append(i)
    else:
        B.append(i)
    n += 1
print(sum(A) - sum(B))

Submission status: Accepted

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

print(sum)

Submission status: Accepted

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


a = 0
b = 0

isAlice = True

while n > 0:
    
    if isAlice:
        a += max(arr)
        isAlice = False
    else:
        b += max(arr)
        isAlice = True
    
    arr.remove(max(arr))
    n -= 1
    
print(a - b)

Submission status: Accepted

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

Submission status: Accepted

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


card_list.sort(reverse = True)

alice_list = []
bob_list = []
if N % 2 == 0:
    for i in range(0, N, 2):
        alice_list.append(card_list[i])
    for i in range(1, N, 2):
        bob_list.append(card_list[i])
else:
    for i in range(0, N + 1, 2):
        alice_list.append(card_list[i])
    for i in range(1, N, 2):
        bob_list.append(card_list[i])


alice_score = sum(alice_list)
bob_score = sum(bob_list)

ans = alice_score - bob_score
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
asum = 0
bsum = 0
for a in A[0::2]:
  asum += a
for a in A[1::2]:
  bsum += a
print(asum - bsum)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a 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)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(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())
a = input().split()
a = [int(i) for i in a]
a = list(reversed(sorted(a)))

alice = sum([int(a[i]) for i in range(0, n, 2)])
bob = sum([int(a[i]) for i in range(1, n, 2)])

print(alice-bob)

Submission status: Accepted

Solution code:
# ABC088B - Card Game for Two
def main():
    N, *A = map(int, open(0).read().split())
    A.sort(reverse=1)
    ans = sum(A[::2]) - sum(A[1::2])
    print(ans)


if __name__ == "__main__":
    main()