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.sort()
c=0
for i in range(n-1,-1,-1):
    if (n-i)%2==1:
        c+=a[i]
    else:
        c-=a[i]
print(c)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort()
total=0
i=n-1
while(0<=i-1):
  total+=A[i]-A[i-1]
  i-=2
if(i==0):
  total+=A[0]
print(total)

Submission status: Accepted

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

A.sort(reverse=True)

Alice = sum([a for a in A[0::2]])
Bob = sum([a for a in A[1::2]])

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
alice = 0
bob = 0

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

a.sort()
a.reverse()

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

Submission status: Accepted

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

ys = reversed(sorted(xs))
answer = 0
for i, y in enumerate(ys):
    if i % 2 == 0:
        answer = answer + y
    else:
        answer = answer - y
print(answer)

Submission status: Accepted

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

ys = reversed(sorted(xs))
zs = [y if i % 2 == 0 else -y for i, y in enumerate(ys)]
print(sum(zs))

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
a.reverse()

A = a[::2]
B = a[1::2]

print(sum(A) - sum(B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
input()
l = list(map(int, input().split()))
l.sort(reverse=True)
alice = sum(l[::2])
bob   = sum(l[1::2])
print(alice-bob)

Submission status: Accepted

Solution code:
n = int(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())
cardlist = input().split()
cardlist = [int(n) for n in cardlist]
cardlist_s = sorted(cardlist, reverse=True)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input());
a = list(map(int, input().split(' ')));
alice = [];
bob   = [];

for x in range(n):
    m = max(a);
    i = a.index(m);
    if ( x%2 == 0):
        alice.append( a.pop(i) );
    else:
        bob.append( a.pop(i) );

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

Submission status: Accepted

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

A.sort()
A.reverse()

AL=[A[i] for i in range(0,N,2)]
BO=[A[i] for i in range(1,N,2)]

print(sum(AL)-sum(BO))

Submission status: Accepted

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

ali = 0
bob = 0

a.sort(reverse=True)
for i, m in enumerate(a):
    if i % 2 == 0:
        ali += m
    else:
        bob += m

print(ali - bob)

Submission status: Accepted

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

ali = bob = 0
for i,a in enumerate(reversed(A)):
    if i%2:
        bob += a
    else:
        ali += a
print(ali - bob)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

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 = 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())
c = list(map(int,input().split()))
c.sort()
c.reverse()
a = 0
b = 0

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

print(a-b)

Submission status: Accepted

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

import math

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

#aを昇順でSort
a.sort()
a.reverse()

sumA = 0
sumB = 0

# print(a)
sumA = sum(a[0::2])

sumB = sum(a[1::2])
print(sumA-sumB)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
## ABC 088
n = int(input())
cl = [int(_) for _ in input().split()]

cl.sort(reverse=True)

alice = 0
bob = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

a = list(reversed(sorted(a)))

ans = 0
flag = 1
for x in a:
  ans += x * flag
  flag *= -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
if n % 2:
    a.append(0)

a.sort()

alice = 0
bob = 0

while len(a) > 0:
    alice += a.pop()
    bob += a.pop()

print(str(alice-bob))

Submission status: Accepted

Solution code:
N = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
cnt = 0
Alice = 0
Bob = 0
for n in nums:
    if cnt % 2 == 0:
        Alice += n
    else:
        Bob += n
    cnt += 1
print(Alice-Bob)

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())
l=list(map(int,input().split()))
l.sort(reverse=True)
print(sum(l[0::2])-sum(l[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, a in enumerate(A):
  if i % 2 == 0:
    Alice += a
  else:
    Bob += a
    
print(Alice - Bob)

Submission status: Accepted

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

c = a[-2::-2]
d = a[-1::-2]

print(sum(d)-sum(c))

Submission status: Accepted

Solution code:
def answer(*inp):

    N = int(inp[0])
    cards = sorted([int(n) for n in inp[1].split()], reverse=True)

    alice = 0
    bob = 0

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

    print(alice - bob)


answer(input(), input())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
a = a[::-1]
for i in range(n):
    c = c + ((-1)**(i%2))*a[i]

print(c)

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 % 2 == 0:
        Alice += max(A)
    else:
        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[::2]) - sum(A[1::2]))

Submission status: Accepted

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

A.sort()
A.reverse()

R = sum([a if i % 2 == 0 else -1 * a for i, a in enumerate(A)])
print(R)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = np.sort(np.array([int(i) for i in input().split()]))[::-1]

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

print(alice-bob)

Submission status: Accepted

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

p_a = sum(sorted(a, reverse = True)[::2])
p_b = sum(a) - p_a
print(p_a - p_b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
total = 0
for i,x in enumerate(a):
  total += x*(-1)**i
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
hands = list(map(int,input().split()))
Alice = 0
Bob = 0
for i in range(N):
    ans = hands.pop(hands.index(max(hands)))
    if i % 2 == 0:
        Alice += ans
    else:
        Bob += ans
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

alice_score = sum(a_list[0::2])
bob_score = sum(a_list[1::2])

print(alice_score - bob_score)

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

listA.sort()
listA.reverse()

pointA=0
pointB=0
index=0
while index <n:
    if index%2 ==0:
        pointA+=listA[index]
    else:
        pointB+=listA[index]
    index+=1

print(pointA-pointB)

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

Submission status: Accepted

Solution code:
n = int(input())
list_a = list((map(int, input().split())))
list_a.sort()
list_alice = list_a[-1::-2]
if n == 1:
    list_bob = []
else:
    list_bob = list_a[-2::-2]
ans_alice = 0
ans_bob = 0
for number in list_alice:
    ans_alice += number
for number in list_bob:
    ans_bob += number
print(ans_alice - ans_bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
list = [int(i) for i in input().split()]
sortlist = sorted(list, reverse=True)
Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
#AtCorder Beginner Contest 088 B Card Game for Two

#number of cards
n = int(input())

#cards in the field
line = list(map(int,input().split()))
pointA = 0
pointB = 0

while len(line) > 0:
    pointA += max(line)
    line.remove(max(line))
    if len(line) == 0:
        break
    else:
        pointB += max(line)
        line.remove(max(line))

print(pointA-pointB)

Submission status: Accepted

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

arr.sort(reverse=True)

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = 0
bob = 0
flag_alice = True
for num in a:
    if flag_alice:
        alice += num
        flag_alice = False
    else:
        bob += num
        flag_alice = True
print(alice - bob)

Submission status: Accepted

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

    Alice = 0
    Bob = 0
    j = 0

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

    print(Alice - Bob)

main()

Submission status: Accepted

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

A.sort()

x=sum(A[-1::-2])
y=sum(A[-2::-2])
print(x-y)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = sum(A[::2]) - sum(A[1::2])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split(' ')))
ans = 0
for i in range(N):
    ans = ans + max(A) * (-1) ** i
    A.remove(max(A))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
lst = [int(x) for x in stdin.readline().rstrip().split()]
lst.sort()
lst.reverse()

Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#utf-8を書かないと日本語で怒られる
n = int(raw_input())
#nを数字にする
l = []
l = map(int, raw_input().split())

# sort
l.sort(reverse=True)
#print(l)

# N回のfor文を回して奇数のときはアリスにとらせて偶数ではボブにとらせる
# nは0から回ることに注意（アリスは奇数回目ではない）
alice = 0
bob = 0
for i in range(n):
  if i%2 == 0:
    alice += l[i]
    #print(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

a.sort(reverse=True)

cnt = 0

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(c) for c in input().split()]
alice = 0
bob = 0

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 = [int(c) for c in input().split()]
alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
a.reverse()
Alice = []
Bob = []
for i,p in enumerate(a):
    if i % 2 == 0:
        Alice.append(p)
    else:
        Bob.append(p)
print (sum(Alice) - sum(Bob))

Submission status: Accepted

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

a.sort()
a = a[::-1]

A = a[::2]
B = a[1::2]

ans = sum(A) - sum(B)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
aa.sort(reverse=True)

f = s = 0
for i in range(N):
	if i%2 == 0:
		f += aa[i]
	else:
		s += aa[i]

print(f-s)

Submission status: Accepted

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

alice_point = 0
bob_point = 0
for i in range(n):
    if i % 2 == 0:
        alice_point += a_list[i]
    else:
        bob_point += a_list[i]

print(alice_point - bob_point)

Submission status: Accepted

Solution code:
import numpy as np

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

alice_point = 0
bob_point = 0
for i in range(n):
    argmax_a = np.argmax(a_list)
    max_a = np.max(a_list)
    if i % 2 == 0: # If Alice takes a card
        alice_point += max_a
    else: # If Bob takes a card
        bob_point += max_a
    del a_list[argmax_a] # No confidence -> Review how to delete list element!

print(alice_point - bob_point)

Submission status: Accepted

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

a.sort()
a.reverse()

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

print(total)

Submission status: Accepted

Solution code:
n = int(input())
num = list(map(int, input().split()))
sum1 = sum2 = 0
for i in range(n):
    if i % 2 == 0:
        x = max(num)
        a = num.index(x)
        sum1 += x
        del num[a]
    else:
        y = max(num)
        b = num.index(y)
        sum2 += y
        del num[b]

print(sum1 - sum2)

Submission status: Accepted

Solution code:
N = int(input())
a_list = [a for a in map(int, input().split())]
a_list.sort()
a_list.reverse()
alice = 0
bob = 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()) 
ai = input().split()
ai = list(map(int, ai))

sorted_ai = sorted(ai, reverse=True)

alice = 0
bob = 0

for index, x in enumerate(sorted_ai):
    if (index % 2 == 0):
        alice += x
    else:
        bob += x
        
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if i%2 == 0:
        Amax += max(A)
        A.remove(max(A))
    else:
        Bmax += max(A)
        A.remove(max(A))

print(Amax - Bmax)

Submission status: Accepted

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

Arr.sort(reverse=True)

i = 0
ans = 0
for a in Arr:
  if i%2 == 0:
    ans += a
  else:
    ans -= a
  i += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
l=list(map(int, input().split()))
C=0
l.sort()
l.reverse()
n=N//2
if N%2==1:
    C += min(l)
    l.remove(min(l))
for i in range(n):
    C += l[2*i]-l[2*i+1]
print(C)

Submission status: Accepted

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


solve()

Submission status: Accepted

Solution code:
N, = map(int, raw_input().split())
a = sorted(map(int, raw_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 = 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 = input()
scores = list(map(int, input().split()))

scores.sort()
scores.reverse()
alice_flag = True
alice_score = 0
bob_score = 0

for score in scores:
    if alice_flag:
        alice_score += score
        alice_flag = False
    else:
        bob_score += score
        alice_flag = True

print(alice_score - bob_score)

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())
l=[int(i) for i in input().split()]
ans=sum(l)
l.sort()
for i in range(-2,-n-1,-2):
    ans-=l[i]*2
print(ans)

Submission status: Accepted

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

A=[]
B=[]
while len(a)>0:
    A.append(max(a))
    a.remove(max(a))
    if len(a)>0:
        B.append(max(a))
        a.remove(max(a))
print(sum(A)-sum(B))

Submission status: Accepted

Solution code:
n = input()
s = list(map(int,input().split()))
Alice = []
Bob = []
for i in range(len(s)):
    if i % 2 == 0:
        Alice.append(max(s))
        s.remove(max(s))
    else:
        Bob.append(max(s))
        s.remove(max(s))
print(sum(Alice) - sum(Bob))

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())
card=list(map(int,input().split()))
card=sorted(card, reverse=True)
a=0
b=0
for i in range(N):
    if i%2==0:
        a+=card.pop(0)
    else:
        b+=card.pop(0)
print(abs(a-b))

Submission status: Accepted

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

Submission status: Accepted

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

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

A_point = sum([a for i, a in enumerate(a_list) if i % 2 == 0])
B_point = sum([a for i, a in enumerate(a_list) if i % 2 == 1])

print(A_point - B_point)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i 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())
a_list = sorted(list(map(int, input().split())), reverse=True)
n_alice = sum(a_list[::2])
n_bob = sum(a_list[1::2])
print(n_alice - n_bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,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())
l=sorted(map(int,input().split()))[::-1]
v=sum([l[i] for i in range(0,N,2)])-sum([l[i] for i in range(1,N,2)])
print(v)

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:
n = int(input())
a = [int(m) for m 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 = list(map(int, input().split()))
alice = 0
bob = 0


for i in range(len(a_list)):
    if i % 2:
        bob += sorted(a_list, reverse=True)[i]
    else:
        alice += sorted(a_list, reverse=True)[i]

print(str(alice - bob))

Submission status: Accepted

Solution code:
n=int(input())
num=sorted(list(map(int,input().split())),reverse=True)
a=[]
b=[]
flag=True
for i in range(n):
  l=max(num)
  num.remove(l)
  if flag:
    a.append(l)
    flag=False
  else:
    b.append(l)
    flag=True
print(sum(a)-sum(b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = input()

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

alice = []
bob = []
for na in range(int(n)):
    if na == 0 or na % 2 == 0:
        maxn = max(nums)
        alice.append(maxn)
        nums.remove(maxn)
    else:
        maxn = max(nums)
        bob.append(maxn)
        nums.remove(maxn)

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

Submission status: Accepted

Solution code:
input();
al=[int(i) for i in input().split()]
al.sort()
al = al[::-1]
print(sum(al[::2])-sum(al[1::2]))