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

a_list.sort(reverse = True)
for i in range(0, n, 2):
    alice += a_list[i]
for i in range(1, n, 2):
    bob += a_list[i]
print(alice - bob)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = [None]*N
    A = list(map(int, input().split()))
    Alice = 0
    Bob = 0
    while(A):
        Alice += max(A)
        A.remove(max(A))
        if A:
            Bob += max(A)
            A.remove(max(A))
    print(Alice - Bob)

Submission status: Accepted

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

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

Submission status: Accepted

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

alice_cards = []
bob_cards = []
while len(ordered_numbers) != 0:
    try:
        alice_cards.append(ordered_numbers.pop(0))
        bob_cards.append(ordered_numbers.pop(0))
    except IndexError:
        break

alice_point = sum(alice_cards)
bob_point = sum(bob_cards)

print(alice_point-bob_point)

Submission status: Accepted

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

even_indexes = list(num for num in range(0, N) if num % 2 == 0)
odd_indexes = list(num for num in range(0, N) if num % 2 == 1)
alice_cards = list(ordered_numbers[even_index] for even_index in even_indexes)
bob_cards = list(ordered_numbers[odd_index] for odd_index in odd_indexes)

alice_point = sum(alice_cards)
bob_point = sum(bob_cards)

print(alice_point-bob_point)

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(1, n+1):
  
  if i % 2 != 0:
    card = max(a)
    alice += card
  else:
    card = max(a)
    bob += card
  
  a.remove(card)
  
print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
# スペース区切りの整数の入力
a=[]
a = list(map(int, input().split()))
a.sort()
#print(a[::-1])
a=a[::-1]
i=0
sum=0
while i<len(a):
  if i%2==0:
    sum=sum+a[i]
  else:
    sum=sum-a[i]
  i=i+1

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
n = input()
ma = map(int, input().split())
ls = []
for m in ma:
  ls.append(m)
ls.sort()
jdg = 0
Alice = 0
Bob = 0

for l in reversed(ls):
  if jdg == 0:
    Alice = Alice + l
  else:
    Bob = Bob + l
  jdg = 1 - jdg

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

lines = sys.stdin.read().splitlines()
cards = [int(v) for v in lines[1].split(" ")]
cards.sort(reverse=True)
alice = 0
bob = 0
l = len(cards)
for i in range(0, l, 2):
  alice += cards[i]
  if i + 1 < l:
    bob += cards[i+1]
print(alice - bob)

Submission status: Accepted

Solution code:
_ = int(input())
cards = sorted(map(int, input().split()), reverse=True)

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

print(res)

Submission status: Accepted

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

A.sort(reverse=True)

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

print(alice - bob)

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)
    else:
        bob += max(A)
    A.remove(max(A))
    
print(alice - bob)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(int, read_line().split()[:n]))


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    local_a = list(a)
    a.sort(reverse=True)
    return sum(a[::2]) - sum(a[1::2])


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a_total, b_total = 0,0
for k in range(N):
    m = max(a)
    if k%2==0:
        a_total += m
    else:
        b_total += m
    a.remove(max(a))
print(a_total-b_total)

Submission status: Accepted

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


for i in range(n):
  curmax = max(lis)
  lis.remove(curmax)
  if i%2 == 0:
    alice += curmax
  else:
    bob += curmax
    
print(alice-bob)

Submission status: Accepted

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

Alice = 0
Bob = 0
for i, v in enumerate(A[::-1]):
  if i % 2 == 0:
    Alice += v
  else:
    Bob += v
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

diff = 0

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

print(diff)

Submission status: Accepted

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

Submission status: Accepted

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

li.sort()
li_rev = li[::-1]

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

Submission status: Accepted

Solution code:
# ABC 88, B - card game for two
n = int(input())
A = [int(el) for el in input().split(' ')]

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
number_list = list(map(int,input().split()))
Alice_sum = 0
Bob_sum = 0
for i in range(N):
    if(i%2==0):
        Alice_sum += max(number_list)
        number_list.remove(max(number_list))
    else:
        Bob_sum += max(number_list)
        number_list.remove(max(number_list))
print(Alice_sum-Bob_sum)

Submission status: Accepted

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

a = sum(cards[0::2])
b = sum(cards[1::2])

print(a - b)

Submission status: Accepted

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

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

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

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

Solution code:
CARD_NUM = int(input())
RAW_CARDS = input().split(' ')

card_array = [int(raw_card) for raw_card in RAW_CARDS]
card_array.sort(reverse=True)

alice_cards = list()
bob_cards = list()

is_alice = True

for card in card_array:
    if is_alice:
        alice_cards.append(card)
    else:
        bob_cards.append(card)
    is_alice = not is_alice

print(sum(alice_cards) - sum(bob_cards))

Submission status: Accepted

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

A = sorted(A, reverse=True)

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

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

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

Submission status: Accepted

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

a.sort()
a.reverse()

sa = 0
sb = 0

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

print(sa-sb)

Submission status: Accepted

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

Submission status: Accepted

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

alicep=0
bobp=0

for i in range(n):
	if i%2 == 0:
		alicep += max(cardpoints)
		cardpoints.remove(max(cardpoints))
	else:
		bobp += max(cardpoints)
		cardpoints.remove(max(cardpoints))

print(alicep-bobp)

Submission status: Accepted

Solution code:
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:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
al=0
bo=0
 
for i in range(n):
    if i==0 or i%2==0:
        al+=a.pop(0)
    else:
        bo+=a.pop(0)
 
print(al-bo)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

A.sort(reverse = True)

Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

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

print(a-b)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int, input().split()))
a.sort()
A=0
B=0
is_A=True
while len(a)>0:
  if is_A:
    A+=a.pop()
  else:
    B+=a.pop()
  is_A = not is_A
print(A-B)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())

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

a,b = 0,0

for i in range(n):
    if i%2==0:
        a += max(card)
        card.pop(card.index(max(card)))
    else:
        b += max(card)
        card.pop(card.index(max(card)))
        
    
print(a-b)

Submission status: Accepted

Solution code:
N = int(input())
kList = list(map(int, input().split()))
aTotal = 0
bTotal = 0
kList.sort(reverse=True)

for i in range(N):
    if i % 2 == 0:
        aTotal += kList[i]
    else:
        bTotal += kList[i]

print(aTotal - bTotal)

Submission status: Accepted

Solution code:
import math

n = int(input())
#a = int(input())
#a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]
#ls1 = [input() for i in range(n)]
#m = int(input())
#ls2 = [input() for i in range(m)]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
list = [int(i) for i in input().split()]

d = bSort(list)


A = 0
B = 0

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

Submission status: Accepted

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

a.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(key=lambda x: -x)
print(sum(A[0::2])-sum(A[1::2]))

Submission status: Accepted

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

As = sorted(A,reverse = True)
count = 0
for i in range(N):
  if i % 2 == 0:
    count += As[i]
  else:
    count -= As[i]
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

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

arr.sort()

a = 0
b = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
b = sorted(b, reverse=True)
c = [0, 0]
d = [1, 0]
e = [0, 1]
for i in range(a):
    c[0] += b[i] * d[i % 2]
    c[1] += b[i] * e[i % 2]
print(abs(c[0] - c[1]))

Submission status: Accepted

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

for i, card in enumerate(cards):
  if i%2 == 0:
    d += card
  else:
    d -= card
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a = IR(2)
    n %= 500
    if a >= n:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    a = LI()
    a.sort(reverse=True)
    op = 0
    ans = 0
    for ai in a:
        ans += -ai * op or ai
        op ^= 1
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0
ab = False
for i in l:
  if ab == False:
    alice += i
    ab = True
  else:
    bob += i
    ab = False
    
print(alice - bob)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int,input().split(" ")))
cards.sort()
cards.reverse()
# print(cards)

sum_A = 0
sum_B = 0

for i in range(N):
	if i % 2 == 0:
		sum_A += cards[i]
	else:
		sum_B += cards[i]

ans = sum_A - sum_B

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())

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

a.sort(reverse = True)

#print(a)

al = sum([a[i] for i in range(0,n,2)])
bb = sum([a[i] for i in range(1,n,2)])

print(al-bb)

Submission status: Accepted

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

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

Submission status: Accepted

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

alice = []
bob = []
sorted_cards = sorted(a, reverse=True)

for i, v in enumerate(sorted_cards):
    if i % 2 == 0:
        alice.append(v)
    else:
        bob.append(v)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0
count = 1
while(count <= n):
    alice += max(a)
    index = a.index(max(a))
    del a[index]
    count += 1
    if(len(a) > 0):
        bob += max(a)
        index = a.index(max(a))
        del a[index]
        count += 1
    
print(alice - bob)

Submission status: Accepted

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

alice = list()
bob   = list()

for i in range(int(len(a_list)+1/2)):
	try:
		alice.append(max(a_list))
		a_list.remove(max(a_list))
		bob.append(max(a_list))
		a_list.remove(max(a_list))
	except ValueError:
		break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data = input().split()
N = int(data[0])
Ai = input().split()
ai =[]
for i in range(N):
    ai.append(int(Ai[i]))

ai.sort()#昇順並び替え。list.sort()
alice = 0
bob = 0
for i in range(1,N+1):
    if i%2 != 0:
        alice += ai.pop()#list.pop()は配列の末尾の要素を削除して、削除した要素を返すメソッド
    else:
        bob += ai.pop()
print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
ls = sorted(list(map(int, input().split())))
Alice = 0
Bob = 0

while len(ls) != 0: 
    Alice += ls.pop()
    if len(ls) == 0:
        break
    Bob += ls.pop()
print(Alice - Bob)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a_sorted = sorted(a,reverse=True)
diff = 0
for i in range(int(N/2)):
       diff +=  a_sorted[2*i] - a_sorted[2*i + 1]
if(N%2 != 0):
       diff += a_sorted[N-1]
print(diff)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
A=0
B=0
while len(a) >=1:
    A += a.pop(0)
    if len(a)==0:
        break
    B += a.pop(0)
print(A-B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

def main():
    N = int(input())
    A = list(map(int, input().split()))

    p1_total = 0
    p2_total = 0
    for i in range(N):
        if i % 2 == 0:
            tmp = max(A)
            p1_total += tmp
            del A[A.index(tmp)]
        else:
            tmp = max(A)
            p2_total += tmp
            del A[A.index(tmp)]

    print(p1_total - p2_total)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

x=0
y=0
for i in range(len(li)):
    for j in range(len(li)-1):
        if li[j]<li[j+1]:
            a=li[j]
            li[j]=li[j+1]
            li[j+1]=a


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

print(x-y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
a = list(map(int, input().split()))
a.sort()
Alice = 0
Bob = 0

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

Submission status: Accepted

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

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=[]
a=list(map(int,input().split()))
a.sort()
a.reverse()
alice=[]
bob=[]
for i in range (0,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_list = list(map(int, input().split()))

a_sorted = sorted(a_list, reverse=True)
alice = sum(a_sorted[0::2])
bob = sum(a_sorted[1::2])

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
count = 1
for c in a:
    if count%2==1:
        alice += c
    else:
        bob += c
    count +=1
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC88 B

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

Submission status: Accepted

Solution code:
size = int(input())
nums = list(map(int, input().split()))
nums.sort()
nums.reverse()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

cards = sorted(a)
alice = cards[-1::-2]
bob = cards[-2::-2]

ans = sum(alice) - sum(bob)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int, input().split()))
A = 0
B = 0
while len(cards) > 0:
  A += max(cards)
  cards.pop(cards.index(max(cards)))
  if len(cards) > 0:
    B += max(cards)
    cards.pop(cards.index(max(cards)))
print(A - B)

Submission status: Accepted

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

a_sum=0
b_sum=0
for i in range(n):
    cnt=0
    max_a=0
    for i in range(n):
        if (a[i]>=max_a):
            max_a=a[i]
            cnt=i
    a_sum = a_sum+a[cnt]
    #print(a_sum,cnt)
    a[cnt]=0
    cnt=0
    max_a=0
    for i in range(n):
        if (a[i]>=max_a):
            max_a=a[i]
            cnt=i
    b_sum = b_sum+a[cnt]
    #print(b_sum)
    a[cnt]=0
print(a_sum-b_sum)

Submission status: Accepted

Solution code:
def cardGameForTwo():
	N = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	diffPoint = 0 
	for index in range(0, N):
		if index % 2 == 0:
			diffPoint += a[index]
		else:
			diffPoint -= a[index]
	print(diffPoint)

cardGameForTwo()

Submission status: Accepted

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

print(sum(b)-sum(c))