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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

if len(a) % 2 != 0:
    a.append(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=sorted(a,reverse=True)
alice=0
bob=0
for i in range(N):
    if i%2==0:
        alice+=a_sort[i]
    else:
        bob+=a_sort[i]
print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
al = 0
bo = 0
while a:
    al += a.pop(-1)
    if not a:
        break
    bo += a.pop(-1)
print(al-bo)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
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=sorted(list(map(int,input().split())),reverse=True)
al=[a[2*i] for i in range(n//2)]
bo=[a[2*i+1] for i in range(n//2)]
if n%2!=0:
  al.append(a[-1])
print(sum(al)-sum(bo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(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())
l = sorted(list(map(int, input().split())), reverse=True)
Alice = 0
Bob = 0

for i in range(len(l)):
    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()))

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()
a.reverse()
b=[]
if len(a)%2==0:
    for i in range(0,(len(a)//2)):
        b.append(a[2*i]-a[2*i+1])
else:
    for i in range(0,(len(a)//2)):
        b.append(a[2*i]-a[2*i+1])
    b.append(a[len(a)-1])
print(sum(b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ali = []
bob = []
for i in range(n):
    if i % 2 == 0:
        ali.append(A[i])
    else:
        bob.append(A[i])
        
print(sum(ali) - sum(bob))

Submission status: Accepted

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

A.sort(reverse=True)

Alice = 0
Bob = 0
for i in range(N):
  temp = A.pop(0)
  if i % 2 == 0:
    Alice += temp
  else:
    Bob += temp

print(str(Alice - Bob))

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    al = list(map(int, input().split()))
    al = sorted(al, reverse=True)
    an = 0
    bn = 0
    for i in range(n):
        if i % 2 == 0:
            an += al[i]
        elif i % 2 == 1:
            bn += al[i]
    print(an - bn)
resolve()

Submission status: Accepted

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

a_sorted = sorted(a, reverse=True)
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 1:
        alice += a_sorted[i]
    else:
        bob += a_sorted[i]
print(abs(alice-bob))

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int,input().split()))
alice = 0
bob = 0

nums.sort()
while nums:
    alice+=nums.pop()
    if nums:
        bob+=nums.pop()

print(alice-bob)

Submission status: Accepted

Solution code:
import math
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
alice=0
bob=0
k=math.floor(n/2)
if (n%2)==0:
    for i in np.arange(1,k+1):
        alice+=a[2*i-2]
        bob+=a[2*i-1]
if (n%2)==1:
    for i in np.arange(1,k+1):
        alice+=a[2*i-2]
        bob+=a[2*i-1]
    alice+=a[n-1]  
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
alice = 0
bob = 0
for i in range(len(arr)):
    if i%2 == 0:
        alice += arr[i]
    else:
        bob += arr[i]
print(abs(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()
Alice = 0
Bob = 0
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=sorted([int(i)for i in input().split()])
res=0
for i in range(n):
    tmp=a.pop(-1)
    if i%2==0:
        res+=tmp
    else:
        res-=tmp
print(res)

Submission status: Accepted

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

target_num = sum(a_list[::2]) - sum(a_list[1::2])
print(target_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a_list = list(map(int, input().split()))
# print(a_list)

a_list = sorted(a_list, reverse=True)
# print(a_list)

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

Submission status: Accepted

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

A, B = 0, 0

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

print(A-B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(alice_sum - bob_sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def main():
    N = int(input())
    aList = list(map(lambda x: int(x), input().split()))

    aliceValue = 0
    bobValue = 0
    isAliceTurn = True
    while len(aList) > 0:
        maxValue = max(aList)
        aList.remove(maxValue)
        if isAliceTurn:
            aliceValue += maxValue
        else:
            bobValue += maxValue

        isAliceTurn = not isAliceTurn

    print(aliceValue - bobValue)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
Alice = 0
Bob = 0
isAlice = True
for i in range(n):
    tmp = max(a)
    a.remove(tmp)
    if isAlice:
        Alice += tmp
    else:
        Bob += tmp
    isAlice = not(isAlice)
print(Alice-Bob)

Submission status: Accepted

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

sorted_a = sorted(a, reverse=True)

alice = sum(sorted_a[::2])
bob = sum(sorted_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 = 0
bob = 0

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

print(alice - bob)

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 % 2 == 0:
        al += a[i]
    else: bo += a[i]
print(al - bo)

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(len(A)):
    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()))
b = sorted(a, reverse=True)

print(sum(b[0::2]) - sum(b[1::2]))

Submission status: Accepted

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

b = sorted(a, reverse=True)

ans_Alice = 0
ans_Bob = 0

for i in range(x): 
    if i%2 ==0:
        ans_Alice += int(b[i])
    else:
        ans_Bob += int(b[i])

        
print(int(ans_Alice) - int(ans_Bob))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input();a,b,c=0,0,sorted(map(int,input().split()))
while c:
  a+=c.pop()
  b+=c.pop() if c else 0
print(a-b)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(n) for n in 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())
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:
def main():
	N = int(input())
	a = list(map(int, input().split()))
	len_a = len(a)

	a.sort(reverse = True)

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

	print(Alice - Bob)

  
if __name__ == "__main__":
  	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

a_list = sorted(a_list, reverse = True)

# print(a_list)

Alice_Score = 0
Bob_Score = 0

for i in range(n):

    # 奇数(1, 3, 5…)枚目はAliceのターン
    if i % 2 == 0 :
        Alice_Score = Alice_Score + a_list[i]
    else :
        Bob_Score = Bob_Score + a_list[i]

ans = Alice_Score - Bob_Score

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
if N == 1:
    a = int(input())
    print(a)
else:
    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:
num = int(input())
org_list = list(map(int, input().split()))

new_list = sorted(org_list, reverse=True)

alice_sum = sum(new_list[::2])
bob_sub = sum(new_list[1::2])

# print(new_list)
# print(str(alice_sum) + ":" +str(bob_sub))
print(str(alice_sum-bob_sub))

Submission status: Accepted

Solution code:
import sys
n,*a=map(int,sys.stdin.read().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)
alice = 0
for i in range(0,N,2):
    alice += a[i]
bob = 0
for i in range(1,N,2):
    bob += a[i]
print(alice - bob)

Submission status: Accepted

Solution code:
from collections import deque

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

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = sorted(rl(), reverse=True)
a = 0
b = 0
for i in range(n):
  if i & 1 == 0:
    a += li[i]
  else:
    b += li[i]
print(a-b)

Submission status: Accepted

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

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

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
a, b = 0, 0

while l:
  m1 = max(l)
  a += m1
  l.remove(m1)
  if l:
    m2 = max(l)
    l.remove(m2)
print( 2 * a - s )

Submission status: Accepted

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

if n%2 != 0:
  a.append(0)
  n += 1
 
a.sort()
d = 0

for i in range(int(n/2)):
               d += a[2*i+1]-a[2*i]
           
print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
alice = 0
bob = 0
chance = "A"
for _ in range(len(arr)):
	i = max(arr)
	if chance == "A":
		alice += i
		chance = "B"
	else:
		bob += i
		chance = "A"
	indx = arr.index(i)
	del arr[indx]
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

Submission status: Accepted

Solution code:
N = int(input())
data = list(map(int, input().split()))
Alice = 0
Bob = 0
count = 0
while N > count:
  high = data[0]
  point = 0
  for i in range(N):
    if data[i] > high:
      high = data[i]
      point = i
  if count % 2 == 0:
    Alice += high
  else:
    Bob += high
  data[point] = 0
  count += 1
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = sorted(A,reverse=True)
x=0
for i in range(0,N,2):
    x = x + B[i] 
for j in range(1,N,2):
    x = x - B[j]
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
Ali,Bob=0,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())
a=list(map(int,input().split()))
a.sort(reverse=True)
a.append(0)
Ali,Bob=0,0
for i in range(0,n,2):
    Ali +=a[i]
    Bob +=a[i+1]
print(Ali-Bob)

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 a[::2]:
    alice += i

for j in a[1::2]:
    bob += j

print(alice-bob)

Submission status: Accepted

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

ali = 0
bob = 0

a.sort()
# print(a)
while True:
    if(len(a) > 0):
        ali += a.pop()
    else:
        break
    if(len(a) > 0):
        bob += a.pop()
    else:
        break

print(ali - bob)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
A_before=input().split(' ')
for i in range(len(A_before)):
  A.append(int(A_before[i]))
for i in range(len(A)):
  for j in range(len(A)-1):
    if A[j]<A[j+1]:
      x=A[j]
      A[j]=A[j+1]
      A[j+1]=x
a=0
b=0
for i in range(len(A)):
  if i%2==0:
    a=a+A[i]
  else:
    b=b+A[i]
print(a-b)

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

int_list.sort(reverse=True)
odd = int_list[::2]
even = int_list[1::2]
print(sum(odd)-sum(even))

Submission status: Accepted

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

a = sorted(a, reverse = True)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import re
import sys
from collections import *
from functools import lru_cache
from heapq import *
from itertools import *

INF=float('inf')

sys.setrecursionlimit(2**31-1)

rfs=lambda:rl().split()
ri=lambda:int(rl())
ris=lambda:list(map(int,rfs()))
rl=lambda:next(sys.stdin)
rrs=lambda:list(map(str.strip,sys.stdin))
rs=lambda:rl().strip()
rt=lambda:sys.stdin.read()
rg=lambda:list(map(list,rrs()))

def n4(i,j):
    return [
                (i-1,j),
        (i,j+1),        (i,j-1),
                (i+1,j),
    ]

def n8(i,j):
    return [
        (i-1,j-1),(i-1,j),(i-1,j+1),
        (  i,j-1),        (  i,j+1),
        (i+1,j-1),(i+1,j),(i+1,j+1),
    ]

inb=lambda i,j,m,n:0<=i<m and 0<=j<n

###########################################

N,a=ri(),ris()
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))

Submission status: Accepted

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

Submission status: Accepted

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

Alice = []
Bob = []
while len(an) > 0:
    Alice.append(max(an))
    del an[an.index(max(an))]
    if len(an) > 0:
        Bob.append(max(an))
        del an[an.index(max(an))]
    else:
        break

k = 0
j = 0
for i in range(len(Alice)):
    k += Alice[i]
for i in range(len(Bob)):
    j += Bob[i]

print(str(k-j))

Submission status: Accepted

Solution code:
n=int(input())
A=[int(x) for x in input().split()]
B=sorted(A)
Alice=[]
Bob=[]
while len(B)!=0 and len(B)!=1:
  Alice.append(B[-1])
  B.pop()
  Bob.append(B[-1])
  B.pop()
if len(B)==1:
  Alice.append(B[0])
  B.pop()
print(sum(Alice)-sum(Bob))

Submission status: Accepted

Solution code:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    n = int(input().rstrip())
    a_list = [int(x) for x in input().rstrip().split(" ")]
    a_list.sort(reverse=True)

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

a = sorted(a, reverse=True)
for i 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)
A=a[::2]
B=a[1::2]
print(sum(A)-sum(B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort(reverse=True)

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

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(s) for s in 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
ans = Alice - Bob

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
p1, p2 = 0, 0
for i in range(N):
	max_A = max(A)
	if i % 2 == 0:
		p1 += max_A
	else:
		p2 += max_A
	A.remove(max_A)
print(p1 - p2)

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

alice = 0
bob = 0
A.sort()

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

print(abs(alice - bob))

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
for i in range(n):
    ans+=a[-i-1]*(-1)**(i)
    
    
print(ans)

Submission status: Accepted

Solution code:
n,*x=map(int,open(0).read().split());a=0;t=1;x.sort()
while x:a+=t*x.pop();t*=-1
print(a)

Submission status: Accepted

Solution code:

N,*list1 = open(0).read().split()

N=int(N)

#print(N)

list1=[int(i) for i in list1]

list1.sort(reverse=True)

#print(list1)

aaa=[]

bbb=[]


for i,n in enumerate(list1):
    if (i+1)%2 == 1:
        aaa.append(list1[i])
    else:
        bbb.append(list1[i])


#print(aaa)

#print(bbb)

print(sum(aaa)-sum(bbb))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from math import ceil

n=ni()
a=nl()

sa = sorted(a)[::-1]
aa = []
bb = []
for i in range(n):
  if i%2==0:
    aa.append(sa[i])
  else:
    bb.append(sa[i])

print(sum(aa)-sum(bb))

Submission status: Accepted

Solution code:
n = int(input())
an = list(map(int,input().split()))
a = sorted(an, 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)