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
import math
n = input()
N = map(int, input().split())
N = sorted(list(N), reverse=True)

a = sum(N[::2])
b = sum(N[1::2])
print(a - b)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
sumA = 0
sumB = 0
for i in range(1,N+1):
    m = max(a)
    if i%2 == 1:
        sumA += m
    else:
        sumB += m
    a.remove(m)

print(sumA-sumB)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(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:
# ABC_088_B_Card_Game_for_two.py
N=int(input())
a=list(map(int, input().split()))
a.sort( reverse= True)

ScoreAlice=0
ScoreBob=0
for i in range (0,N):
	if i%2==0: #Alice
		ScoreAlice+=a[i]
	else: #Bob
		ScoreBob+=a[i]
print(ScoreAlice-ScoreBob)

Submission status: Accepted

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

print(abs(sum(A[0:n:2]) - sum(A[1:n:2])))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
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)
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)
pt=0
for i in a[::2]:
  pt+=i
for i in a[1::2]:
  pt-=i
print(pt)

Submission status: Accepted

Solution code:
n,s = int(raw_input()),map(int,raw_input().split())
s.sort(key = lambda x:-x)
print sum(s[0:n:2]) - sum(s[1:n: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):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
if N == 1:
  print(input())
else:
  A = 0
  B = 0
  a = list(map(int,input().split()))
  a.sort()
  a.reverse()
  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 = sorted([int(X) for X in 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)
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())
Ali = list(map(int,input().split()))

Ali.sort(reverse = True)

AP = BP = 0

for i in range(N):
  if i%2 == 0:
    AP += Ali[i]
  else:
    BP += Ali[i]

print(AP-BP)

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:
        A = max(a)
        Alice = Alice + A
        a.remove(A)
    else:
        A =max(a)
        Bob = Bob + A
        a.remove(A)
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

a = list(map(int, a))
a.sort(reverse=True)
alice_n = a[::2]
bob_n = a[1::2]

print(sum(alice_n) - sum(bob_n))

Submission status: Accepted

Solution code:
n=int(input())
number_list=list(map(int,input().split()))
new_list=sorted(number_list,reverse=True)
#print(new_list)
alice_number=[]
for i in range(n):
    if i%2==1:
        continue
    alice_number.append(new_list[i])
#print(alice_number)
bob_number=[]
for i in range(n):
    if i%2==0:
        continue
    bob_number.append(new_list[i])
#print(bob_number)
result=sum(alice_number)-sum(bob_number)
print(result)

Submission status: Accepted

Solution code:
alice = 0
bob = 0
n = int(input())
a = list(map(int,input().split()))
sorted_a = sorted(a, reverse=True) 

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    l = [int(x) for x in input().split()]
    Alice = 0
    Bob = 0
    l.sort()
    l.reverse()
    for i in range(len(l)):
        if i % 2 == 0:
            Alice += l[i]
        else:
            Bob += l[i]
    print(Alice-Bob)
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

alice = 0
bob = 0

for n in range(N):
    if len(a) == 0:
        break
    card = max(a)
    alice += card
    a.remove(card)
    if len(a) == 0:
        break
    card = max(a)
    bob += card
    a.remove(card)

print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
cards = [int(i) for i in input().split(' ')]
cards.sort(reverse=True)

alice = 0
bob = 0

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

Submission status: Accepted

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

Bob=0
Alice=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

ansA=0
ansB=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())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
alice = l[0::2]
bob = l[1::2]
print(sum(alice) - sum(bob))

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]
print(alice - bob)

Submission status: Accepted

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

Alice_point = 0
Bob_point = 0
Alice_flag = 1
Bob_flag = 0
for _ in range(n):
    if Alice_flag:
        Alice_point+=max(numbers)
        numbers.remove(max(numbers))
        Alice_flag=0
        Bob_flag=1
    elif Bob_flag:
        Bob_point+=max(numbers)
        numbers.remove(max(numbers))
        Alice_flag=1
        Bob_flag=0

print(Alice_point-Bob_point)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        ans += a
    else:
        ans -= a

print(ans)

Submission status: Accepted

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

A_sort = sorted(A, reverse=True)
Alice = [a for i, a in enumerate(A_sort) if i%2==0]
Bob = [a for i, a in enumerate(A_sort) if i%2==1]

ans = sum(Alice) - sum(Bob)

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

n = stdin.readline().rstrip()
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort(reverse=True)

N=M=0

for i in range(0,len(A),2):
    N = N + A[i]

for i in range(1, len(A), 2):
    M = M + A[i]

print (N-M)

Submission status: Accepted

Solution code:
n = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)
alice = []
bob = []
for i in range(0, n, 2):
    alice.append(cards[i])
    try:
        bob.append(cards[i+1])
    except:
        break
print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
n = int(input())
cards = [i for i in map(int, input().split())]
alice = []
bob = []
for i in range(n):
    if i % 2 == 0:
        alice.append(max(cards))
        cards.pop(cards.index(max(cards)))
    else:
        bob.append(max(cards))
        cards.pop(cards.index(max(cards)))
print(sum(alice) - sum(bob))

Submission status: Accepted

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

alice = 0
bob = 0

A_rev = sorted(A, reverse=True)

while True:
    if len(A_rev) != 0:
        alice += A_rev.pop(0)
    
    if len(A_rev) != 0:
        bob += A_rev.pop(0)
    
    if len(A_rev) == 0:
       break
 
print(alice - bob)

Submission status: Accepted

Solution code:
N = input()
MM = input().split()
list1 =[]
for i in MM:
  x = int(i)
  list1.append(x)
list1.sort(reverse = True)
total = 0
for i in range(len(list1)):
  if i%2 ==0:
    total += list1[i]
  else:
    total -= list1[i]
print(total)

Submission status: Accepted

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

num_lists.sort()
num_lists.reverse()
alice_num_lists = []
bob_num_lists = []

for i in range(n):
  if i%2 == 0:
    alice_num_lists.append(num_lists[i])
  else:
    bob_num_lists.append(num_lists[i])

alice_score = 0
bob_score = 0
for i in alice_num_lists:
  alice_score += i
for i in bob_num_lists:
  bob_score += i

print(alice_score - bob_score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
array = list(map(int,input().split()))
a = b = 0
for i, m in enumerate(sorted(array, reverse=True)):
    if i == 0 or i % 2 == 0:
        a += m
    if i % 2 != 0:
        b += m
print(a-b)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

score_a = a[::2]
score_b = a[1:][::2]

print(sum(score_a) - sum(score_b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
N=int(N)
ls=[int(s) for s in input().split()]
ls=sorted(ls,reverse=True)
A=0
B=0
i=0
while i<N:
  if i%2==0:
    A=A+ls[i]
  if i%2==1:
    B=B+ls[i]
  i=i+1
print(A-B)

Submission status: Accepted

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

a = 0
b = 0
while len(L):
    a += L.pop(L.index(max(L)))
    if len(L) == 0: break;
    b += L.pop(L.index(max(L)))

print(abs(a-b))

Submission status: Accepted

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

sort_A = sorted(A,reverse=True)
#print(sort_A)

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
l=len(a)
a.sort(reverse=True)
alice=bob=c=0
for i in range(l):
    if c%2==0:
        alice+=a[i]

    else:
        bob+=a[i]
    c+=1
print(alice-bob)

Submission status: Accepted

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

A.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    a.sort(reverse=True)
    alice = sum(a[::2])
    bob = sum(a[1::2])
    print(alice - bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
    N = int(input())
    a = sorted(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)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = map( int, input())
a = list(map( int, input().split() ))
A_point = 0
B_point = 0
flag = 1

a.sort(reverse=True)

for point in a:
    if flag%2 == 1:
        A_point += point
        flag += 1
    elif flag%2 == 0:
        B_point += point
        flag += 1

print("{}".format(A_point-B_point))

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)
        a.remove(max(a))
    else:
        Bob += max(a)
        a.remove(max(a))
print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())

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

print(sum([((-1)**(i%2))*a for i, a in enumerate(l_a)]))

Submission status: Accepted

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

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)
alice = 0
bob = 0
for i, el in enumerate(a):
    if i % 2 == 0:
        alice += el
    else:
        bob += el
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(0, n):
    if i % 2 == 0:
        alice += a[i]
    else: 
        bob += a[i]
print(int(alice - bob))

Submission status: Accepted

Solution code:
X = int(input())
A = list(map(int, input().split()))
list.sort(A, reverse=True)
B=0
C=0
ans = 0
for i,j in enumerate(A):
    if (i+1)%2 != 0:
        B+=j
    else :
        C+=j
ans = B-C
print(ans)

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.sort(reverse=True)
Alice = 0
for i in range(0,N,2):
    Alice += A[i]
Bob = sum(A) - Alice
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())
table=list(map(int,input().split()))
alice_num=0
bob_num=0
table=sorted(table)
for i in range(N-1,-1,-1):
    if N%2==0:
        if i%2==1:
            alice_num+=table[i]
        else:
            bob_num+=table[i]
    else:
        if i%2==1:
            bob_num+=table[i]
        else:
            alice_num+=table[i]

print((alice_num)-(bob_num))

Submission status: Accepted

Solution code:
n = int(input())
data = input().split()

int_data = [int(int_data) for int_data in data]
int_data.sort(reverse=True)

Alice = 0
Bob = 0

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

Submission status: Accepted

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

a.sort()

alice = 0
bob = 0


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

print(abs(alice-bob))

Submission status: Accepted

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

Submission status: Accepted

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

AN.sort(reverse=True)

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

print (alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for i, j in enumerate(a):
    if i&1 is 0: ans += j
    else: ans -= j
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Alice = 0
Bob = 0

for x in range(0, len(a), 2):
    Alice += a[x]

for x in range(1, len(a), 2):
    Bob += a[x]

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    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]
        if i % 2 != 0: bob += A[i]
    print(alice - bob)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

A = sum(a[0::2])
B = sum(a[1::2])

print(A-B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC 088 B

N = int(input())
x = list(map(int,input().split()))
x = sorted(x, reverse=True)
a = 0
b = 0
ans = 0

if N % 2 == 0:
    for i in range(N//2):
        a += x[2*i]
        b += x[2*i + 1]
    ans = a-b
else:
    for i in range((N-1)//2):
        a +=  x[2*i]
        b +=  x[2*i + 1]
    ans = a+ x[-1] - b
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
asum=0
bsum=0
cnt=0
while True:
    asum+=max(A)
    A.remove(max(A))
    cnt+=1
    if cnt==N:
        break
    bsum+=max(A)
    A.remove(max(A))
    cnt+=1
    if cnt==N:
        break

print(asum-bsum)

Submission status: Accepted

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

a.sort(reverse=True)
if n%2 == 1:
    a.append(0)
    n += 1
ans = 0
for i in range(n//2):
    ans += a[2*i]
    ans -= a[2*i+1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
alice = 0
Bob = 0

list.sort(a, reverse=True)
for i in range(math.ceil(n/2)):
	alice += a[i*2]
for i in range(math.floor(n/2)):
	Bob += a[i*2 + 1]
print(alice - Bob)

Submission status: Accepted

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

L.sort(reverse=True)
ans=0
for i in range(n):
	if (i+2)%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()))

A.sort(reverse = True)

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

Submission status: Accepted

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

a.sort(reverse=True)

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

print(ans - ans2)

Submission status: Accepted

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

score.sort(reverse=True)
Alice = []
Bob = []
for i in range(len(score)):
  if i%2==0:
    Alice.append(score[i])
  else:
    Bob.append(score[i])
    
print(sum(Alice)-sum(Bob))

Submission status: Accepted

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

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

alice = 0
bob = 0

while len(a) != 0:
    alice += max(a)
    a.remove(max(a))
    if len(a) == 0:
        break
    bob += max(a)
    a.remove(max(a))

print(alice-bob)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    ans=sum([a[i]*((-1)**i) for i in range(N)])
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
#10
N = int(input())
x = list(map(int,input().split()))
alis = 0
bob = 0
cou = 0

x.sort()

for i in reversed(range(N)):
    if cou %2 == 0:
        alis += x[i]
    else:
        bob += x[i]
    cou += 1

print(alis - bob)

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

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

print(alice - bob)

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

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

Submission status: Accepted

Solution code:
N = int (input ())
L = input ().split ()
l = [int(s) for s in L]
list.sort (l, reverse=True)
a = 0
x = 0
y = 0
while True:
    x += int (l[a])
    a += 1
    if a == N:
        break
    y += int (l[a])
    a += 1
    if a == N:
        break
print (x-y)

Submission status: Accepted

Solution code:
# B Card Game for Two

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

al = 0
bo = 0

for i in range(len(a)):
    if i % 2 == 1:
        bo += a[i]
    else:
        al += a[i]

print(al - bo)

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:
def main():
    N = int(input())
    a = sorted([int(x) for x in input().split(" ")], reverse=True)
    Alice = sum([x for i, x in enumerate(a) if i % 2 == 0])
    Bob = sum([x for i, x in enumerate(a) if i % 2 == 1])
    print(Alice-Bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(A - B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
Alice = 0
Bob = 0
i = 0
while i < N:
  Alice += a[i]
  i += 1 
  if i >= N:
    break
  Bob += a[i]
  i += 1
  
print(Alice - Bob)