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())
c = list(map(int,input().split()))
c.sort(reverse = True)
a = 0
b = 0
if n % 2 == 0:
    for i in range(n // 2 ):
        a += c[i * 2]
        b += c[i * 2 + 1]
else:
    for i in range(n // 2 ):
        a += c[i * 2]
        b += c[i * 2 + 1]
    a += c[n - 1]

print(a - b)

Submission status: Accepted

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

a.sort(reverse=True)

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

print(cnt)

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

Alice=0
Bob=0

for j in range(N):
    if j%2==0:
        Alice+=max(A)
        A.remove(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.sort(reverse = True)
ans = 0
f = 0
for a in A:
  if f == 0:
    ans += a
  else:
    ans -= a
  f ^= 1
print(ans)

Submission status: Accepted

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

A.sort(reverse = True)

alc = 0
bob = 0

N -= 1
end = int(N/2) + 1

if N % 2 == 0:
    f = 1
else:
    f = 0

for i in range(0, end):
    alc += A[2*i]
    if f == 1 and 2*i == N:
        break
    bob += A[2*i+1]

print(alc-bob)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = list(map(int,input().split()))
    Alice = 0
    Alice_j = True
    Bob = 0
    Bob_j = False
    a.sort(reverse = True )
    for i in range(N):
        if Alice_j == True:
            Alice += a[i]
            Alice_j = False
            Bob_j = True
        elif Bob_j == True:
            Bob += a[i]
            Bob_j = False
            Alice_j = True
    return Alice - Bob

print(main())

Submission status: Accepted

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

while Ai:
    Alice += max(Ai)
    Ai.remove(max(Ai))
    if not Ai:
        break
    Bob += max(Ai)
    Ai.remove(max(Ai))

print(Alice-Bob)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    a = sorted(LI(), reverse=True)
    alice = 0
    for i in range(0, n, 2):
        alice += a[i]
    print(2 * alice - sum(a))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

a.sort(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:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

a = sorted(a, reverse=True)

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

print(x-y)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = sorted(list(mapint()), reverse=True)

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

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
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=sorted(a)

alice=0
bob=0
i=0
while a:
    if i%2==0:
        alice+=a.pop()
    else:
        bob+=a.pop()
    i+=1
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

arr.sort(reverse=True)

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

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:
n = int(input())
al = list(map(int, input().split()))
al.sort(reverse=True)
ali = 0
bob = 0
for i,a in enumerate(al):
    if i%2 == 0: ali += a
    else: bob += a

print(ali-bob)

Submission status: Accepted

Solution code:


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    n = int(input())
    a = sorted([int(i) for i in input().split()], reverse=True)

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

    print(alice - bob)

Submission status: Accepted

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

Alice, Bob = 0, 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())
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())
aa = list(sorted(map(int, input().split())))
print(abs(sum(aa[::2]) - sum(aa[1::2])))

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N = int(input())
a_list = list(map(int,input().split()))

Alice = 0
Bob = 0

a_list.sort(reverse=True)

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

print(Alice-Bob)

Submission status: Accepted

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

a.sort()
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += a[n-1-i]
    elif i % 2 == 1:
        bob += a[n-1-i]

print(alice - bob)

Submission status: Accepted

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

l.append(0)
_n = int(len(l)/2)

a = 0
b = 0

l.sort(reverse=True)

for i in range(_n):
  a += l[i*2]
  b += l[i*2 + 1]

print(a-b)

Submission status: Accepted

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

Card.sort(reverse=True)

if len(Card)>=2:
    A = sum(Card[::2])
    B = sum(Card[1::2])
else:
    A = Card[0]
    B = 0

print(A-B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    cards=[]
    sorted_cards=[]
    n = int(input())
    cards=list(map(int,input().split()))
    sorted_cards=sorted(cards,reverse=True)
    alice=0
    bob=0

    for idx,card in enumerate(sorted_cards):
        if idx%2==0:
            alice+=card
        else:
            bob+=card
    print(alice-bob)

if __name__=="__main__":
    main()

Submission status: Accepted

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


def solve(N: int, a: "List[int]"):
    a.sort(reverse=True)
    return sum(a[::2]) - sum(a[1::2])

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
a.sort()

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

print(alice - bob)

Submission status: Accepted

Solution code:
#!/user/bin/env pypy3
import sys
from typing import List


def fast_input():
    return sys.stdin.readline()[:-1]


def solve(cards: List[int]) -> int:
    sorted_cards = sorted(cards, reverse=True)
    alice = 0
    bob = 0
    for i, card in enumerate(sorted_cards):
        if i % 2 == 0:
            alice += card
        else:
            bob += card
    return alice - bob


def main():
    n = int(fast_input())
    a = list(map(int, fast_input().split()))
    result = solve(a)
    print(result)


main()

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0

a.sort(reverse = True)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
array = list(map(int, input().split()))
array.sort()
sum_1 = 0
sum_2 = 0

for i in range(N):
    if i % 2 == 0:
        sum_1 += array[-1]
        array.pop(-1)
        
    else:
        sum_2 += array[-1]
        array.pop(-1)
print(sum_1 - sum_2)

Submission status: Accepted

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

arr.sort(reverse=True)
answer = [0, 0]
for index in range(len(arr)):
    answer[index % 2] += arr[index]
print(answer[0] - answer[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N = input()
num_list = list(map(int,input().split(' ')))
i = 0
Bob = 0
Alice = 0
for n in sorted(num_list, reverse=True):
  i += 1
  if i % 2 == 1:
    Bob += n
  elif i % 2 == 0:
    Alice += n
ans = Bob - Alice
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
offset = True if len(A) % 2 == 0 else False
alice = sum(A[offset::2])
bob = sum(A[not offset::2])
print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x.strip()) for x in input().split()]
a = sorted(a, reverse=True)
alice,bob = 0,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 sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    a = list(map(int, readline().split()))
    a.sort(reverse=True)

    x = sum(a[::2])
    y = sum(a[1::2])

    print(x - y)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
score_A = 0
score_B = 0
a.sort(reverse=True)
i = 1
for n in a:
  if i % 2 == 1:
    score_A += n
  elif i % 2 == 0:
    score_B += n
  
  i += 1


result = score_A - score_B
print(result)

Submission status: Accepted

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

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

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 = input("").split(" ")
a = [int(aa) for aa in a]
ap = 0
bp = 0
temp = 0
for c in range(len(a)):
    if c % 2 == 0:
        temp = a.pop(a.index(max(a)))
        ap += temp
    else:
        temp = a.pop(a.index(max(a)))
        bp += temp
print(str(abs(ap-bp)))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
alice = []
bob = []

for i in range(n):
    if i % 2 == 0:
        alice.append(max(a))
        a.remove(max(a))
    else:
        bob.append(max(a))
        a.remove(max(a))

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

Submission status: Accepted

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

alice=sum(s[::2])
bob=sum(s)-alice
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(a)-s*2)

Submission status: Accepted

Solution code:
# coding: utf-8

num = int(input())
str = input().split()
table = [int(i) for i in str]

table2 = sorted(table, reverse = True)
a_point = 0
b_point = 0

for i in range(num):
    if i % 2 == 0:
        a_point += table2[i]
    elif i % 2 == 1:
        b_point += table2[i]
print(a_point - b_point)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
alice = 0
bob = 0
a.sort()
i = 0
for x in reversed(a):
  if(i%2==0):
    alice += x
  else:
    bob += x
  i += 1
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a, b, turn = 0, 0, 1
while len(A) != 0:
    if turn & 1:
        a += A.pop()
    else:
        b += A.pop()
    turn += 1
print(a-b)

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

Alice = []
Bob = []

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

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

while len(a) > 0:
    Alice.append(a.pop(0))
    Bob.append(a.pop(0))

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

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    li.sort(reverse=True)
    a = sum(li[::2])
    b = sum(li[1::2])
    ans = a - b
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
A,B = [],[]
for num in range(n):
    if(num == 0 or num % 2 == 0):
        A.append(a[num])
    else:
        B.append(a[num])
print(sum(A)-sum(B))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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


print(alice-bob)

Submission status: Accepted

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

Alice = 0
Bob = 0
while len(cards) >= 2:
    Alice += cards[-1]
    cards = cards[:-1]
    Bob += cards[-1]
    cards = cards[:-1]
if len(cards) == 1:
    Alice += cards[-1]
print(Alice - Bob)

Submission status: Accepted

Solution code:
# 2020-08-30, Sun

n = int(input())
lis = sorted(list(map(int, input().split())), reverse=True)
a = 0
b = 0

for i in lis[::2]:
    a += i

for i in lis[1::2]:
    b += i

print(a - b)

Submission status: Accepted

Solution code:
# 2020-08-30, Sun

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
x = 0
y = 0
for i in range(len(a)):
    b = a.pop()
    if i % 2 == 0:
        x += b
    else:
        y += b
print(x - y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = sorted(map(int, input().split()))
a = 0
b = 0
for i in range(n):
  if i % 2 == 0:
  	a += l.pop()
  else:
    b += l.pop()
print(a - b)

Submission status: Accepted

Solution code:
N = input()
A = list(input().split())
A = list(map(int,A))
A = sorted(A,reverse = True)
a = 0
b = 0
try :
  while len(A) != 0 :
    a += A.pop(0)
    b += A.pop(0)
  print(a-b)
except IndexError :
  print(a-b)

Submission status: Accepted

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

print(abs(a-b))

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(int(N/2) + 1):
	if len(cards) > 0:
		alice += max(cards)
		cards.remove(max(cards))
	if len(cards) > 0:
		bob += max(cards)
		cards.remove(max(cards))
	
print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
la = list(map(int, input().split()))
la.sort(reverse=True)
a = 0
b = 0
for i in range(n):
  if i%2==0:
    a += la[i]
  else:
    b += la[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):
    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=[]
B=[]

for i in range(len(a)):
    if i%2==1:
        A.append(a[i])
    else:
        B.append(a[i])

print(abs(sum(A)-sum(B)))

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:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=0
c=0
for i in range(n):
  if i%2==0:
    b+=a[i]
  else:
    c+=a[i]
print(b-c)

Submission status: Accepted

Solution code:
"""Boot-camp-for-Beginners_Easy010_B_Toll-Gates_29-August-2020.py"""
import numpy as np

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

Alice = [a[i] for i in range(0, len(a), 2)]
Bob = [a[i] for i in range(1, len(a), 2)]
#print(Alice)
#print(Bob)

s_max = 0
for i in range(len(Alice)):
    s_max += Alice[i]
s_min = 0
for i in range(len(Bob)):
    s_min += Bob[i]
#print(s_max)
#print(s_min)
print(s_max-s_min)

Submission status: Accepted

Solution code:
N=int(input())
li=list(map(int, input().split()))
li.sort(reverse=True)
Alice=[]
Bob=[]

for i in range(N):
  if i%2==0:
    Alice.append(li[i])
  else:
    Bob.append(li[i])

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

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:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
cards = [int(s) for s in input().split()]

alice_total = 0
bob_total = 0

cards.sort(reverse=True)

for i in range(len(cards)):
  if i % 2 == 0:
    alice_total += cards[i]
  else:
    bob_total += cards[i]

diff = alice_total - bob_total
print(diff)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
# ソートしたとき、Aliceは偶数(0,2,...)番目を、Bobは偶数(1,3,...)番目を取る
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 = 0
B = 0
while True:
  m_a = max(a)
  A += m_a
  a.remove(m_a)
  if len(a) == 0: break
  
  m_b = max(a)
  B += m_b
  a.remove(m_b)
  if len(a) == 0: break

print(A-B)

Submission status: Accepted

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

alice = 0
bob = 0

cards.sort(reverse=True)

for i in range(loopCnt):
  if i == 0 or i%2 == 0:
    alice += cards[i]
  elif i%2 == 1:
    bob += cards[i]

print(alice-bob)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    score = [0, 0]
    sort_a = sorted(a, reverse=True)

    for i in range(n):
        if i >= 2:
            sub_i = i % 2
        else:
            sub_i = i
        score[sub_i] += sort_a[i]

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Card Game for Two
a=int(input())
b=list(map(int,input().split()))
b.sort()
total=0
total2=0
for i in range(a):
    if i%2==0:
        total+=b[i]
    else:
        total2+=b[i]
print(max(total,total2)-min(total,total2))

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse = True)

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

print(diff)

Submission status: Accepted

Solution code:
n = int(input())
alst = list(map(int, input().split()))
alst.sort(reverse = True)
ans = 0
pm = 1
for a in alst:
    ans += a * pm
    pm *= -1
print(ans)

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)
alice=sum(a[::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)
A = sum(a[0::2])
B = sum(a[1::2])
print(A-B)

Submission status: Accepted

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

a.sort(reverse=True)

pt_alice = 0
pt_bob = 0
alices_turn = True
for i in range(N):
    if alices_turn:
        pt_alice += a[i]
    else:
        pt_bob += a[i]
    alices_turn = not alices_turn

print(pt_alice-pt_bob)

Submission status: Accepted

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

while(cards != []):
    result += max(cards)
    cards.remove(max(cards))
    if cards != []:
        result2 += max(cards)
        cards.remove(max(cards))

print(result-result2)

Submission status: Accepted

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

Submission status: Accepted

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

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


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 088 B
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
aa = sorted(a)
for i in range(0, N, 2):
    A += aa[-i-1]
    if (i+2)<=N:
        B += aa[-i-2]
print(A-B)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al=lin()
	al.sort(reverse=True)
	return sum(al)-(2*sum(al[1::2]))
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n=int(input())
li=list(map(int,input().split()))
newli=sorted(li)
gu=[]
ki=[]
for i in range(n):
  if i%2==0:
    gu.append(newli[-(i+1)])
  else:
    ki.append(newli[-(i+1)])
print(sum(gu)-sum(ki))

Submission status: Accepted

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

alice =[]
bob = []

for i in range(len(a)):
    if i%2==0:
        alice.append(a[i])
    elif i%2 != 0:
        bob.append(a[i])
dif = sum(alice) - sum(bob)
print(dif)