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

A=[]
B=[]

for i in range(N):
    if i==0 or i%2==0:
        A.append(lst[i])
    else:
        B.append(lst[i])

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

Submission status: Accepted

Solution code:
data = [input() for x in range(0, 2, 1)]

cards = [int(x) for x in data[1].split(" ")]

#バブルソート
for i in range(0, len(cards), 1):
  
  for j in range(i + 1, len(cards), 1):
    
    if cards[i] < cards[j]:
      tmp1 = cards[i]
      tmp2 = cards[j]
      
      cards[i] = tmp2
      cards[j] = tmp1
      
alice = 0
bob = 0

#cardsをソート

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

Submission status: Accepted

Solution code:
def main():
  size = input()
  a = list(map(int, input().split()))
  a = merge_sort(a)
  
  alice_res = 0
  bob_res = 0
  
  for i in range(len(a)):
    if i%2 == 0:
      alice_res += a[i]
    else:
      bob_res += a[i]
 
  print(alice_res-bob_res)
  
 
def merge_sort(array):
  if len(array)<=1:
    return array
  
  spl_size = len(array)//2
  
  left_list = merge_sort(array[:spl_size])
  right_list = merge_sort(array[spl_size:])
  
  return merge_list(left_list, right_list)
 
 
def merge_list(left_list, right_list):
  left_index = 0
  right_index = 0
  sorted_list = []
  
  while left_index<len(left_list) and right_index<len(right_list):
    if left_list[left_index] < right_list[right_index]:
      sorted_list.append(right_list[right_index])
      right_index+=1
    else:
      sorted_list.append(left_list[left_index])
      left_index+=1
      
  if left_index == len(left_list):
    sorted_list.extend(right_list[right_index:])
  if right_index == len(right_list):
    sorted_list.extend(left_list[left_index:])
      
  return sorted_list
    
                          
main()

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-
# input
a = int(input())
num = [int(a) for a in input().split()]

# Sort
num.sort(reverse=True)

ans = sum(num[0::2]) - sum(num[1::2])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

li.sort()
li.reverse()
ans = 0
for i in range(n):
  if i%2 == 0:
    ans += li[i]
  else:
    ans -= li[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = 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

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

ans = (Alice - Bob)

print(ans)

Submission status: Accepted

Solution code:
import sys
import subprocess
import re
import datetime
import os

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 = Alice + A[i]
    else:
        Bob = Bob + A[i]

ans = (Alice - Bob)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 整数の入力
n = input()
n = int(n)

# いくつあるかわからないときのスペース区切りの整数の入力
nums = input().split()
nums = list(map(int,nums))

#print(nums)

nums.sort(reverse=True)

#print(nums)

i = 0
Alis = 0
Bob = 0

for i in range(0,n):
    if i % 2 == 0:
        Alis = Alis + nums[i]
    else:
        Bob = Bob + nums[i]

print(Alis-Bob)

#print(Alis)
#print(Bob)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
A_0 = A.sort(reverse=True)
swt = 0
Alice_point = 0
Bob_point = 0

for i in range(n):
    if swt == 0:
        Alice_point += A[i]
        swt = 1
    else:
        Bob_point += A[i]
        swt = 0
print(Alice_point - Bob_point)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

b = []
for i in range(N):
    b.append(max(a))
    a.remove(max(a))

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

result = Alice - Bob
print(result)

Submission status: Accepted

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

als = sum(a[::2])
bob = sum(a[1::2])

print(als - bob)

Submission status: Accepted

Solution code:
a = int(input())
card = list(map(int, input().split()))
card.sort(reverse=True)
Alice_card = []
Bob_card = []
for i in range(a):
    if i % 2 == 0:
        Alice_card.append(card[i])
    else:
        Bob_card.append(card[i])

Alice_point = sum(Alice_card)
Bob_point = sum(Bob_card)
Point = Alice_point - Bob_point
print(Point)

Submission status: Accepted

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

a.sort(reverse=True)
alice = a[0::2]
bob = a[1::2]

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

Submission status: Accepted

Solution code:
def main():
    N = map(int, input().split())
    a = [int(s) for s in input().split()]
    a.sort(reverse = True)
    ans = 0
    ans = sum(a[0::2]) - sum(a[1::2])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
  max=0
  tmp=0
  for j in list:
    if max<j:
      max=j
      key=tmp
    tmp+=1
  if i%2==0:#Aliceの番
    Alice+=max
  else:
    Bob+=max
  del list[key]
print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(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())
s=list(map(int,input().split()))
s.sort(reverse=True)
a=[int(i) for i in s[::2]]
b=[int(j) for j in s[1::2]]
print(sum(a)-sum(b))

Submission status: Accepted

Solution code:
# ABC088B - Card Game for Two
import sys
input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
# ABC088B - Card Game for Two
n = int(input())
lst = sorted(list(map(int, input().rstrip().split())), reverse=True)
total = 0
for i in range(n):
    if i % 2 == 0:
        total += lst[i]
    else:
        total -= lst[i]
print(total)

Submission status: Accepted

Solution code:
input()
print(sum(-k if i%2 else k for i,k in enumerate(sorted(map(int,input().split()),reverse=True))))

Submission status: Accepted

Solution code:
n=(int(input())+1)%2
print(sum(k if i%2==n else -k for i,k in enumerate(sorted(map(int,input().split())))))

Submission status: Accepted

Solution code:
_ = input()
print(sum(k if i%2 == 0 else -k for i,k in enumerate(sorted(map(int,input().split()),reverse=True))))

Submission status: Accepted

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

Submission status: Accepted

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

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())
numbers = list(map(int,input().split()))
alice = []
a = sum(numbers)
numbers.sort()
b = int(n/2)
if n%2 == 0 :
    for i in range(b) :
        alice.append(int(numbers[2*i+1])) 
else :
    for j in range(b+1) :
        alice.append(int(numbers[2*j])) 

x = sum(alice)
y = a - x
print(x - y)

Submission status: Accepted

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

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

Submission status: Accepted

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

A.sort(reverse=True)
alice = sum([a for i, a in enumerate(A) if i%2 == 0])
bob   = sum([a for i, a in enumerate(A) if i%2 == 1])
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a = [int(x) for x in input().split()]
a.sort()
a.reverse()
j=0
k=0
for i in range(N):
    if i%2==0:
        j=j+a[i]
    else:
        k=k+a[i]
l=j-k
print(l)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

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


A.sort()
A.reverse()

Alice=0
Bob=0

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

        
gap=Alice-Bob
print(gap)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Alice = 0
Bob = 0

num_list.sort(reverse=True)
for i, num in enumerate(num_list):
    if i % 2 == 0:
        Alice += num
    else:
        Bob += num

print(Alice - Bob)

Submission status: Accepted

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

Alice = 0
Bob = 0

for i in range(n):
    current_max = max(num_list)
    if i % 2 == 0:
        Alice += current_max
    else:
        Bob += current_max
    num_list.remove(current_max)

print(Alice - Bob)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
alice = []
bob = []

for i in range(len(A)):
  max_n = max(A)
  A.remove(max_n)
  if i%2 == 0:
    alice.append(max_n)
  else:
    bob.append(max_n)
print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
import sys

def main():
    n = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)
    print(counter(n, a))

def counter(n, a):
    return sum(a[::2]) - sum(a[1::2])

if __name__ == '__main__':
    main()

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

for i in range(n//2):
    bob+=a[-2-2*i]

if n%2!=0:
    alice+=a[0]


print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
Alice = 0
Bob = 0
for i in range(0, len(a), 2):
        Alice += a[i]
        
for i in range(1, len(a), 2):
        Bob += a[i]

print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
alice = sum([A[i] for i in range(0, n, 2)])
bob = sum([A[i] for i in range(1, n, 2)])
print(alice - bob)

Submission status: Accepted

Solution code:

N = int(input())

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

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())
a_list = list(map(int, input().split(' ')))
a_list.sort()
Alice = sum(a_list[-1::-2])
Bob = sum(a_list[-2::-2])
result = Alice - Bob
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

card_list.sort()
card_list.reverse()

Alice = 0
Bob = 0

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

Submission status: Accepted

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

a.sort(reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
a.reverse()
score = 0
for ind,i in enumerate(a):
    if(ind%2==0):
        score+=i
    else:
        score-=i
print(score)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
n=[int(i) for i in input().split()]
list.sort(n,reverse=True)
Ali=0
Bob=0

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

Submission status: Accepted

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

alice_count = 0
bob_count = 0
for i in range(N//2):
  alice_count += max(a)
  a.pop(a.index(max(a)))
  bob_count += max(a)
  a.pop(a.index(max(a)))

if a:
  alice_count += a[0]
  
count = alice_count - bob_count

print(count)

Submission status: Accepted

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


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

a.sort(reverse=True)

print(sum(j for i,j in enumerate(a) if i%2==0) - sum(j for i,j in enumerate(a) if i%2==1))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
c1 = 0
c2 = 0
for i in a[::2]:
    c1 += i
    a.remove(i)
c2 = sum(a)
print(c1 - c2)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
al = []
bo = []
for idx, card in enumerate(a):
    if idx % 2 == 0:
        al.append(card)
    else:
        bo.append(card)
print(sum(al) - sum(bo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a[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)
Asum=0
Bsum=0
for i in range(N):
    if i%2==0:
        Asum+=a_list[i]
    else:
        Bsum+=a_list[i]
print(Asum-Bsum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
aList = list(map(int, input().split()))
aList.sort(reverse = True)
aPoint = 0
bPoint = 0
if N % 2 == 0:
    for i in range(N//2):
        aPoint += aList[2*i]
        bPoint += aList[2*i + 1]
else:
    for i in range(N//2):
        aPoint += aList[2*i]
        bPoint += aList[2*i + 1]
    aPoint += aList[N-1]
print(aPoint - bPoint)

Submission status: Accepted

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

pts=[0,0]
for i in range(N):
	pts[i%2] += a[i]

print(pts[0]-pts[1])

Submission status: Accepted

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

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

Submission status: Accepted

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

m = sum([n for i, n in enumerate(a) if i%2 == 0])

print(2*m - sum(a))

Submission status: Accepted

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

a = sorted(a, reverse=True)

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

print(alice - bob)

Submission status: Accepted

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

card.sort()
card.reverse()

A=card[0::2]
B=card[1::2]

ans=sum(A)-sum(B)

print(ans)

Submission status: Accepted

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

a.sort(reverse=True)

alice = True
al = 0
bo = 0

for a_ in a:
    if alice:
        al += a_
    else:
        bo += a_
    alice = not alice

print(al - bo)

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

card.sort()
card.reverse()

A = card[0::2]
B = card[1::2]

x = sum(A) - sum(B)

print(x)

Submission status: Accepted

Solution code:
n = int(input())

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

b = sorted(a, reverse=True) # reverse = Trueは降順
# print(b)
# print(b[0])

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

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

Submission status: Accepted

Solution code:
n=int(input())
L=[int(i) for i in input().split()]
print(2*sum(sorted(L)[::-2])-sum(L))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Ai = input().split()
Ai = [int(n) for n in Ai]
Ai = sorted(Ai, reverse=True)
Alice = 0
Bob = 0
i = 0
while True:
  if i+1 <= N-1:
    Alice += Ai[i]
    Bob += Ai[i+1]
  if i == N-1:
    Alice += Ai[i]
  if i > N-1:
    break
  i = i + 2

print(Alice - Bob)

Submission status: Accepted

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

total=0

for i in range(len(a)):
    if i % 2 == 0 :
        total+=max(a)
        index=a.index(max(a))
        a[index]=0
    else:
        total-=max(a)
        index=a.index(max(a))
        a[index]=0

print(total)

Submission status: Accepted

Solution code:
N = int(input())
list_an = input().split()
list_an_int = [int(s) for s in list_an]

list_an_int.sort()
list_an_int.reverse()

Alice_counter = 0
Bob_counter = 0

counter = 0
for i in range(N):
    if counter % 2 == 0:
        Alice_counter += list_an_int[i]
    else:
        Bob_counter += list_an_int[i]
    counter += 1
print(Alice_counter - Bob_counter)

Submission status: Accepted

Solution code:
import sys
l1, l2 = [sys.stdin.readline().strip() for i in range(2)]
input_list = [int(i) for i in l2.split()]
input_list.sort(reverse=True)
odd_index = [j for i, j in enumerate(input_list) if i%2 != 0]
even_index = [j for i, j in enumerate(input_list) if i%2 == 0]
print(sum(even_index) - sum(odd_index))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

result = 0
is_even = True
for x in a:
    result += x if is_even else -x
    is_even = not is_even
print(result)

Submission status: Accepted

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

for i, num in enumerate(sorted(a)[::-1]):
    if i%2 == 0:
        alice += num
    else:
        bob += num

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#088 B
N =int(input())

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

Submission status: Accepted

Solution code:
N = int(input())
numbers_list = sorted([int(num) for num in input().split()])
Alice_sum = sum([numbers_list[index] for index in range(N) if index % 2 == 0])
Bob_sum = sum([numbers_list[index] for index in range(N) if index % 2 != 0])
print(abs(Alice_sum - Bob_sum))

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
A=sum([a[i] for i in range(n) if i%2==0])
B=sum([a[i] for i in range(n) if i%2!=0])
print(abs(A-B))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
input()

numbers = sorted(list(map(int, input().split())))

alice = bob = 0

while(len(numbers)):
	if len(numbers) == 1:
		alice += numbers.pop()
	else:
		alice += numbers.pop()
		bob += numbers.pop()

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Alice = 0
Bob = 0

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

Submission status: Accepted

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

n_list.sort()
sorted_list = n_list[::-1]

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

Submission status: Accepted

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

total = 0

while nums:
    total += max(nums)
    nums.remove(max(nums))
    if nums:
        total -= max(nums)
        nums.remove(max(nums))

print(total)


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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(S)

Submission status: Accepted

Solution code:
n=input()
a=map(int, raw_input().split())
a.sort()
al=bo=0
i=0
for aa in reversed(a):
    if i%2==0:al+=aa
    else:bo+=aa
    i+=1
print(al-bo)

Submission status: Accepted

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

c = 0
ad = 0
for i in range(n):
 if c == 0:
  ad += b[i]
  c = 1
 else:
  ad -= b[i]
  c = 0

print(ad)

Submission status: Accepted

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

alice = a[::2]
bob = a[1::2]

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

Submission status: Accepted

Solution code:
_,s=open(0);c=0
for a in sorted(map(int,s.split())):c=a-c
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

alice = cards[::2]
bob = cards[1::2]

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

Submission status: Accepted

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