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枚のカードを大きい順に並べたリストを作成し、0,2,4,...番目をAliceが、1,3,5,...番目をBobが取ると考え、これらの総和の差を出力する
N = int(input())
a = list(map(int, input().split()))
b = sorted(a)[::-1]
Alice = 0
Bob = 0
for i in range(len(b)):
	if i % 2 == 0:
		Alice = Alice + b[i]
	else:
		Bob = Bob + b[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(raw_input())
a = map(int, raw_input().split())
a.sort(reverse=True)
count = 0
if n % 2 == 0:
	for i in range(n / 2):
		count += (a[2 *i] - a[2 * i + 1])
else:
	for i in range((n - 1) / 2):
			count += (a[2 * i] - a[2 * i + 1])
	count += a[n - 1]
print count

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(len(A)):
    if i%2==0:
        Alice += A[i]
    else:
        Bob += A[i]

print(Alice - Bob)

Submission status: Accepted

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

alice_score = 0
bob_score = 0
for index, i in enumerate(sorted(a, reverse=True)):
    if index % 2 == 0:
        alice_score += i
    else:
        bob_score += i
print(alice_score-bob_score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 088 B

N = int(input())
A =[int(j) for j in 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 = 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()
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:
n = int(input())
num_list = list(map(int, input().split(' ')))
num_list.sort(reverse = True)

alice = 0
bob = 0

for i, num in enumerate(num_list):
    if i % 2 == 0:
        alice += num
    else:
        bob += num

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 = input()
li2 = input().split()
li = []
for l in li2:
  li.append(int(l))
li.sort()
li.reverse()
t = 0
ans = 0
for i in li:
  if t % 2 == 0:
    ans += int(i)
  else:
    ans -= int(i)
  t += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

As = sorted(map(int,input().split()),reverse=True)

alice = 0
bob = 0

for i in range(0,N,2):
    alice += As[i]
    if i < N - 1:
        bob += As[i + 1]

print(alice - bob)

Submission status: Accepted

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

N = int(input())
li_raw = input().split()
li = [int(j) for j in li_raw]

turn = 1
A = 0
B = 0

while li != []:
    max = 0
    for x in li:
        if x > max:
            max = x
    if turn == 1:
        A += max
    else:
        B += max
    li.remove(max)
    turn = -turn
print(A-B)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().rstrip().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()))

counter = 0

A.sort(reverse=True)
for n in range(N):
    counter += A[n]*(-1)**n

print(counter)

Submission status: Accepted

Solution code:
N = int(input())
cards = [int(i) for i in input().split()]
alice = 0
bob = 0
for i in range(N):
    if i % 2 == 0:
        alice += max(cards)
        cards.remove(max(cards))
    elif i % 2 == 1:
        bob += max(cards)
        cards.remove(max(cards))
print(alice - bob)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

alice = 0
bob = 0

ai_s.sort(reverse=True)

while ai_s:
    alice += ai_s.pop(0)
    if ai_s:
        bob += ai_s.pop(0)

ans = alice - bob
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc088/tasks/abc088_b
n = input().split()[0]
a_list = list(map(int, input().split()))

alice_list = []
bob_list = []
sorted(a_list)

for i in range(len(a_list)):
    max_a = max(a_list)
    a_list.remove(max_a)

    if i % 2 == 0:
        alice_list.append(max_a)
    else:
        bob_list.append(max_a)

answer = sum(alice_list) - sum(bob_list)
print(answer)

Submission status: Accepted

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

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())
cards = sorted(map(int, input().split()), reverse=True)
score_alice, score_bob = 0, 0

for i in range(n):
  if i % 2 == 0:
    score_alice += cards[i]
  else:
    score_bob += cards[i]

print(score_alice - score_bob)

Submission status: Accepted

Solution code:
N = int(input())
card_list = input().rstrip().split()
card_list = [int(s) for s in card_list]
sort_card_list = sorted(card_list, reverse = True)
alice_point = 0
bob_point = 0

for i, x in enumerate(sort_card_list):
    if i%2 == 0:
        alice_point = alice_point + x
    else:
        bob_point = bob_point + x

print(alice_point-bob_point)

Submission status: Accepted

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

Submission status: Accepted

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

score_alice= 0
score_bob = 0

while True:
  alice_card = max(A)
  A.remove(alice_card)
  score_alice += alice_card
  
  if len(A) == 0:
    break

  bob_card = max(A)
  A.remove(bob_card)
  score_bob += bob_card
  
  if len(A) == 0:
    break

print(score_alice - score_bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8

N = int(input())
a = sorted([int(x) for x in input().split()], reverse=True)

Alice = sum(a[::2])	#最初から最後までを2間隔で取る。
Bob = sum(a[1::2])	#一項から最後までを2間隔で取る。

print(Alice-Bob)

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) - Alice
print(Alice - Bob)

Submission status: Accepted

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

a_list.sort()
a_list.reverse()

x = 0
y = 0
n = 0

for a in a_list:
  if n % 2 == 0:
    x = x + a
    n = n +1
  else:
    y = y + a
    n = n +1

sabun = x - y

print(sabun)

Submission status: Accepted

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

Submission status: Accepted

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

A = A + [0, 0, 0, 0, 0]
sum = 0
for i in range(N//2 + 2):
  sum = sum + A[i*2] - A[i*2 + 1]
  
print(sum)

Submission status: Accepted

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

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

print(alice - bob)

Submission status: Accepted

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

alice_num = sum(a[::2])
bob_num   = sum(a[1::2])
print(alice_num - bob_num)

Submission status: Accepted

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


A = sorted(A, reverse=True)

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

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

Submission status: Accepted

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

a = sorted(a, reverse = True)
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())
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())
cards = list(map(int, input().split()))
sorted_cards = sorted(cards, reverse=True)

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

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)
print(sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

alice = 0
bob = 0
turn = "alice"

a.sort()
a.reverse()

for i in range(n):
    if turn == "alice":
        alice += a[i]
        turn = "bob"
    else:
        bob += a[i]
        turn = "alice"

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:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys
import math


N = int(input())
An = list(map(int, sys.stdin.readline().rstrip().split()))
An = sorted(An, key=lambda x:-x)
print(sum(An[0::2]) - sum(An[1::2]))

Submission status: Accepted

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

Alice = sum(a[0::2])
Bob = sum(a[1::2])
print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
data = list(map(int,input().split()))
data.sort(reverse=True)
alice = 0
bob = 0
for i in range(len(data)):
    if i%2 == 0:
        alice += data[i]
    elif i%2 == 1:
        bob += data[i]
        
print(alice-bob)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a_s = list(map(int,input().split()))
    a_s.sort()
    a_s.reverse()
    Alice,Bob = 0,0
    for i,a in enumerate(a_s):
        if i % 2 == 0:
            Alice += a
        else:
            Bob += a
            
    print(Alice-Bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
Alice, Bob = 0, 0
for turn in range(0, n-1):
    if len(l) != 0:
        Alice += max(l)
        l.remove(max(l))
    if len(l) != 0:
        Bob += max(l)
        l.remove(max(l))
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())
a = list(map(int, input().split()))

Alice = []
Bob = []

while 0 < len(a):
    Alice.append(a.pop(a.index(max(a))))
    if 0 < len(a):
        Bob.append(a.pop(a.index(max(a))))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
a_list = sorted(list(map(int,input().split())),reverse=True)
alice = []
bob = []
for _ in range(math.ceil(len(a_list)/2)):
    alice.append(a_list.pop(0))
    if len(a_list) == 0:
        break
    bob.append(a_list.pop(0))
print(sum(alice)-sum(bob))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

san = sorted(an, reverse=True)
alice = 0
bob = 0
turn_alice = True
for a in san:
    if turn_alice:
        alice += a
    else:
        bob += a
    turn_alice = not turn_alice

print(alice - bob)

Submission status: Accepted

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

Alice = sum(aList[0::2])
Bob = sum(aList[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
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 sys import stdin
n = int(stdin.readline().rstrip())
al = [int(_) for _ in stdin.readline().rstrip().split()]
al.sort(reverse=True)
print(sum(al[::2])-sum(al[1::2]))

Submission status: Accepted

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

Submission status: Accepted

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

a = sorted(a, reverse=True)

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
sc=[0,0]
for i,ai in enumerate(a):
    sc[i%2]+=ai
print(sc[0]-sc[1])

Submission status: Accepted

Solution code:
input()
card = [int(i) for i in input().split(" ")]
card.sort(reverse = True)

alice = [card[i] for i in range(len(card)) if i % 2 == 0]
bob = [card[i] for i in range(len(card)) if i % 2 == 1]

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

Submission status: Accepted

Solution code:
def gusaku():
    n = int(input())
    List = list(map(int, input().split()))
    # 昇順ソートなので，前のsumnが小さくなる
    List_sorted = sorted(List, reverse=True)
    print(sum(List_sorted[::2]) - sum(List_sorted[1::2]))

gusaku()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = np.array(input().split(), dtype=int)
a = np.sort(a)[::-1]
print(np.sum(a[0::2]) - np.sum(a[1::2]))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = sorted(a, reverse=True)
    return str(sum(a[::2]) - sum(a[1::2]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
N = int(input())
aList = [int(x) for x in input().split()]
aList.sort(reverse=True)
print(sum(aList[::2]) - sum(aList[1::2]))

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:
n=int(input())
a=list(map(int,input().split()))
a.sort()
Alice=0
Bob=0
for i in range(n):
  if len(a)>0:
    Alice+=a.pop()
  if len(a)>0:
    Bob+=a.pop()
print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
a=0
b=0
def max():
    m = 0
    j = 0
    for i in range(len(x)):
        if x[i]>m:
            m=x[i]
            j=i
    x.pop(j)
    return m
if n%2 == 0:
    i=0
    while i<n:
        a += max()
        b += max()
        i += 2
else:
    i=0
    while i<n-1:
        a += max()
        b += max()
        i += 2
    a+=max()
print(a-b)

Submission status: Accepted

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

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

Submission status: Accepted

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

L.sort()
L.reverse()

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:
# coding: utf-8
N = int(input())
L = input().split()
for i in range(N):
  L[i]=int(L[i])

L.sort()
L.reverse()

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

a_s.sort()
a_s.reverse()
alice = 0
bob = 0
for i, a in enumerate(a_s):
    if i % 2 == 0:
        alice += a
    else:
        bob += a
ans = alice - bob

print(ans)

Submission status: Accepted

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

print(sum([a*(-1)**i for i, a in enumerate(A)]))

Submission status: Accepted

Solution code:
input()
ai = [int(i) for i in input().split(" ")]
ai.sort()
ai = tuple((j ,a) for j,a in enumerate(reversed(ai)))
alice=sum([ a for j,a in list(filter(lambda x: x[0]%2 == 0, ai))])
bob=sum([ a for j,a in list(filter(lambda x: x[0]%2 == 1, ai))])
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:
def main():
    N = int(input())
    an = sorted(list(map(int, input().split())), reverse=True)
    print(sum(an[i] for i in range(0, N, 2)) -
          sum(an[j] for j in range(1, N, 2)))


main()

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]

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]

ans = Alice - Bob
print(ans)

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(0,N):
  if i %2 == 0:
    alice += card_num[i]
  else:
    bob   += card_num[i] 
ans = int(alice - bob)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(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(reverse=True)

ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += A[i]
    if i % 2 == 1:
        ans -= A[i]

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc088/tasks/abc088_b

import itertools
import collections
import bisect

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

    a_sum = sum([A[a] for a in range(0, len(A), 2)])
    b_sum = sum([A[a] for a in range(1, len(A), 2)])
    print(a_sum - b_sum)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import exit
# A,B,C = [int(n) for n in input().split()]
N = int(input())
a = sorted([int(n) for n in input().split()], key=lambda x:-x)
ali = 0
bob = 0
for i in range(N):
    if i % 2 == 0:
        ali +=a[i]
    else:
        bob +=a[i]
print(ali-bob)
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
exit()

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

Submission status: Accepted

Solution code:
input();c=0
for a in sorted(map(int,input().split())):c=a-c
print(c)

Submission status: Accepted

Solution code:

input();c=0
for a in sorted(map(int,input().split())):c=a-c
print(c)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted((int(s) for s in input().split()), reverse=True)
ans = sum(v * (-1 if i & 1 else 1) for i, v in enumerate(a))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Turn = True
Alice = 0
Bob = 0
for i in range(0, N):
    if Turn==True:
        Alice = Alice+a[i]
    else:
        Bob = Bob+a[i]
    Turn = not Turn
print("{}".format(Alice-Bob))

Submission status: Accepted

Solution code:

n = int(input())

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

Ai.sort(reverse = True)


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

Submission status: Accepted

Solution code:
n = int(input())

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

alice = []

bob = []

for i in range(n):
	alice.append(max(card))
	del card[card.index(max(card))]
	if card == []:
		break
	bob.append(max(card))
	del card[card.index(max(card))]
	if card == []:
		break
        
print(sum(alice) - sum(bob))

Submission status: Accepted

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

card.sort()
card.reverse()

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

print (a-b)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

Alice = sum(a[::-1][::2])
Bob = sum(a[::-1][1:][::2])

print(Alice - Bob)

Submission status: Accepted

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

countA = 0
countB = 0

card_list.sort()
card_list.reverse()


for i, x in enumerate(card_list):
    if i % 2 == 0:
        countA += x
    else :
        countB += x
        
print(countA - countB)

Submission status: Accepted

Solution code:
N = int(input())
lst = sorted([int(x) for x in input().split()], reverse=True)
ret = 0
for idx, x in enumerate(lst):
    if idx % 2 == 0:
        ret += x
    else:
        ret -= x
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
lst = sorted([int(x) for x in input().split()], reverse=True)
a = sum([lst[x] for x in range(0, len(lst), 2)])
b = sum([lst[x] for x in range(1, len(lst), 2)])
print(a - b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def card_game_for_two(N: int, A: list) -> int:
    sorted_A = sorted(A, key=lambda x: - x)
    alice = sum(a for i, a in enumerate(sorted_A) if i % 2 == 0)
    bob = sum(a for i, a in enumerate(sorted_A) if i % 2 == 1)
    return alice - bob


if __name__ == "__main__":
    N = int(input())
    A = map(int, input().split())
    ans = card_game_for_two(N, A)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
alice=[]
bob=[]
for i in range(len(a)):
    alice.append(max(a))
    a.remove(max(a))
    if len(a)==0:
        print(sum(alice)-sum(bob))
        break
    bob.append(max(a))
    a.remove(max(a))
    if len(a)==0:
        print(sum(alice)-sum(bob))
        break

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])[::-1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
hoge=list(map(int,input().split()))
hoge.sort()
hoge.reverse()
flag="A"
alice=0
bob=0
for i in range(n):
  if(flag=="A"):
    alice+=hoge[i]
    flag="B"
  else:
    bob+=hoge[i]
    flag="A"

print(alice-bob)

Submission status: Accepted

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

l.sort(reverse=True)
Alice = sum(l[0::2])
Bob = sum(l[1::2])

print(Alice-Bob)

Submission status: Accepted

Solution code:
N = int(input())
a = input().split()
a_list = []

for i in range(N):
    a_list.append(int(a[i]))

a_list.sort(reverse=True)

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

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

li=sorted(li,reverse=True)
for i in range(N):
    if i%2 == 0:
        Alice.append(li[i])
    else:
        Bob.append(li[i])
print(sum(Alice)-sum(Bob))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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