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:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    a = 0
    b = 0
    for i, v in enumerate(A):
        if i % 2 == 0:
            a += v
        else:
            b += v
    ret = a - b
    print(ret)
    return


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

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

Submission status: Accepted

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

a.sort()
alice = []
bob = []
for i in range(N):
    if i%2 == 0:
        alice.append(a.pop())
    else:
        bob.append(a.pop())

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

Submission status: Accepted

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

sort_a = sorted(a, reverse=True)

cnt = 0
Alice = 0
Bob = 0
for i in sort_a:
    if cnt % 2 == 0:
        Alice += i
    else:
        Bob += i
    cnt += 1

print(Alice - Bob)

Submission status: Accepted

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

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

Submission status: Accepted

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

A.sort()
A.reverse()

Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())

num_list = sorted([ int(v) for v in input().split() ])

a_sum, b_sum = 0, 0

for i in range(n):
  if i % 2 == 0:
    a_sum += num_list[i]
  else:
    b_sum += num_list[i]

print(abs(a_sum-b_sum))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    _ = input()
    A = [int(e) for e in input().split()]
    A.sort(reverse=True)
    sum_a = 0
    sum_b = 0
    for i, e in enumerate(A):
        if i % 2 == 0:
            sum_a += e
        else:
            sum_b += e
    print(sum_a - sum_b)

main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
A = []
B = []
if n % 2 == 0:
    while len(a) > 0:
        A.append(max(a))
        a.remove(max(a))
        B.append(max(a))
        a.remove(max(a))
else:
    while len(a) > 1:
        A.append(max(a))
        a.remove(max(a))
        B.append(max(a))
        a.remove(max(a))
    A.append(max(a))
print(sum(A) - sum(B))

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l, reverse=True)
l_a=[]
l_b=[]
for i in range(n):
  if i%2==0:
    l_a.append(l1[i])
  else:
    l_b.append(l1[i])
print(sum(l_a)-sum(l_b))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
alice_list=[]
bob_list=[]
a.sort()
if n%2==0:
    for x in range(0,n):
        if x%2==1:
            alice_list.append(a[x])
        else:
            bob_list.append(a[x])
else:
    for x in range(0,n):
        if x%2==1:
            bob_list.append(a[x])
        else:
            alice_list.append(a[x])

alice_sum=sum(alice_list)
bob_sum=sum(bob_list)
ans=alice_sum-bob_sum


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
Ali=0
Bob=0
a.sort()
ab_flag=0
while len(a)!=0:
    if ab_flag==0:
        Ali += a.pop()
        ab_flag=1
    else:
        Bob += a.pop()
        ab_flag=0
print(Ali-Bob)

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n = II()
a = sorted(LI(), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

Solution code:
n = int(input())
dat_a = list(map(int, input().split()))
dat_a.sort()
a = 0
b = 0
while True:
    if len(dat_a) ==0:
        break
    a += dat_a.pop()

    if len(dat_a) ==0:
        break
    b += dat_a.pop()
print(a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
N = input()
L = list(map(int,input().split()))
L.sort()
L.reverse()

cnt = 0

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

print(cnt)

Submission status: Accepted

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

a.sort(reverse=True)

ans = 0

while len(a) > 0:
    ans += a.pop(0)
    if len(a) == 0:
        break
    ans -= a.pop(0)

print(ans)

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
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
Alice = sum(sorted(data)[0::2])
Bob   = sum(sorted(data)[1::2])
print(max(Alice,Bob)-min(Alice,Bob))

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:
numS = int(input())
num1 = [int(i) for i in input().split()]
num1.sort(reverse=True)

numA = []
numB = []

for index1 in range(numS ):
    if index1%2 == 0:
        numA.append(num1[index1])
    else:
        numB.append(num1[index1])

print(str(sum(numA) - sum(numB)))

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    n = intin()
    alist = intina()

    alist.sort(reverse=True)

    alice = 0
    bob = 0

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

    print(alice - bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
a_decending = a[::-1]
Alice = 0
Bob = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

# 先攻：a  後攻：b
a=b=0

# 数字が大きい順にソート
l.sort()
l.reverse()

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

# 出力
print(a-b)

Submission status: Accepted

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

    a_list = sorted(a_list, reverse=True)

    answer = 0
    for i in range(len(a_list)):
        if i % 2 == 0:
            if i + 1 <= len(a_list) - 1:
                answer += a_list[i] - a_list[i+1]
            else:
                answer += a_list[i]

    print(answer)

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

alice = 0
bob = 0

a.sort(reverse = True)

i = 0

while True:
    if i >= n:
        break
    alice += a[i]
    i += 1
    if i >= n:
        break
    bob += a[i]
    i += 1

print(alice - bob)

Submission status: Accepted

Solution code:
_ = 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:


def main():
    num = int(input())
    data = list(map(int, input().split()))
    data.sort(reverse=True)

    aaa = sum(data[::2])
    bbb = sum(data[1::2])

    print(aaa - bbb)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())) , reverse=True)
a,b = 0,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())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
alice = 0
bob = 0
alice_cards = cards[::2]
bob_cards = cards[1::2]
alice_sum = sum(alice_cards)
bob_sum = sum(bob_cards)
print(alice_sum - bob_sum)

Submission status: Accepted

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

n_list.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import numpy as np

def main():
    N = int(input())
    a = np.array([int(_) for _ in input().split(" ")])

    Alice = np.array([])
    Bob = np.array([])

    turn = 1
    while len(a) != 0:
        if int(turn%2) != 0:
            Alice = np.append(a.max(), Alice)
        else:
            Bob = np.append(a.max(), Bob)

        a = np.delete(a, a.argmax())
        turn += 1

    print(int(Alice.sum() - Bob.sum()))

main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    int(input())
    l = list(map(int, input().split()))
    # l = [2, 7, 4]
    l.sort()
    l.reverse()
    a = sum(l[::2])
    b = sum(l[1::2])
    print(a - b)

Submission status: Accepted

Solution code:
#Card Game for Two
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] > a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a

x = int(input())
cards = input()
card = cards.split(" ")
card = [int(s) for s in card]
bSort(card)
Alice = 0
Bob = 0

for i in range(0,len(card),2):
    Alice += int(card[i])
for i in range(1,len(card),2):
    Bob += int(card[i])
    
print(Alice - Bob)

Submission status: Accepted

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

A.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())

a = list(int(i) for i in input().split() )

a.sort() #リストaを昇順にソート

i = Alice = Bob = 0

while len(a) >= 1:
	if i % 2 == 0:
		Alice += a.pop(len(a)-1) #リストaの末尾の値を加えて、リストから削除
	elif i % 2 != 0:
		Bob += a.pop(len(a)-1) #リストaの末尾の値を加えて、リストから削除

	i += 1


print(Alice - Bob)

Submission status: Accepted

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

cardList.sort(reverse=True)

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

Submission status: Accepted

Solution code:
n = int(input())
cards = [int(i) for i in input().split()]
cards.sort(reverse=True)
a = 0
b = 0
for i, num in enumerate(cards):
    if(i % 2 == 0):
        a = a + num
    else:
        b = b + num
print(a - b)

Submission status: Accepted

Solution code:
#入力取得
N = int(input())
a = [int(i) for i in input().split()]

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

a_sum = 0
b_sum = 0

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

    elif i % 2 == 1:
        b_sum = b_sum + a[i]


print(a_sum - b_sum )

Submission status: Accepted

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

al = 0
bo = 0

for i in range(len(tmp)):
  if i %2 == 0:
    al = al + int(tmp[i])

  else:
    bo = bo + int(tmp[i])

print(al - bo)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()
alice = 0
bob = 0
for i in range(n-1, -1, -2):
    if i >= 0:
        alice += A[i]
    if i >= 1:
        bob += A[i-1]

print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
a2 = sorted(a,reverse=True)
if (len(a2)%2!=0):a2+=[0]
print(-sum(np.diff(a2)[::2]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

while a:
    al_val += max(a)
    a.remove(max(a))
    if not a: break
    bo_val += max(a)
    a.remove(max(a))

print(al_val - bo_val)

Submission status: Accepted

Solution code:
# 入力割り当て
N = int(input())
A = list(map(int, input().split()))

# sort
A_sort = sorted(A, reverse=True)

# 変数定義
n = 0
m = 0
i = 0

# 降順に割り当て
for i in range(N):
	if i%2 == 0:
		n += A_sort[i]
	else:
		m += A_sort[i]

# 結果の表示
ans = n - m
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if len(A) & 1:
  A.append(0)
A.sort()
print(sum([A[i+1]-A[i] for i in range(0, len(A), 2)]))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=0
a.sort()
a.reverse()
for i in range(0,n,2):
 d+=a[i]
arisu=d
bobu=sum(a)-d

print(arisu-bobu)

Submission status: Accepted

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

Submission status: Accepted

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

ali = 0
bo = 0

while len(a) > 0:
    ali += a.pop(a.index(max(a)))
    if len(a) == 0:
        break
    bo += a.pop(a.index(max(a)))

print(ali - bo)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
list.sort(a, 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()))
r = 0
for i in range(len(a)):
    m = max(a)
    a.remove(m)
    # print(m)
    if i % 2 == 0:
        r += m
    else:
        r -= m
print(r)

Submission status: Accepted

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

card.sort(reverse=True)

print(sum(card[::2]) - sum(card[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,s in enumerate(a):
    if (i+1)%2:
        alice+=s
    else :
        bob+=s
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 = input()
a = input().split()
N = int(N)
a = [int(s) for s in a]
Alice = 0
Bob = 0
a.sort()
a.reverse()
for num in range(N):
	if num % 2 == 0:
		Alice += a[num]
	else:
		Bob += a[num]
print(int(Alice - Bob))

Submission status: Accepted

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

for i in range(N//2):
    ali.append(A[i*2])
    bob.append(A[i*2+1])
if N%2==1:
    ali.append(A[-1])
    
        
print(sum(ali)-sum(bob))

Submission status: Accepted

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

Submission status: Accepted

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

t = sorted(t,key = lambda x:-x)

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

Submission status: Accepted

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

A.sort(reverse=True)
alice = sum([A[i] for i in range(0, N, 2)])
bob = sum([A[i] for i in range(1, N, 2)])
print(alice - bob)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a = sorted(a, reverse=True)
    Alice = [x for i, x in enumerate(a) if i % 2 == 0]
    Bob = [x for i, x in enumerate(a) if i % 2 != 0]
    print(sum(Alice) - sum(Bob))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

input()
a=sorted(ipt(),reverse=True)
print(sum(a[::2])-sum(a[1::2]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
m = list(map(int, input().split()))
m.sort(reverse=True)
a = 0
b = 0
t = True
for i in m:
  if t:
    a += i
  else:
    b += i
  t = True if not(t) else False
print(a-b)

Submission status: Accepted

Solution code:
_ = 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 = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
Alice = []
Bob = []
while len(A) != 0:
        Alice.append(A[0])
        A = A[1:]
        if len(A) != 0:
                Bob.append(A[0])
                A = A[1:]

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

Submission status: Accepted

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

x,y = 0,0

for i in range(0,n,2):
    x += b[i]
for i in range(1,n,2):
    y += b[i]

print(x-y)

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(i) for i in input().split()]
score_Alice = 0
score_Bob   = 0
turnA = True
a.sort(reverse = True)
for i in range(n):
  if turnA == True:
    score_Alice += a[i]
  else:
    score_Bob   += a[i]
  turnA = not turnA
print(score_Alice - score_Bob)

Submission status: Accepted

Solution code:
N = int(input())
s = list(map(int,input().split()))
s.sort()
alice = 0
bob = 0
for n in range((N+1)//2):
    alice += s[-1]
    del s[-1]
    try:
        bob += s[-1]
        del s[-1]
    except IndexError:
        break
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

    a.sort(reverse = True)

    Alice, Bob = 0, 0

    for turn in range(0, len(a), 2):
        Alice += a[turn]

    for turn in range(1, len(a), 2):
        Bob += a[turn]

    print(Alice - Bob)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

num_list = sorted(num_list)

point = 0
player = 1
while num_list:
    point += num_list.pop() * player
    player *= -1

print(point)

Submission status: Accepted

Solution code:
N = input()
a = list(map(int, input().split()))
a = sorted(a, reverse = True)
Alist = []
Blist = []
for i in range(len(a)):
    if i % 2 == 0:
        Alist.append(a[i])
    else:
        Blist.append(a[i])
print(sum(Alist) - sum(Blist))

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    a = sorted(a, reverse = True)

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

solve()

Submission status: Accepted

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

x = 0
y = 0

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

print(x - y)

X = []

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# abc088 b
#
n = int(input())
cards = list(map(int, input().split()))
a = 0
b = 0
for i in range(n):
    r = max(cards)
    if i % 2 == 0:
        a += r
    else:
        b += r
    cards.remove(r)
print(a-b)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(s) for s in input().split()]
A.sort()
vA = 0;
vB = 0;
for i in range(N):
    if (len(A) == 0):
        break
    vA += A.pop()
    if (len(A) == 0):
        break
    vB += A.pop()
print(vA - vB)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(num):
  if i//2*2 == i:
    alice += cards[i]
  else:
    bob += cards[i]

print(alice - bob)

Submission status: Accepted

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

if num//2*2 == num:
  for i in range(num//2):
    alice += cards[i*2]
    bob += cards[i*2+1]
else:
  for i in range(num//2):
    alice += cards[i*2]
    bob += cards[i*2+1]
  alice += cards[num-1]

print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
cards = list(map(int, input().split()))
remains = cards.copy()
alice, bob = [], []
while remains:
    a = max(remains)
    alice.append(a)
    remains.remove(a)
    if not remains:
        break
    b = max(remains)
    bob.append(b)
    remains.remove(b)
print(abs(sum(alice) - sum(bob)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  arr = sorted([int(x) for x in input().split()])[::-1]
  print(sum(arr[0::2]) - sum(arr[1::2]))


if __name__ == "__main__":
  main()

Submission status: Accepted

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

A_sorted = sorted(A, reverse=True)

Alice_point = 0; Bob_point = 0

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

print(ans)

Submission status: Accepted

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

a.sort()
alice=[]
bob=[]
for i in range(n):
    x=a.pop(-1)
    if i%2==0:
        alice.append(x)
    else:
        bob.append(x)

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

Submission status: Accepted

Solution code:
N = int(input())

a = sorted([int(x) for x 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(reverse=True)
ans = 0
for i,ai in enumerate(a):
    if i%2==0:
        ans += ai
    else:
        ans -= ai
print(ans)