Problem:


Score: 200 points

Problem Statement

We have N cards. A number a_i is written on the i-th card.

Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.

The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Constraints

N is an integer between 1 and 100 (inclusive).

a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:  

N
a_1 a_2 a_3 ... a_N

Output

Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

Sample Input 1

2
3 1

Sample Output 1

2

First, Alice will take the card with 3. Then, Bob will take the card with 1.
The difference of their scores will be 3 - 1 = 2.

Sample Input 2

3
2 7 4

Sample Output 2

5

First, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.

Sample Input 3

4
20 18 2 18

Sample Output 3

18



Sample input:
2
3 1


Sample output:
2

Submission status: Accepted

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

A = []
B = []

while N > 0:
    A.append(max(a))
    a.remove(max(a))
    N -= 1
    if N != 0:
        B.append(max(a))
        a.remove(max(a))
        N -= 1

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

Submission status: Accepted

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

a.sort()
a.reverse()

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

Submission status: Accepted

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

a.sort()
a.reverse()

alice,bob=0,0

if n%2 == 0:
    for i in range(int(n/2)):
        alice += a[2*i]
        bob += a[2*i+1]
else:
    for i in range(int((n+1)/2)):
            alice += a[2*i]
            bob += a[2*i+1] if 2*i+1<len(a) else 0

print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
src = list(map(int, input().split()))
a = 0
b = 0
srt = sorted(src, reverse=True)
for i,s in enumerate(srt):
    if i%2 == 0:
        a += s
    else:
        b += s
print(a-b)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
A_score = 0
B_score = 0
counter = 0
while len(a)>0:
  if counter % 2 == 0:
    A_score += a.pop()
  else:
    B_score += a.pop()
  counter += 1

print(A_score - B_score)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
alice_sum = 0
bob_sum = 0
turn = 1
a.sort(reverse=True)
for i in range(n):
    if turn == 1:
        alice_sum += a.pop(0)
    else:
        bob_sum += a.pop(0)
    turn *= (-1)
print(alice_sum-bob_sum)

Submission status: Accepted

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

bob = 0
alice = 0

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

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:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(A - B)

Submission status: Accepted

Solution code:
N, i = [input() for x in range (2)]
arr = sorted([int(y) for y in i.split(' ')], reverse=True)

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = sorted([int(a) for a in input().split()], reverse = True)
    Alice = 0
    for i in range(N):
        if i % 2 == 0:
            Alice += A[i]
    return 2*Alice - sum(A)

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

Submission status: Accepted

Solution code:
import math
N = int(input())
M = list(map(int, input().split()))
alice = 0
bob = 0
M.sort()
for i in range(math.ceil(N/2)): 
    alice += M[2*i]
    if N % 2 != 0 and i == int(N/2):
        break
    bob += M[2*i+1]
print(abs(alice - bob))

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
q_li = deque(lis)
a = 0
b = 0
for l in range(n):
    if l % 2 == 0:
        a += q_li.popleft()
    else:
        b += q_li.popleft()
print(a-b)

Submission status: Accepted

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

    
print(alice-bob)

Submission status: Accepted

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

while a != []:
  alice += max(a)
  a.remove(max(a))
  try:
  	bob += max(a)
  except:
    break
  try:
    a.remove(max(a))
  except:
    break
    
print(alice-bob)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
a=list(map(int,input().split()))
A=0
B=0


a=sorted(a,reverse=True)

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())
lista=list(map(int,input().split()))
lista.sort(reverse=True)
alice=list()
bob=list()
for i in range(n):
    if i%2==0:
        alice.append(lista[i])
        
    else: 
        bob.append(lista[i])

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

Submission status: Accepted

Solution code:
n = int(input())
array = list(map(int,input().split()))
array.sort(reverse=True)
alice = 0
bob = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0

for i in range(0, len(A), 2):
    alice += A[i]
    if len(A) > i + 1:
        bob += A[i + 1]

print(alice - bob)

Submission status: Accepted

Solution code:
#ABC 088 B
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Alice=0
Bob=0

if len(A)%2==1:
    A.append(0)

while len(A)>=1:
    Alice+=A.pop(0)
    Bob+=A.pop(0)
print(Alice-Bob)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))[::-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(sorted(map(int, input().split())))[::-1]
if N % 2 == 1:
    a += [0]
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())
cards = list(map(int, input().split()))

cards.sort(reverse = True)
sum_A = 0
sum_B = 0


for i in range(N):
    if i % 2 == 0:
        sum_A += cards[i]
    else:
        sum_B += cards[i]

print(sum_A - sum_B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def searchMaxIndex(arr):
    if len(arr) == 0:
        return -1

    result = 0
    for i in range(len(arr)):
        if arr[i] > arr[result]:
            result = i

    return result

def pullValueBiIndex(arr, index):
    result = arr[index]
    arr.pop(index)
    return result

card_count = int(input())
cards = input()
cards = [int(value) for value in cards.split(' ')]

alice = 0
bob = 0

while len(cards) > 0:
    index = searchMaxIndex(cards)
    alice += pullValueBiIndex(cards, index)

    index = searchMaxIndex(cards)
    if index == -1:
        break
    bob += pullValueBiIndex(cards, index)

print(alice - bob)

Submission status: Accepted

Solution code:
N=int(input())
a = [int(i) for i in input().split()] 
sorted_a=sorted(a)
sum_A=0
sum_B=0
while sorted_a != []:
    sum_A+= sorted_a[-1]
    if len(sorted_a)!=1:
        sum_B+= sorted_a[-2]
    del sorted_a[-1]
    if sorted_a!=[]:
        del sorted_a[-1]

print(sum_A-sum_B)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ABC 083 B - Some Sums
# 整数の入力
a = int(input())
# スペース区切りの整数の入力
b = [int(s) for s in input().split()]
b.sort(reverse=True)
alice = sum(b[0::2])
bob   = sum(b[1::2])
# print("Alice : {}".format(alice))
# print("Bob   : {}".format(bob))
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_sort = sorted(a, reverse=True)

Asum = 0
Bsum = 0

for i in range(1, N+1):
  if i%2 != 0:
    Asum += a_sort[i-1]
  else:
    Bsum += a_sort[i-1]

print(Asum-Bsum)

Submission status: Accepted

Solution code:
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
a = sum([v for i, v in enumerate(c) if i % 2 == 0 ])
b = sum([v for i, v in enumerate(c) if i % 2 == 1 ])
print(a - b)

Submission status: Accepted

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

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

print(Alice-Bob)

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(0,n,2):
  alice+=a[i]
for i in range(1,n,2):
  bob+=a[i]
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(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, ai in enumerate(a):
    if i % 2 == 0:
        alice += ai
    else:
        bob += ai

print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
#list内包表記で書こう
#速いし、書きやすい
a=sorted([int(i) for i in input().split()],reverse=True)
b=0
for i in range(n):
    if i%2==0:
        b+=a[i]
    else:
        b-=a[i]

print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
al = 0
bo = 0
for i, v in enumerate(a):
    if i % 2 == 0:
        al += v
    else:
        bo += v
print(abs(al - bo))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Num = int(input())
Num_Array = sorted(list(map(int,input().split())),reverse=True)
Alice,Bob = 0,0

for i in range(Num):

    if i % 2 == 0 :
        Alice += Num_Array[i]
    else:
        Bob   += Num_Array[i]

print(Alice - Bob)

Submission status: Accepted

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

for i in range ( Num ):
    Check_Max = -1

    for x in range(len(Num_Array)):
        if Num_Array[x] > Check_Max :
            Check_Max = Num_Array[x]
            check = x

    Num_Array.pop(check)

    if i % 2 == 0 :
        Alice += Check_Max
    else:
        Bob += Check_Max

print(Alice - Bob)

Submission status: Accepted

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

sorted_A = sorted(A, reverse=True)

alice = 0
bob = 0
for index, point in enumerate(sorted_A):

  # Alice
  if (index + 1) % 2 != 0:
    alice = alice + point
  
  # Bob
  else:
    bob = bob + point
 
answer = alice - bob

print(answer)

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

Submission status: Accepted

Solution code:
from itertools import zip_longest

def main():
    n, *a = map(int, open(0).read().split())
    a = reversed(sorted(a))
    res = sum(a - b for a, b in zip_longest(*[iter(a)]*2, fillvalue=0))
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

c.sort(reverse=True)
for i,j in enumerate(c):
  if i % 2 == 0:
    a += j
  else:
    b += j

print(a-b)

Submission status: Accepted

Solution code:
import math
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
for i in range(1, math.floor(N / 2 + 1)):
    Alice += max(a)
    a.remove(max(a))
    Bob += max(a)
    a.remove(max(a))
if N %2 != 0:
    Alice += max(a)
print(Alice - Bob)

Submission status: Accepted

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

li.sort(reverse = True)
for i in li[0::2]:
  a.append(i)
for i in li [1::2]:
  b.append(i)
print(sum(a) - sum(b))

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)):
    diff += (-1)**i * a[i]

print(diff)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
a_lst = [int(x) for x in stdin.readline().rstrip().split()]

alice_sum = 0
bob_sum = 0

a_lst.sort(reverse=True)

for i, v in enumerate(a_lst):
  if i % 2 == 0:
    alice_sum += v
  else:
    bob_sum += v

print(alice_sum - bob_sum)

Submission status: Accepted

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

Bob=Alice = 0
loop=0

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

Submission status: Accepted

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

a = a.split()


for i in range(n):
	a[i] = int(a[i])

a	= sorted(a)
a.reverse()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    sw = 0
    alice = 0
    bob = 0
    for i in a:
        if sw == 0:
            alice += i
            sw = 1
        else:
            bob += i
            sw = 0
    print(alice-bob)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input1 = input().rstrip()
inputs = input().rstrip().split(' ')
inputs_list = list(inputs)
input1 = int(input1)

Alice = 0
Bob = 0

for i in range(input1):
    tmp = inputs_list[0]
    for j in range(len(inputs_list)):
        if (int(tmp) < int(inputs_list[j])):
            tmp = inputs_list[j]
    inputs_list.remove(tmp)
    if (i % 2 == 0):
        Alice += int(tmp)
    else:
        Bob += int(tmp)

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

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int, input().split()))
lis = sorted(lis)
alice = 0
bob = 0
for i, value in enumerate(lis):
    if i % 2 != 0:
        alice += value
    else:
        bob += value
print(abs(alice - bob))

Submission status: Accepted

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

Submission status: Accepted

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

b = sorted(a, reverse = True)

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

print(total)

Submission status: Accepted

Solution code:
N = int(input())

#mapの使い方
#map(functon,sequence_object)
#第一引数が関数第二引数がシーケンス
#mapを使うと一つの要素に対する処理をリスト全体に対して行ってくれる
#input.splitではinput（入力）をスペース区切りのリストにしている。その要素に対してmapで数字をintに変換

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

#降順にソート
l.sort(reverse=True)

#スライスの使い方l(strt:stop:step)
#strt,stopは0から始まる
print(sum(l[0::2]) - sum(l[1::2]))

Submission status: Accepted

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

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

print(alice-bob)

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:
# B - Card Game for Two
n = int(input())
num_list = list(map(int, input().split()))

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

Submission status: Accepted

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

a.sort()
a.reverse()


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

print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())

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

#リストを大きい順に並び替える
A.sort(reverse=True)
#print(A)

#Aliceは要素0から偶数分加算
Alice = sum(A[0::2])
#Bobは要素1から奇数分加算
Bob = sum(A[1::2])

#print(Alice,Bob)

#AliceからBobを引く
print(Alice-Bob)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
cards = [int(i) for i in input().split()]
alice = 0
bob = 0

for j in range(n):
    if j%2 == 0:
        alice += cards.pop(cards.index(max(cards)))
    else:
        bob += cards.pop(cards.index(max(cards)))

print(alice - bob)

Submission status: Accepted

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

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

    print(alice - bob)


main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=list(sorted(map(int,input().split()),reverse=True))
print(sum(aa[::2]) - sum(aa[1::2]))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
for i in range(n):
  if i % 2 == 0: # Alice
    alice += a.pop(np.argmax(a))
  else: # Bob
    bob += a.pop(np.argmax(a))
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
a = sorted(list(map(int, input().split())))
A = sum(a[-1::-2])
B = sum(a[-2::-2])
print(str(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())
list_c = sorted(map(int,input().split()))[::-1]
a = sum(list_c[::2])
b = sum(list_c[1::2])

print(a - b)

Submission status: Accepted

Solution code:
N = int(input())
numbers = [x for x in map(int, input().split())]
numbers.sort(reverse=True)
print(sum([numbers[x] for x in range(N) if x % 2 ==0]) 
      - sum([numbers[x] for x in range(N) if x % 2 ==1]))

Submission status: Accepted

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

A.sort(reverse=True)
l = 0
r = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        l += a
    else:
        r += a
print(l-r)

Submission status: Accepted

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

sla=sorted(la,reverse=True)

a_li=[]
b_li=[]
for i in range(n):
    if(i%2==0):
        a_li.append(sla[i])
    else:
        b_li.append(sla[i])

print(sum(a_li)-sum(b_li))

Submission status: Accepted

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

alice = 0
bob = 0

a_list.sort(reverse=True)

for x in range(0, n, 2):
    alice += a_list[x]

for y in range(1, n, 2):
    bob += a_list[y]

print(alice - bob)

Submission status: Accepted

Solution code:
#ABC 088 B - Card Game for Two
N = int(input())
card_list = [int(i) for i in input().split()]
alice = 0
bob = 0
for i in range(N):
    if i%2==0:
        m = max(card_list)
        alice += m
        card_list.remove(m)
    if i%2==1:
        m = max(card_list)
        bob += m
        card_list.remove(m)
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

apoint = 0
bpoint = 0
while True:
	apoint += max(cards)
	cards.remove(max(cards), )

	if len(cards) == 0:
		break

	bpoint += max(cards)
	cards.remove(max(cards))

	if len(cards) == 0:
		break

dif = apoint - bpoint
print(dif)

Submission status: Accepted

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

Alice_score = 0
Bob_score = 0
for i in range(-(-N//2)): # 回数
    Alice_score += max(a)
    a.remove(max(a))
    if len(a) == 0: 
        break
    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()))

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

Submission status: Accepted

Solution code:
def intget():
    return int(input())

_n = intget()
ar = list(map(int, input().split()))
ar.sort()
ar.reverse()

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

print(alice - bob)

Submission status: Accepted

Solution code:
N=int(input())
AN=list(map(int,input().split()[:N]))
ANsort=sorted(AN,reverse=True)

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

Submission status: Accepted

Solution code:
n=int(input())
card=list(map(int,input().split()))
A=0
B=0
count=0
while len(card)!=0:
    point=max(card)
    if count%2==0:
        A +=point
    else:
        B +=point
    count +=1
    card.remove(point)
print(A-B)

Submission status: Accepted

Solution code:
input()
cards = sorted(map(int, input().rstrip("\n").split()), reverse=True)

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

Submission status: Accepted

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

a.sort(reverse=True)

alice = 0
bob = 0

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

Submission status: Accepted

Solution code:
n = input()
a_list = [int(num) for num in input().split()]

alice = 0
bob = 0

while True:
  if len(a_list) < 1:
    break
  next_num = max(a_list)
  alice += next_num
  a_list.remove(next_num)
  if len(a_list) < 1:
    break
  next_num = max(a_list)
  bob += next_num
  a_list.remove(next_num)

print(alice - bob)

Submission status: Accepted

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

a.sort();
result = 0;

for i in range(N):
    result += a[i]*(-1)**i

print(abs(result))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if len(a)%2 == 1:
    a = [0] + a

count = 0
for i in range(len(a)//2):
    count+=a[2*i+1]-a[2*i]
print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

a = 0
b = 0

card.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = 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
    elif i%2 == 1:
        Bob += a
answer = Alice - Bob
print(answer)

Submission status: Accepted

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

a_list_descend = sorted(a_list, reverse=True)

diff = sum(a_list_descend[0::2]) - sum(a_list_descend[1::2])

print(diff)

Submission status: Accepted

Solution code:
_,*l=map(int,open(0).read().split())
l.sort()
print(sum(l[-1::-2])-sum(l[-2::-2]))

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[i]
    else:
        bob += a[i]

print(alice - bob)

Submission status: Accepted

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

for i in range(0, n, 2):
    alice += a_list[i]
for i in range(1, n, 2):
    bob += a_list[i]
print(alice - bob)