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

a_list.sort(reverse=True)

Alice = 0
Bob = 0
for num,i in enumerate(a_list):
    if (num+1)%2 != 0:
        Alice+=i
    else:
        Bob+=i
        
print(Alice - Bob)

Submission status: Accepted

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

Alice = 0
Bob = 0

ls_b = sorted(ls_a, reverse=True)

for i in range(n):
    if i % 2 == 0:
        Alice += ls_b[i]
    elif i % 2 == 1:
        Bob += ls_b[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(reverse = True)
print(sum(i for i in a[::2]) - sum(i for i in a[1::2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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 = sorted(list(map(int, input().split())), reverse=True)

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

ans = Alice - Bob
print(ans)

Submission status: Accepted

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

Alice = 0
Bob = 0
cou = 1

for i in range(N):
    if cou % 2 != 0:
        Alice += max(a)
        a.remove(max(a))
    else:
        Bob += max(a)
        a.remove(max(a))
    cou += 1

print(Alice - Bob)

Submission status: Accepted

Solution code:
dbflag=""

def debug(*args):
  if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
  if ""!=dbflag:return _INDATA.readline()
  else: return input()


result = 0

N = int(readline())

#リスト型
A = [int(i) for i in readline().split(' ')]


#２次元配列
import numpy as np
ndary=np.array(A,dtype=int)

ndary.sort()
d = ndary[::-1]
for i in range(0,N):
  if i%2==0:
    result += d[i]
  else:
    result -= d[i]

print(result)

Submission status: Accepted

Solution code:
#coding=utf-8
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=input()

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

alice = 0
bob = 0

while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

print(alice - bob)

Submission status: Accepted

Solution code:
N=input()

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

alice = 0
bob = 0

#Ai.sort()
#print(Ai)

while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

print(alice - bob)

Submission status: Accepted

Solution code:
N=input()

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

alice = 0
bob = 0

Ai.sort()
#print(Ai)

while True:
    try:
        alice += Ai.pop()
        bob += Ai.pop()
    except:
        break

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=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()))
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

while(True):
    a.sort()
    alice += a.pop(-1)
    if a == []:
        break
    a.sort()
    bob += a.pop(-1)
    if a == []:
        break

print(alice-bob)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

a.sort(reverse=True)
print(2*sum([x for i, x in enumerate(a) if i % 2 == 0])-sum(a))

Submission status: Accepted

Solution code:

n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

ans = alice - bob
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

l = sorted([int(i) for i in input().split()],reverse = True)

alice = [i for idx,i in enumerate(l) if idx % 2 == 0]
bob = [i for idx,i in enumerate(l) if idx % 2 == 1]

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

Submission status: Accepted

Solution code:

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

new_a = sorted(a)

A = []
B = []

while len(new_a) != 0:
    if len(new_a) != 0:
        A.append(new_a.pop())
    else:
        break

    if len(new_a) != 0:
        B.append(new_a.pop())
    else:
        break
        

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

Submission status: Accepted

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

count = 0
A = 0
B = 0

while count < N+1 and len(a) >0: 
	m = max(a)
	A += m
	a.remove(m)  
	if len(a) > 0:
		m = max(a)
		B += m
		a.remove(m)
	count +=1

print(A - B)

Submission status: Accepted

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

alice = 0
bob = 0
an.sort()
an.reverse()
for i,v in enumerate(an):
    if i % 2 ==0:
        alice += v
    else:
        bob += v

print(alice - bob)

Submission status: Accepted

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

import numpy
import scipy

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

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

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

print(alice - bob)

Submission status: Accepted

Solution code:
import sys

def main():
    n, *a = map(int, sys.stdin.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:
N = int(input())
a = list(map(int, input().split()))

a = sorted(a, reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n  = int(input())
aa = [int(i) for i in input().split()]

aa = sorted(aa)

a, b, is_a = 0, 0, True
while len(aa) != 0:
    if is_a:
        a += aa.pop(-1)
        is_a = False
    else:
        b += aa.pop(-1)
        is_a = True

print(a-b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
Alice = 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:
num = []
A = 0
B = 0
count = int(input())
list = input().split()
for i in range(count):
    num.append(int(list[i]))
num = sorted(num, reverse = True)

while num != []:
    A += num.pop(0)
    if num != []:
        B += num.pop(0)

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(" ")))
As=list(reversed(sorted(A)))
print(sum(As[::2])-sum(As[1::2]))

Submission status: Accepted

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

for i in range(0,len(a_list) + 1,2):
    if i < len(a_list):
        Alice = Alice + a_list[i]
    else:
        break

for j in range(1,len(a_list) + 1,2):
    if j < len(a_list):
        Bob = Bob + a_list[j]
    else:
        break

diff = Alice - Bob

print(diff)

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]
ans = sum(Alice) - sum(Bob)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a = [int(i) for i in input().split()] 
A=0
B=0
C=0
k=0
for i in range(n):
  if i%2==0:
    k=max(a)
    A += k
    del a[a.index(k)]
  else :
    k=max(a)      
    B += k
    del a[a.index(k)]   
  
C=A-B          
print(C)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#88b
N = int(input())
a_list = [int(e) for e in input().split()]

a_list.sort(reverse=True)
Alice_point = sum(a_list[0::2])
Bob_point = sum(a_list[1::2])
print(Alice_point - Bob_point)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
A=list(map(int,input().split()))
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())
al = list(map(int,input().split()))
al = sorted(al, reverse=True)
print(sum(al[0::2]) - sum(al[1::2]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()] 
a.sort()
a = a[::-1]

Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
alice = 0
bob = 0
for i in range(1,n+1):
  if i%2==1:
    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())
input_list = list(map(int, input().split()))
input_list.sort(reverse=True)
# aliceは奇数番目のものを、bobは偶数番目のものをとる
a = 0
b = 0
for i in range(n):
    if (i+1) % 2 == 1:
        a += input_list[i]
    else:
        b += input_list[i]
print(a - b)

Submission status: Accepted

Solution code:
from collections import deque
 
N = int(input())
a = deque(sorted([int(i) for i in input().split()]))
 
sub = 0
for i in range(N):
    if i % 2 == 0:
        sub += a.pop()
    else:
        sub -= a.pop()
 
print(sub)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examB():
    N = I()
    A = LI(); A.sort(reverse = True)
    cur = 0
    for i,j in enumerate(A):
        cur +=j*((-1)**i)
    print(cur)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

Solution code:
n=int(input())
alis=sorted(list(map(int,input().split())))[::-1]
acount=0
bcount=0
for i in range(n):
	if i%2 ==0:
		acount+=alis[i]
	else:
		bcount+=alis[i]
print(acount-bcount)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum_ = sum(a)
a.sort()
#print(a)
alice = 0
for i in range(len(a)):
    if i % 2 == 0:
        #print(a[-i-1],alice)
        alice += a[-i-1]
print(2*alice - sum_)
#print(alice)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
alice = 0
bob = 0
l.sort(reverse= True)
while len(l) > 0:
    alice += l.pop(0)
    if len(l) == 0:
        break
    bob += l.pop(0)
print(alice - bob)

Submission status: Accepted

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

for g in range(d_number):
    d_sum += d[g]  # Bobのとる要素の合計

print(c_sum - d_sum)  # 差分を出力

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a = int(input())  # Nを入力
b = input()  # a1,a2...anを入
b = map(int, b.split())
b = sorted(b)
b = b[::-1]
c = b[::2]
c_number = len(c)
d = b[1::2]
d_number = len(d)
c_sum = 0
d_sum = 0
for i in range(c_number):
    c_sum += c[i]

for g in range(d_number):
    d_sum += d[g]

print(c_sum - d_sum)

Submission status: Accepted

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

print(al - bo)

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:
from sys import stdin
from itertools import combinations

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort(reverse=True)

ali = 0
bob = 0

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

print(ali-bob)

Submission status: Accepted

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

Submission status: Accepted

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

A.sort(reverse=True)

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

print(res)

Submission status: Accepted

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

Alice=[]    #Aliceが持っているカード
Bob=[]      #Bobが持っているカード
for i in range(N):
    if i%2==0:      #偶数だったらAlieがとる番
        Alice.append(max(a))
        a.remove(max(a))
    else:           #奇数だったらBobがとる番
        Bob.append(max(a))
        a.remove(max(a))

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

Submission status: Accepted

Solution code:
def card_game_for_two():
    input() # 一行目の入力は使わない　
    cards = sorted(list(map(int, input().split())), reverse=True)

    score_diff = sum(cards[::2]) - sum(cards[1::2])

    print(score_diff)

card_game_for_two()

Submission status: Accepted

Solution code:
N = int(input())
As = map(int, input().split())
sorted_As = sorted(As, reverse=True)
alice_sum = 0
bob_sum = 0
for i, a in enumerate(sorted_As):
    if (i+1) % 2 == 1:
        alice_sum += a
    else:
        bob_sum += a
print(alice_sum - bob_sum)

Submission status: Accepted

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

a.sort(reverse=True)

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Accepted

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

Alice = 0
Bob = 0

for i in range(N):
    maxa = max(a)
    a.remove(maxa)
    if i % 2 == 0:
        Alice += maxa
    else:
        Bob += maxa

ans = Alice - Bob
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

alice_score = sum(cards[::2])
bob_score = sum(cards[1::2])

print(alice_score - bob_score)

Submission status: Accepted

Solution code:
input()
a = list(reversed(sorted([int(i) for i in input().split()])))
print(sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

Solution code:
def buttle(a):
    alice = 0
    bob = 0

    a.sort(reverse=True)
    for i in range(len(a)):
        if i % 2 != 0:
            continue
        alice += a[i]
        if len(a) > i+1:
            bob += a[i+1]
    return alice - bob

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

Submission status: Accepted

Solution code:
input()
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
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)
ali=0
bob=0
for i in range(len(a)):
  if i%2==0:
    ali+=a[i]
  else:
    bob+=a[i]
print(ali-bob)

Submission status: Accepted

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

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

print(alice_p - bob_p)

Submission status: Accepted

Solution code:
# ABC 088: B – Card Game for Two
n = int(input())
a = [int(s) for s in input().split()]

a.sort(reverse = True)

score_Alice = sum(a[0::2])
score_Bob = sum(a[1::2])

print(score_Alice - score_Bob)

Submission status: Accepted

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

Alice, Bob = 0, 0

for i in range(N):
  if i % 2 == 0:
    Alice += a.pop(a.index(max(a)))
  else:
    Bob += a.pop(a.index(max(a)))
    
ans = abs(Alice - Bob)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
a=list(map(int,input().split()))
A=0
B=0
for i in range(n):
    if i%2==0:
        A+=max(a)
        a.remove(max(a))
    else:
        B+=max(a)
        a.remove(max(a))
print(A-B)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    a = list(map(int, readline().split()))
    a = sorted(a)[::-1]

    A, B = 0, 0
    sa, sb = 0, 1
    for i in range(N):
        sa += (-1)**i
        sb += (-1)**(i+1)
        A += sa * a[i]
        B += sb * a[i]

    print(A-B)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
couA = 0
couB = 0
for i in range(0,len(a),2):
    couA +=a[i]
for j in range(1,len(a),2):
    couB +=a[j]
print(couA-couB)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Alis = 0
Bob = 0

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

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
list_a.sort(reverse=True)
list_alice = [a for i, a in enumerate(list_a) if i % 2 == 0]
list_bob = [a for i, a in enumerate(list_a) if i % 2 != 0]
print(sum(list_alice) - sum(list_bob))

Submission status: Accepted

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

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

Submission status: Accepted

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

print(s-d)

Submission status: Accepted

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

Submission status: Accepted

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

ascore = bscore = 0
for i in range(1, n+1):
    if i % 2 == 1:
        ascore += max(a)
    else:
        bscore += max(a)
    a.remove(max(a))
print(ascore - bscore)

Submission status: Accepted

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

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

def main():
    input()
    aa=list(map(int, input().split()))
    aa.sort(reverse=True)
    print(sum(aa[::2])-sum(aa[1::2]))

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-06 16:18:30(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    a.sort(reverse=1)
    alice, bob = 0, 0
    for i in range(n):
        if i % 2 == 0:
            alice += a[i]
        else:
            bob += a[i]
    ans = alice - bob
    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = list(map(lambda i: int(i), input().split()))
    a.sort()
    alice = []
    bob = []
    for i in range(len(a)):
        if i % 2 == 0:
            alice.append(a[len(a) - 1 - i])
        else:
            bob.append(a[len(a) - 1 - i])
    print(sum(alice) - sum(bob))

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    a.sort(reverse=True)

    A = 0
    B = 0

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

    print(A - B)

Submission status: Accepted

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

a.sort(reverse=True)

Alice = 0
Bob = 0

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

print("{}".format(Alice - Bob))

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())
a = [int(i) for i in input().split()]
junban = True
Alice = Bob = 0

while a:
    if junban:
        Alice += max(a)
        a.remove(max(a))
        junban = False
    else:
        Bob += max(a)
        a.remove(max(a))
        junban = True

print(Alice -Bob)

Submission status: Accepted

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

a.sort(reverse=True)

x=0
p_alice=0
p_bob=0

while (x < n):
    if(x%2==0):
        p_alice += a[x]
    else:
        p_bob += a[x]
    x+=1

print(p_alice-p_bob)

Submission status: Accepted

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

a.sort(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)
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 = 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 = sorted(A)
alice = 0
bob = 0
i = 0
for a in A[::-1]:
    if i%2==0: alice += a
    else: bob += a
    i+=1

print(alice-bob)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
A=many_int()

A=sorted(A,reverse=True)

Alice=A[::2]
Bob=A[1:][::2]

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

Submission status: Accepted

Solution code:
N = int(input())
a_list = [int(num) for num in input().split()]
a_list.sort(reverse=True)

alice = 0
bob = 0

for i, num in enumerate(a_list, 1):
  if i % 2:
    alice = alice + num
  else:
    bob = bob + num
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
alice, bob = 0, 0
while len(a) > 0:
    alice += max(a)
    a.remove(max(a))
    if len(a) > 0:
        bob += max(a)
        a.remove(max(a))
    else:
        break
ans = alice - bob
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(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 = 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(int(x) for x in input().split())
a_s = sorted(a, reverse = True)

al = 0
bo = 0
for i in range(n):
    if i % 2 == 0:
        al += a_s[i]
    else:
        bo += a_s[i]

print(al-bo)

Submission status: Accepted

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

print((Alice-Bob))