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:
# -*- coding: utf-8 -*-

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

_as.sort(reverse=True)

Alice = _as[0::2]
Bob = _as[1::2]

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
a_order = sorted(a, reverse=True)
alice, bob = 0, 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

N = input()

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

list.sort(li,reverse=True)

#print(li)
#print(len(li))
l = 0
g = 0

for i in range(0,(len(li)),2):
    #l =[int(x) for x in list(str(i))]
    l += li[i]
#print(l)


for j in range(1,(len(li)),2):
    #m =[int(y) for y in list(str(j))]
    g += li[j]
#print(g)

print(l-g)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

total_a = 0
total_b = 0

a.sort(reverse=True)
for i in range((n+1)//2):
    total_a += a[i*2]
for i in range(n//2):
    total_b += a[i*2 + 1]
print(total_a - total_b)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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())
v = sorted([int(i) for i in input().split()], reverse=True)
ans = 0
for i in range(n):
  ans += (v[i] if i%2 == 0 else -v[i])
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

alice_point = 0
bob_point = 0
for index in range(N):
	if index % 2 == 0:
		alice_point += a[index]
	else:
		bob_point += a[index]

print(alice_point - bob_point)

Submission status: Accepted

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

numArraySorted = sorted(numArray,reverse=True) #soted method cannot change raw data

alice = 0
bob = 0

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

print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Card_n.sort()

A_n = []
B_n = []

for i in range(len(Card_n)):
    if not i%2 == 0:
        A_n.append(Card_n.pop())
    else:
        B_n.append(Card_n.pop())

#print(A_n)
#print(B_n)
print(abs(sum(A_n) - sum(B_n)))

Submission status: Accepted

Solution code:
import sys


def solve(inp):
    N = int(inp.readline())
    A = list(reversed(sorted(map(int, inp.readline().split(' ')))))

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

    return str(a - b)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    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]
print(alice-bob)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(x) for x in input().split()]
a = sorted(a, reverse=True)
A = sum(a[:N:2])
B = sum(a[1:N:2])
print(A - B)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input()

As = sorted([int(a) for a in input().split()], reverse=True)
alice = sum([a if i % 2 == 0 else 0 for i, a in enumerate(As)])

print(alice - (sum(As) - alice))

Submission status: Accepted

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

sum=0
for x in range(len(A)):
  sum=sum+(-1)**(x)*A[x]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -coding: utf-8 -

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

a = sorted(a, reverse = True)

#print(a)

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

#print(alice)

bob = sum(a) - alice

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

*A, = map(int, input().split())
A.sort(reverse=True)

sum1 = 0
sum2 = 0

for i in range(len(A)):
    if i%2==0:
        sum1 = sum1 + A[i]
    else:
        sum2 = sum2 + A[i]
print(sum1-sum2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
N = int(input())
a = list(map(int, input().split()))

if len(a)%2 != 0 :
  a.append(0)
a.sort(reverse=True)

sum = 0
for i in range(0, len(a), 2) :
  sum += (a[i]-a[i+1])
print (sum)

Submission status: Accepted

Solution code:
# coding: utf-8


class Player:

    def __init__(self):
        self.point = 0

    def add_point(self, point):
        self.point += point

    def get_point(self):
        return self.point


def main():

    _ = int(input())
    cards = list(map(int, input().split(' ')))
    cards = sorted(cards, reverse=True)

    alice = Player()
    bob = Player()
    players = [alice, bob]
    for i, card in enumerate(cards):
        players[i % len(players)].add_point(card)

    print(alice.get_point() - bob.get_point())

    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
sumajedan = 0
sumadva = 0

n = int(input())

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

a.sort(reverse = True)

for x in range(n):
    if x%2 == 0:
        sumajedan=sumajedan + a[x]
    else:
        sumadva = sumadva + a[x]
print(sumajedan - sumadva)

Submission status: Accepted

Solution code:
n=int(input())
li=list(input().split(" "))
for g in range(n):
    li[g]=int(li[g])
ali=0
bob=0
li.sort()
li.reverse()
for i in range(n):
    if i%2==0:
        ali+=li[i]
    else:
        bob+=li[i]
print(abs(ali-bob))

Submission status: Accepted

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

# A = [20,18,2,18]
Alice = 0
Bob = 0

A.sort(reverse=True)

for i,num in enumerate(A):
    if i%2 == 0:
        Alice+=num
    else:
        Bob+=num

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

A=B=I=0
for i in a:
    if I %2:B+=i
    else:A+=i
    I+=1

print(A-B)
# other
# print(sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

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

A=B=I=0
for i in a:
    if I %2:B+=i
    else:A+=i
    I+=1

print(A-B)
# other
# print(sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

Solution code:
"""
Created on Wed Jan  1 17:06:59 2020
"""

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

li_sorted=sorted(li, reverse=True)
sum=0
for i in range(N):
    if i%2==1:
        sum+=-1*li_sorted[i]
    else:
        sum+=li_sorted[i]
        
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
cards=sorted(map(int, input().split()), reverse=True)
a=1
b=0
Alice=0
Bob=0
for i in cards:
    if a == 1 and b == 0:
       Alice+=i
       a=0
       b=1
    elif a == 0 and b == 1:
       Bob+=i
       a=1
       b=0
print(Alice-Bob)

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]

ans = alice-bob
print(ans)

Submission status: Accepted

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

a_i.sort(reverse = True)

L_a = []
L_b = []

for i in range(0, N, 2):
    L_a.append(a_i[i])

for i in range(1, N, 2):
    L_b.append(a_i[i])

print(sum(L_a) - sum(L_b))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=0
y=0
for i in range(0,n,2):
    x+=a[i]
for i in range(1,n,2):
    y+=a[i]

print(abs(x-y))

Submission status: Accepted

Solution code:
def get(S):
    return list(map(S, input().split()))

[N] = get(int)
A = get(int)
A = sorted(A)

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

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc088 b-card game for two
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:
# coding: utf-8
import sys


def main():
  n = int(input())
  card = sorted(list(map(int, input().split(' '))), reverse=True)
  A = []
  B = []
  
  for i in range(n):
    if i % 2 == 0:
      A.append(card[i])
    
    else:
      B.append(card[i])
      
  print(sum(A) - sum(B))
  
  return 0


if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    A = sc.intarr()

    new = sorted(A, reverse=True)
    alice = 0

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

    print(alice)


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()

Submission status: Accepted

Solution code:
num = input()
nums = [int(x) for x  in input().split()]
nums = sorted(nums, reverse=True)
alice = sum(nums[::2])
bob = sum(nums[1::2])
print(alice-bob)

Submission status: Accepted

Solution code:

N = int(input())

cards = [data for i, data in enumerate(sorted(map(int, input().split(" ")), reverse=True))]
print(sum(cards[0::2]) - sum(cards[1::2]))

Submission status: Accepted

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

sortedList = sorted(li, reverse=True)

alice = 0
bob = 0
turn = 1

while(len(sortedList)):
  if turn % 2 == 1:
    alice += sortedList.pop(0)
  else:
    bob += sortedList.pop(0)
  
  turn += 1

print(alice - bob)

Submission status: Accepted

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

alice = 0
bob = 0
for n, a in enumerate(sorted(a_list, reverse=True)):
    if n % 2 == 0:
        alice += a
    else:
        bob += a

print(alice-bob)

Submission status: Accepted

Solution code:
import sys

n, *a = map(int, sys.stdin.read().split())

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

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
SA = sorted(A,reverse=True)
ALI =0
BOB=0
for i in range(0,N,2):
    ALI += int(SA[i])
for n in range(1,N,2):
    BOB += int(SA[n])
ans = ALI - BOB
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(abs(A-B))

Submission status: Accepted

Solution code:
num = int(input())
num_list = [int(i) for i in input().split()]

#大きい順に並び変える
num_list.sort(reverse = True)

senkou = 0
koukou = 0
for i in range(num):
    if i % 2 == 0:
        senkou += num_list[i]
    else:
        koukou += num_list[i]

result = senkou - koukou
print(result)

Submission status: Accepted

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
num_list.sort(reverse=True)
result = 0
for i in range(0, len(num_list), 2):
    result += num_list[i]

for i in range(1, len(num_list), 2):
    result -= num_list[i]

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

##Just for prctice
n=int(input())

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

A.sort()
A.reverse()
a=0
b=0
for i in range(n):
    if i%2==0:
        a+=A[i]
    else:
        b+=A[i]

print(a-b)

"""
2
3 1

2

3
2 7 4

5

4
20 18 2 18

18
"""

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A_res = 0
B_res = 0
for i in range(N):
    if i % 2 == 1:
        A_res += max(A)
    else:
        B_res += max(A)
    del A[A.index(max(A))]

print(B_res - A_res)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int ,input().split()))
A = 0
B = 0
for i in range(N) :
    A += max(list(a))
    a.remove(max(list(a)))
    a.append(0)
    B += max(list(a))
    a.remove(max(list(a)))
    a.append(0)



print(A - B)

Submission status: Accepted

Solution code:
n = int(input())
x = input()
a = sorted([int(i) for i in x.split()])[::-1]
alice = sum([i for n,i in enumerate(a) if n%2==0])
bob = sum([i for n,i in enumerate(a) if n%2!=0])
print(alice-bob)

Submission status: Accepted

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

l.sort(reverse = True)

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

Submission status: Accepted

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

Alice = [a[i] for i in range(0, len(a), 2)]

Bob = [a[i] for i in range(1, len(a), 2)]

print(sum(Alice) - sum(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:
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().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()))

NewA = sorted(A, reverse=True)

Alice = 0
Bob = 0 

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


print((Alice)-(Bob))

Submission status: Accepted

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

Submission status: Accepted

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

A = 0
B = 0
idx = 0
for card in cards:
    if idx % 2 == 0:
        A += card
    else:
        B += card
    idx += 1
result = A - B
print(result)

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(1,N+1):
    if i%2 == 1:
        alice += a.pop(a.index(max(a)))
    else:
        bob += a.pop(a.index(max(a)))
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a = sorted(a)
sum1 = 0
sum2 = 0
for i in reversed(range(0,len(a))):
	if(i%2==0):
		sum1+=a[i]
	if(i%2==1):
		sum2+=a[i]
print(abs(sum1-sum2))

Submission status: Accepted

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

a.sort(reverse=True)
b = a[::2]
c = a[1::2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_sorted_list = sorted(a_list, reverse=True)

score_Alice = 0
score_Bob = 0

for i in range(N):
  if i % 2 == 0:
    score_Alice += a_sorted_list[i]
  else:
    score_Bob += a_sorted_list[i]

print(score_Alice - score_Bob)

Submission status: Accepted

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

Alice=0
Bob=0

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

Submission status: Accepted

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

A,B = 0,0
for i in range(n):
  if i == 0 or i%2 == 0:
    A += a[i]
  else:
    B += a[i]

if A > B:
  print(A-B)
else:
  print(B-A)

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int, input().split()))
lili = sorted(li)
lili.reverse()
score = 0
isA = 1
for i in lili:
    if isA % 2 == 1:
        score += i
    else:
        score -= i
    isA += 1
print(score)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a = int(input())  # Nを入力
b = input()  # a1,a2...anを入力
b = map(int, b.split())  # a1,a2...anをint型でリストに入れる
b = sorted(b)  # 大きい順に並べる 
b = b[::-1]  # リストの要素の順番を逆転する
c = b[::2]  # Aliceのとる要素を抽出
c_number = len(c)
d = b[1::2]  # Bobのとる要素を抽出
d_number = len(d)
c_sum = 0
d_sum = 0
for i in range(c_number):
    c_sum += c[i] # Aliceのとる要素の合計
for g in range(d_number):
    d_sum += d[g]  # Bobのとる要素の合計
print(c_sum - d_sum)  # 差分を出力

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

alice=0
bob=0
for _ in range(N):
    alice += max(ans)
    ans.remove(max(ans))
    if len(ans) == 0:
        break
    bob += max(ans)
    ans.remove(max(ans))
    if len(ans) == 0:
        break

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:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    suma = 0
    sumb = 0
    fixL = sorted(a, reverse=True)
    for i in range(N):
        if i % 2 == 0:
            suma += fixL[i]
        else:
            sumb += fixL[i]
    print(suma - sumb)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8

n = int(input())

nums = list(map(int,input().split(' ')))
nums = sorted(nums, reverse=True)
diff = 0
for i in range(n):
  if i % 2 == 0:
    diff += nums[i]
  else:
    diff -= nums[i]
print(diff)

Submission status: Accepted

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

alice = []
bob = []
i = 2
while True:
    mx = max(a)
    if i % 2 == 0:
        alice.append(mx)
    else:
        bob.append(mx)
    a.remove(mx)
    i+=1
    if len(a) == 0:
        break

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

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(n):
    if i%2 == 0 :
        alice += max(a)
        del a[a.index(max(a))]
    else :
        bob += max(a)
        del a[a.index(max(a))]
print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
ab = [0, 0]
is_alice = True
while len(A) != 0:
    now = A.pop()
    if is_alice:
        ab[0] += now
        is_alice = False
    else:
        ab[1] += now
        is_alice = True
print(ab[0] - ab[1])

Submission status: Accepted

Solution code:
num = int(input())
ls = list(map(int,input().split()))
new_ls = sorted(ls,reverse = True)

Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
n=input().rstrip()
n=int(n)
a=input().split()
k=0
li=[]
while k<n:
    b=int(a[k])
    li.append(b)
    k+=1
c=tuple(sorted(li,reverse=True))
h=0
sb=0
while 2*h+1<=n-1:
    sb+=c[2*h+1]
    h+=1
h=0
sa=0
while 2*h<=n-1:
    sa+=c[2*h]
    h+=1
d=sa-sb
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

alice = []
bob = []
a_sorted = sorted(a)
# print(a_sorted)

while len(a_sorted) != 0:
    max = a_sorted.pop()
    # print(max)
    alice.append(max)
    if(len(a_sorted) != 0):
        max = a_sorted.pop()
        bob.append(max)

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()],reverse=True)
#print(a)
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:
import heapq
n = int(input())
A = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(A)
# even if you heapfied your list the type is still list
#print(type(A))
al = []
bo = []
for i in range(n):
  if i % 2 == 0:
    al.append(heapq.heappop(A)*(-1))
  else:
    bo.append(heapq.heappop(A)*(-1))
print(sum(al)-sum(bo))

Submission status: Accepted

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

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

print(a-b)

Submission status: Accepted

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

number = iter(number_list)

a = 0
b = 0

for i in range(int(n)):
    if i % 2 == 0:
        a += int(next(number))
    else:
        b += int(next(number))

print(a-b)

Submission status: Accepted

Solution code:
n=int(input())
alice=[]
bob=[]
l=list(map(int,input().split()))
while len(l)>0:
    alice.append(max(l))
    l.remove(max(l))
    if len(l)>0:
        bob.append(max(l))
        l.remove(max(l))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

alice = 0
bob = 0

# ソート
a.sort(reverse=True)

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

print(alice - bob)

Submission status: Accepted

Solution code:
i=int(input())
lists=list(map(int,input().split()))

sumA=0
sumB=0

while lists!=[]:
    a=max(lists)
    sumA=sumA+a
    lists.remove(a)
    if lists!=[]:    
        b=max(lists)
        sumB=sumB+b
        lists.remove(b)

d=sumA-sumB
print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
l=list(map(int,input().split()))
l.sort()
ans=0
while l:
    ans+=l.pop()
    if l:
        ans-=l.pop()
print(ans)