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:
# ABC088B

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

# print(a_reverse)

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

print(Alice - Bob)

Submission status: Accepted

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

Alice = 0
Bob = 0

while len(a) > 0:
    m_a = max(a)
    Alice += m_a
    a.remove(m_a)

    if len(a) == 0:
        break
    else:
        m_a = max(a)
        Bob += m_a
        a.remove(m_a)

print(Alice-Bob)

Submission status: Accepted

Solution code:
N = 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)
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(" ")))
alice = []
bob = []
a.sort(reverse=True)
for k in range(int(n / 2) + 1):
    try:
        alice.append(a[2 * k])
        bob.append(a[2 * k + 1])
    except:
        pass
al = sum(alice)
bo = sum(bob)
res = abs(al - bo)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

score_a = 0
score_b = 0

for i, a in enumerate(sorted(A,reverse=True)):
    if i%2==0:
        score_a += a
    else:
        score_b += a
print(score_a-score_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:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
N=int(input())
# 文字列の入力
s = input()
a=s.split(' ')
a=list(map(int,a))
a=sorted(a)
a.reverse()
flg=1
ans=0
for i in a:
    ans = ans + (i*flg)
    flg = flg*-1
print(ans)
#print(s[0:K-1]+s[K-1].lower()+s[K:N])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
Alice = 0
Bob = 0
A.sort(reverse=True)
while 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())
a = list(map(int,input().split()))
a.sort(reverse=True)
x = 0
y = 0

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

Submission status: Accepted

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

#処理
a=sorted(a,reverse=True)

score_a=0
score_b=0

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

print(score_a-score_b)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

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())
X = list(map(int, input().split(' ')))

X.sort(reverse = True)

x = sum(X)
a = sum(X[0::2])

b = x - a

print(a-b)

Submission status: Accepted

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

def main():
    # 入力
    N = int(input())
    nums = list(map(int, input().split()))

    # 探索
    alice_sum = 0
    bob_sum = 0

    nums.sort(reverse=True)
    for i in range(len(nums)):
        if i % 2 == 0:
            alice_sum += nums[i]
        else:
            bob_sum += nums[i]

    print(alice_sum - bob_sum)


main()

Submission status: Accepted

Solution code:
N = int(input())
List = [int(x) for x in input().split()]
Sum = sum(List)
List.sort(reverse=True)
del List[::2]
Sum_B = sum(List)
Sum_A = Sum-Sum_B
print(Sum_A-Sum_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())
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()))
a.sort(reverse=True)
ans = 0
for i in range(n):
    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()))

alice = 0
bob = 0

a.sort(reverse=True)

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

print(alice - bob)

Submission status: Accepted

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


for i in range (n):
  if i%2 == 0:
    alice += an_s[i]
  elif i%2 != 0:
    bob += an_s[i]

ans = alice - bob
print(ans)

Submission status: Accepted

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

i = n
ca = 0
cb = 0
for i in range(n):
    if i%2 == 1:
        ca += a[i]
    else:
        cb += a[i]

print(abs(ca-cb))

Submission status: Accepted

Solution code:
N=int(input())
numbers=list(map(int,input().split()))
new_numbers=sorted(numbers,reverse=True)
Alice=0

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

Submission status: Accepted

Solution code:
import math
n = int(input())
li=list(map(int,input().split()))
li.sort(reverse = True)
al = 0
bo = 0
for i in range(0, n, 2):
    al += li[i]
    if (n % 2 == 1 and i == n - 1):
        break
    bo += li[i + 1]
print(al-bo)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
a_list = [int(a) for a in input().split(' ')]
a_list = sorted(a_list, reverse=True)
alice = list()
bob = list()
for i, a in enumerate(a_list):
    if i % 2 == 0:
        alice.append(a)
    else:
        bob.append(a)
print(sum(alice) - sum(bob))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)
alice = a[0::2]
bob = a[1::2]

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

Submission status: Accepted

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

a_n = sorted(a_n, reverse=True)

res = 0
for i in range(len(a_n)):
    if i % 2 == 0:
        res = res + a_n[i]
    else:
        res = res - a_n[i]
print(res)

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:
Alice = 0
Bob = 0

N = int(input())
A = [None] * N
A = list(map(int, input().split()))

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

print(Alice - Bob)

Submission status: Accepted

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

B=sorted(A,reverse=True)
alice_num=0
bob_num=0

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

print(alice_num-bob_num)

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
i = 0

for b in a:
    if (i % 2)==0: Alice += b
    else: Bob += b
    i += 1
print((Alice-Bob))

Submission status: Accepted

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

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:
i = int(input())
nums = list(map(int,input().split()))
num = sorted(nums,reverse=True)
a = 0
b = 0
for index,n in enumerate(num):
	if (index+1)  % 2 != 0:
		a += n
	else:
		b += n
print(a-b)

Submission status: Accepted

Solution code:
#N,K = map(str,input().split())
N = int(input())
#K = int(input())
X = list(map(int,input().split()))
Y=X.copy()
A=[]
B=[]
while Y:
    a=max(Y)
    A.append(a)
    Y.remove(a)
    if not Y:
        break
    b=max(Y)
    B.append(b)
    Y.remove(b)
print(sum(A)-sum(B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

point_a=0
point_b=0

#全てのカードがなくなるまで（＝すべての変数値が0になったらカード無）
#一番目に大きい数値をアリスに
#二番目に大きい数値をボブに
while max(a)>0:
    #一番目に大きい数値をアリスに
    point_a+=max(a)
    #この数値をゼロに戻す
    a[a.index(max(a))]=0
    #二番目に大きい数値（この時点で一番大きい数値）をボブに
    point_b+=max(a)
    #この数値をゼロに戻す
    a[a.index(max(a))]=0

#答え
print(point_a-point_b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
A = a[1::2]
B = a[0::2]
ScoreA = sum(A)
ScoreB = sum(B)
C = abs(ScoreA - ScoreB)
print(C)

Submission status: Accepted

Solution code:
N = int(input())
A = 0
B = 0
ls1 = list(map(int,input().split()))
ls1.sort()
ls1.reverse()
for i in range(N):
    if i%2 == 0:
        A += ls1[i]
    else:
        B += ls1[i]
print(A-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())  #一応読むけど、ループ回せば不要では
aList=list(map(int,input().split()))

aList.sort(reverse = True)

ap = 0
bp = 0

for i,a in enumerate(aList):
    if i%2 == 0: #0から始まるので偶数奇数逆で考える
        ap = ap + a
    else:
        bp = bp + a
print(ap-bp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Alice = sum(a[i] for i in range(len(a)) if i % 2 == 0)
Bob = sum(a[i] for i in range(len(a)) if i % 2 == 1)

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = 0
for i in range(n):
    ans += a[i] * (-1 if i & 1 else 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:
# Problem: https://atcoder.jp/contests/abc088/tasks/abc088_b
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(cardNumberList):
    result = 0
    cardNumberList.sort(reverse=True)

    # algorithm
    # Alices'Turn
    for j in range(0, len(cardNumberList), +2):
        result = result + cardNumberList[j]
    # Bobs'Turn
    for j in range(1, len(cardNumberList), +2):
        result = result - cardNumberList[j]
    return result


if __name__ == "__main__":
    _ = II()
    AI = LI()
    print("{}".format(solver(AI)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def readlines(n):
    for i in range(n):
        for j, x in enumerate(input().split()):
            yield int(x), (i, j)


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


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
count = 1
A = []
B = []
for a in l:
    if count % 2 == 1:
        A.append(a)
    else:
        B.append(a)
    count += 1
print(sum(A) - sum(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 = list(map(int, input().split()))
Alice = 0
Bob = 0
for i in range(N):
  if (i+1)%2 == 1:
    Alice += max(a)
    a.remove(max(a))
  else:
    Bob += max(a)
    a.remove(max(a))
print(Alice - Bob)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

N = int(input())
a = [int(i) for i in input().split()]
Alice = 0
Bob = 0
count = 0
while not all((x == 0 for x in a)):
  if count%2 == 0:
    max_value = max(a)
    Alice += max_value
    max_index = a.index(max_value)
    a[max_index] = 0
    count += 1
  elif count%2 == 1:
    max_value = max(a)
    Bob += max_value
    max_index = a.index(max_value)
    a[max_index] = 0
    count += 1
print(abs(Alice - Bob))

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))
li.sort(reverse=True)
Alice = 0
Bob = 0
for i in range(1,N+1):
    if i%2 !=0:
        Alice+=li[i-1]
    elif i%2 == 0:
        Bob += li[i-1]
ans = Alice-Bob
print(ans)

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

A.sort()
print(sum(A[::-2])-sum(A[-2::-2]))

Submission status: Accepted

Solution code:
N = int(input())

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

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



print(abs(b-c))

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

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

print( "{}".format( abs( even-odd ) ) )

Submission status: Accepted

Solution code:
#6
N = int(input())
a = sorted(list(map(int, input().split())))
Alice_list = []
Bob_list = []
for i in range(1, N+1):
    if i%2==1:     
        Alice_list.append(a[-i])
    else:
        Bob_list.append(a[-i])
print(sum(Alice_list)-sum(Bob_list))

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

data = sorted(data, key=int, reverse=True)

alice_total=0
bob_total=0


for i in range(0, n):
    if i % 2 == 0:
        alice_total = alice_total + int(data[i])
    else:
        bob_total = bob_total + int(data[i])

print(alice_total - bob_total)

Submission status: Accepted

Solution code:
N=int(input())
card=sorted(list(map(int,input().split())),reverse=True)
A=sum([i for x,i in enumerate(card) if x%2])
B=sum([i for x,i in enumerate(card) if not x%2])
print(abs(A-B))

Submission status: Accepted

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

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

scores = {"alice" : 0, "bob" :0}
card_collection.sort(reverse = True)
for i, card in enumerate(card_collection):
    if i % 2 == 0:
        scores['alice'] += card
    else:
        scores['bob'] += card
print(scores["alice"] - scores["bob"])

Submission status: Accepted

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

Submission status: Accepted

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

while alist != []:
    AliSc += alist[0]
    del alist[0]
    if alist != []:
        BobSc += alist[0]
        del alist[0]
    else:
        break

print(AliSc - BobSc)

Submission status: Accepted

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

list=sorted(list)[::-1]
A=0
B=0

for i in range(0,len(list)):
  if i%2==0:
    A=A+list[i]
  else:
    B=B+list[i]
    
print(A-B)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/abc088/tasks/abc088_b
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(allCards, eachCards):
    eachCardSort = sorted(eachCards, reverse=True)
    AlicesTotal = 0
    BobsTotal = 0
    for j in range(0, allCards, +1):
        if j % 2 == 0:
            AlicesTotal = AlicesTotal + eachCardSort[j]
        else:
            BobsTotal = BobsTotal + eachCardSort[j]
    # algorithm
    return AlicesTotal - BobsTotal


if __name__ == "__main__":
    N = II()
    AN = LI()
    print("{}".format(solver(N, AN)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
Alice = 0
Bob = 0
A = sorted(A, reverse = True)
for i, a in enumerate(A):
    if i %2 == 0:
        Alice += a
    else:
        Bob += a

print(Alice - Bob)

Submission status: Accepted

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

a_sum = 0
b_sum = 0

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

print(a_sum - b_sum)

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, = map(int, input().split())
A.sort(reverse=True)
turn = 0
x, y = 0, 0
for a in A:
    if turn == 0:
        x += a
    else:
        y += a
    turn = (turn+1) % 2
print(x-y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))[::-1]
B=[A[i] for i in range(len(A)) if i %2 == 0 ] #Alice
C=[A[i] for i in range(len(A)) if i %2 != 0 ] #Bob

print(sum(B)-sum(C))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
greatest = 0
m = 0
g = N

while g > 0:
  for i in range(N):
    if a[i]>greatest:
      greatest = a[i]
      m = i
  Alice += greatest
  a[m] = 0
  greatest = 0

  for i in range(N):
    if a[i]>greatest:
      greatest = a[i]
      m = i
  Bob += greatest
  a[m] = 0
  greatest = 0
  g = g - 2

print(Alice - 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:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
s = 0
for i in range(N//2):
    s += A[2*i]
    s -= A[2*i+1]
if N % 2 != 0:
    s += A[N-1]
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(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()))
na=sorted(a,reverse=True)
Alice=0
Bob=0

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

print(Alice-Bob)

Submission status: Accepted

Solution code:
#ABC088-B
n = int(input())
a = list(map(int,input().split()))
alice = []
bob = []
a.sort(reverse=True)
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:
input()

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

Submission status: Accepted

Solution code:
input()

AT = 0
Nob = 0
count = 0
for i in reversed(sorted(list(map(int, input().split())))):
    if(count % 2 == 0):
        AT += i
    else:
        Nob += i
    count += 1
print(AT-Nob)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)
isa = True
ali = 0
bob = 0
for t in a:
    if (isa):
        ali += t
    else:
        bob += t
    isa = not isa

print(ali - bob)

Submission status: Accepted

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

a.sort(reverse=True)

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

Submission status: Accepted

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

import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

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

alice=0
bob=0

a.sort()

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

Submission status: Accepted

Solution code:
N = int(input())
l = [int(x) for x in 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 = int(input())
x = input().split()
y = []
for i in x:
  y.append(int(i))
y.sort(reverse=True)
a = 0
b = 0
for i in range(0, n):
  if i % 2 == 0:
    a += int(y[i])
  else:
    b += int(y[i])
print(a - b)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort(reverse=True)
A = 0
B = 0
for i in range(N) :
    if i % 2 == 0 :
        A += a[i]
    else :
        B += a[i]
print(A-B)

Submission status: Accepted

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

A = sum(larev[0::2])
B = sum(larev[1::2])

print(A - B)

Submission status: Accepted

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