Problem:


Score: 200 points

Problem Statement

We have N cards. A number a_i is written on the i-th card.

Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.

The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Constraints

N is an integer between 1 and 100 (inclusive).

a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:  

N
a_1 a_2 a_3 ... a_N

Output

Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

Sample Input 1

2
3 1

Sample Output 1

2

First, Alice will take the card with 3. Then, Bob will take the card with 1.
The difference of their scores will be 3 - 1 = 2.

Sample Input 2

3
2 7 4

Sample Output 2

5

First, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.

Sample Input 3

4
20 18 2 18

Sample Output 3

18



Sample input:
2
3 1


Sample output:
2

Submission status: Accepted

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

Ans = 0
flag = True
for i in A_:
    if flag:
        Ans += i
        flag = False
    else:
        Ans -= i
        flag = True
print(Ans)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/abc088/tasks/abc088_b
# Python 1st 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(cardCount, cardNumberList):
    result = 0
    cardNumberList.sort(reverse=True)
    #   print("整列済み {}".format(cardNumberList))
    # Aliceのターン
    AlicesCard = 0
    for j in range(0, cardCount, +2):
        #        print("Alice got {}".format(cardNumberList[j]))
        AlicesCard = AlicesCard + cardNumberList[j]
    BobsCard = 0
    for j in range(1, cardCount, +2):
        #           print("Bob got {}".format(cardNumberList[j]))
        BobsCard = BobsCard + cardNumberList[j]
    result = abs(AlicesCard-BobsCard)
    return result


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

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
A=a[0::2]
B=a[1::2]
print(sum(A)-sum(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:
from heapq import heappop, heappush, heapify
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  A = list(x for x in map(int, readline().split()))
  heapify(A)
  Alice = 0
  Bob = 0
  for i in range(N):
    if i%2==0:
      Alice += heappop(A)
    else:
      Bob += heappop(A)
  ans = abs(Alice-Bob)
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())
cards_list = list(map(int,input().split()))
cards_list.sort()
cards_list.reverse()
sum_alice = 0
sum_bob = 0
turn = 0

for val in cards_list:
    if turn == 0:
        sum_alice += val
        turn = 1
    else:
        sum_bob += val
        turn = 0

print(sum_alice-sum_bob)

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 in range(n):
    if i % 2 == 0:
        a += cards[i]
    else:
        b += cards[i]
print(a - b)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse=True)
a = []
b = []

for i in range(n):
  if i%2 == 0:
    a.append(li[i])
  else:
    b.append(li[i])

print(sum(a)-sum(b))

Submission status: Accepted

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

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

Alice = 0
Bob = 0

Turn = 0
for a in sorted(A, reverse=True):
    if Turn == 0:
        Alice += a
        Turn =1
    else:
        Bob += a
        Turn = 0
print(Alice-Bob)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
a=[int(x) for x in input().split()]
A=0
B=0
while 1:
    A+=max(a)
    loc=np.argmax(a)
    a.pop(loc)
    if a==[]:break
    B+=max(a)
    loc=np.argmax(a)
    a.pop(loc)
    if a==[]:break
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 = input()
nums = sorted(list(map(int,input().split())),reverse=True)
print(sum(nums[0::2]) - sum(nums[1::2]))

Submission status: Accepted

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

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_min = min(a)
alice = 0
bob = 0
while max(a) != 0:
    alice += max(a)
    for i in range(len(a)):
        if a[i] == max(a):
            a[i] = 0
            break
    bob += max(a)
    for i in range(len(a)):
        if a[i] == max(a):
            a[i] = 0
            break
if alice > bob:
    print(alice-bob)
else:
    print(bob-alice)

Submission status: Accepted

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

while True:
    if len(cards) == 0:
        break
    a += max(cards)
    cards.remove(max(cards))

    if len(cards) == 0:
        break
    b += max(cards)
    cards.remove(max(cards))

print(a - b)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
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())
data = list(map(int,input().split()))
data = sorted(data, reverse=True)
alice = 0
bob = 0
for i,var in enumerate(data):
    if i%2 == 0:    
        alice += var
    else:    
        bob += var
print(alice-bob)

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(reverse = True)
A1 = a[0:n:2]
A2 = a[1:n:2]
print(sum(A1)-sum(A2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ap = 0
bp = 0
a.sort()
flag = 1
for i in range(n):
  if flag == 1:
    ap += a.pop()
  else:
    bp += a.pop()
  flag *= -1
print(ap-bp)

Submission status: Accepted

Solution code:
# solution
import io

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

Submission status: Accepted

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

alice = 0
for i in range(n):
    if i%2==0:
        alice+=a_inputs[i]
print(2*alice-sum(a_inputs))

Submission status: Accepted

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

a = sorted(a)[::-1]

alice = a[0::2]
bob = a[1::2]

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

Submission status: Accepted

Solution code:
#10
n = int(input())
card = list(map(int,input().split()))
card.sort(reverse = True)
A,B = 0,0
for i,j in enumerate(card):
    if i % 2 == 0:
        A += j
    else:
        B += j

print(A-B)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
a.sort(reverse=True)
alc = 0
bob = 0
for i in range(n):
    if not i % 2:
        alc += a[i]
    else:
        bob += a[i]
print(alc - bob)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    b = sorted(a, reverse=True) # aを大きい順に並べる
    
    Alice = 0
    Bob = 0


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = sorted(A, 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()
ans=0
k=1
for i in a:
  ans+=k*i
  k*=-1
if ans<0:
  ans*=-1
print(ans)

Submission status: Accepted

Solution code:
N = int(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:
# ソート
# Greedy
N = int(input().rstrip())
a = sorted([int(i) for i in input().rstrip().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()))

sortedList = sorted(a,reverse=True)



ansList = [sortedList[i] if i%2==0 else -sortedList[i] 
           for i in range(n)]
ans = sum(ansList)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

a_i_list = list(map(int, input().split(" ")))

a_i_list_sorted = sorted(a_i_list, reverse=True)

alice_sum = 0
bob_sum = 0

for index, val in enumerate(a_i_list_sorted):
  if index % 2 == 0:
    alice_sum += val
  else:
    bob_sum += val

print(alice_sum - bob_sum)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

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

    a.sort(reverse=True)
    ans = 0
    for i in range(len(a)):
        ans += a[i]*(-1)**i
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort(reverse=True)
    Alice = 0
    Bob = 0
    for i in range(len(A)):
        if i % 2 == 0:
            Alice += A[i]
        else:
            Bob += A[i]
    print(Alice - Bob)
main()

Submission status: Accepted

Solution code:
N=int(input())
C=list(map(int,input().split()))
D=sorted(C,reverse=True)
A=[]
B=[]
for (i,d) in enumerate(D):
    if i%2==0:
        A.append(d)
    else:
        B.append(d)
print(abs(sum(A)-sum(B)))

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
_DEC = lambda x: x-1
MIIZ = lambda: list(map(_DEC, MII()))

def main():
    n = II()
    aa = MII()
    aa.sort(reverse=True)
    alice = aa[0::2]
    bob = aa[1::2]
    print(sum(alice)-sum(bob))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    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())
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()))

a.sort(reverse=True)

M = 0
m = 0

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

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

print(M-m)

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:
# ABC 088: B – Card Game for Two
n = int(input())
a = [int(s) for s in input().split()]
a.sort(reverse = True)
print(sum(a[0::2]) - sum(a[1::2]))

Submission status: Accepted

Solution code:
# ABC 088: B – Card Game for Two
n = int(input())
a = [int(s) for s in input().split()]
a.sort()
a.reverse()

alice = 0
bob = 0

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
# slice操作 --> [start:stop:step]
# 奇数番目の要素の和 - 偶数番目の要素の和
print(sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

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

a = sorted(a, reverse=True)

alice = 0
bob = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
alice = 0
bob = 0
cards = [int(val) for val in input().split()]

cards = sorted(cards, reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Card Game for Two
N = int(input())
a = list(map(int, input().split()))

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

alice = []
bob = []

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
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:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)
arrA.sort()
arrA = arrA[::-1]

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

ans = Alice-Bob

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

L = sorted(L, reverse=True)

Alice = 0
Bob = 0
count = 0

for i in range (0, len(L)):
	if count == 0:
		Alice+=L[i]
		count=1
	else:
		Bob+=L[i]
		count=0

print(Alice-Bob)

Submission status: Accepted

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

a.sort(reverse=True)

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

print(alice - bob)

Submission status: Accepted

Solution code:
import sys

def resolve():
    N = int(input())
    S = list(map(int, input().split(" ")))
    S.sort(reverse=True)
    print(sum(S[0::2]) - sum(S[1::2]))


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
# B - Card Game for Two
#25min
N = int(input())
a_input = map(int, input().split())
a = list(a_input)
alice = 0
bob = 0
a.sort(reverse=True)
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:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


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


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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
s=[]
t=[]
s.append(a[0::2])
t.append(a[1::2])

print(sum(s[0])-sum(t[0]))

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:
N = int(input())
a_input = map(int, input().split())
a = list(a_input)
alice = 0
bob = 0
for i in range(len(a)):
    max_i = 0
    max_a = 0
    for j in range(N):
        if a[j] > max_a:
            max_a = a[j]
            max_i = j
    if i%2 == 0:
        alice = alice + max_a
    else:
        bob = bob + max_a
    a[max_i] = 0
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
alice = 0
bob = 0
cnt = 0
for i in a:
    if cnt%2==0:
        alice += i
    else:
        bob += i
    cnt += 1

print(abs(alice-bob))

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
a = list(map(int,input().split()))
a.sort()
alice = 0
bob = 0
for i in range(n):
    if i%2 == 0:
        bob += a[i]
    else:
        alice += a[i]
print(abs(alice - bob))

Submission status: Accepted

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

A, B = 0, 0

for i in range(N//2):
    A += a.pop()
    B += a.pop()

if N % 2 == 1:
    A += a.pop()

print(A-B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

Alice_point = 0
Bob_point = 0

for i, value in enumerate(a):
    if i % 2 == 0:
        Alice_point += value
    else:
        Bob_point += value

print(Alice_point - Bob_point)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

A.sort(reverse=True)

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

print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = list()
Bob = list()
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:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())[::-1]
    print(sum(A[::2]) - sum(A[1::2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# abc088_b.py
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
alice = []
bob = []
for i,v in enumerate(A):
    if i%2==0:
        alice.append(v)
    else:
        bob.append(v)
print(sum(alice)-sum(bob))

Submission status: Accepted

Solution code:
a = int(input()) 
b = list(input().split())
c = [int(i) for i in b]
d = sorted(c, reverse=True)
Alice, Bob = 0, 0
for j in range(a):
  if j % 2 == 0:
    Alice += d[j]
  else:
    Bob += d[j]
diff = Alice - Bob
print(diff)

Submission status: Accepted

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

alice = 0
bob = 0
order = "A"
for e in sorted(a)[::-1]:
    if order == "A":
        alice += e
        order = "B"
    else:
        bob += e
        order = "A"

print(alice-bob)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	a = LI()
	a.sort(reverse=True)
	a = np.array(a)
	print(np.sum(a[0::2]) - np.sum(a[1::2]))


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
input()
A = list(map(int, input().split()))
x = 0
y = 0
t = 0
while A:
	m = max(A)
	if t == 0:
		x += m
		t = 1
	else:
		y += m
		t = 0
	A.remove(m)
print(x-y)

Submission status: Accepted

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

alice = 0
bob = 0
a.sort(reverse=True)
for i, v in enumerate(a):
    if i % 2 == 0:
        alice += v
    else:
        bob += v
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
while len(a)>=1:
    Alice+=a[-1]
    a.pop(-1)
    if len(a)>=1:
        Bob+=a[-1]
        a.pop(-1)

print(Alice-Bob)

Submission status: Accepted

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

alice = 0
bob = 0

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

bob = sum(a)-alice
ans = alice-bob
print(ans)

Submission status: Accepted

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

alice = 0
bob = 0

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

bob = sum(a)-alice
ans = alice-bob
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(N:int,A:list) -> int:
   Alice = 0
   Bob = 0
   A.sort(reverse=True)
   for n,a in enumerate(A):
      if (n%2 == 0):
         Alice += a
      else:
         Bob += a
   return Alice - Bob

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))

if __name__ == '__main__':
   main()

Submission status: Accepted

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

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

Submission status: Accepted

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

print(alice - bob)

Submission status: Accepted

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

print(a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
alice = bob = 0
for n, a in enumerate(A):
    if n % 2:
        bob += a
    else:
        alice += a
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse = True)#　.sort()　がポイント。.sort(reverse = True) で降順になる
Alice = 0
Bob = 0

for i in range(len(cards)):# range(len())　の記法はポイント
    if i % 2 == 0:
        Alice += cards[i]
    else:
        Bob += cards[i]

difference = Alice - Bob
print(difference)

Submission status: Accepted

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

a.sort()

alice = 0
bob = 0
flag = 0
for i in range(N):
    if flag == 0:
        alice += a[N-(i+1)]
        flag = 1
    else:
        bob += a[N-(i+1)]
        flag = 0

print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
a = map(int, input().split())
a = sorted(a, reverse=True)
i = 0
s = 0
for x in a:
    if i % 2 == 0:
        s += x
    else:
        s -= x
    i += 1
print(s)

Submission status: Accepted

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n=int(input());l=sorted(list(map(int,input().split())),reverse=1)
    print(abs(sum(l)-2*sum(l[1::2])))

if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
import numpy as np
if __name__ == "__main__":
    N = int(input())
    line = input().rstrip().split(' ')
    line = np.array(line).astype("int")
    line = np.sort(line)[::-1]
    a = 0
    b = 0
    #print(line)
    for i in range(len(line)):
        if i % 2 ==0:
            a += line[i]
        else:
            b += line[i]
    print(a-b)

Submission status: Accepted

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