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.sort()
A=[]
B=[]
while(len(a)>0):
    A.append(a.pop())
    if len(a)==0: break
    B.append(a.pop())
print(sum(A)-sum(B))

Submission status: Accepted

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

alice=[]
bob=[]

if len(cards)%2==0:
    while len(cards)>1:
        alice.append(cards[0])
        del cards[0]
        bob.append(cards[0])
        del cards[0]
else:
    while len(cards)>1:
        alice.append(cards[0])
        del cards[0]
        bob.append(cards[0])
        del cards[0]

    alice.append(cards[0])

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
as_ = np.sort(np.array([int(a) for a in input().split()]))[::-1]

print("%d" % (np.sum(as_[0::2]) - np.sum(as_[1::2])))

Submission status: Accepted

Solution code:
N = int(input())
itemList = input().split(' ')
hoge = []
for i in itemList:
    hoge.append(int(i))
hoge.sort()
hoge.reverse()

A = 0
B = 0

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

print(A-B)

Submission status: Accepted

Solution code:
import random
import numpy
import sys

N=int(input()) #枚数
A = list(map(int, input().split(" ")))#カードのリスト

alice = []
bob = []
while not len(A)==0:
  A = sorted(A,reverse=True)
  alice.append(A.pop(0))
  if len(A)==0:
    break
  bob.append(A.pop(0))
print(sum(alice)-sum(bob))

Submission status: Accepted

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

#
alice = 0
bob = 0
for i in range(N//2):
    alice += A[i*2]
    bob += A[i*2 + 1]
if N%2!=0:
    alice += A[-1]

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

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-
import numpy as np

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

list.sort(A)

Alice=0


for i in range(len(A)):
    try:
        Alice+=A[-1-2*i] 
    except:
        pass

print(Alice-(sum(A)-Alice))

Submission status: Accepted

Solution code:
N = int(input())

ai = input().split()

ai = list(map(int,ai))

ai.sort(reverse=True)

sum1 = 0;
sum2 = 0;

for i in range(N):
	if i%2 == 1:
		sum2+=ai[i]
	else:
		sum1 +=ai[i]

print(sum1-sum2)

Submission status: Accepted

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

a.sort(reverse=True)
res = 0
s = 1
for d in a:
  res += s * d
  s *= -1

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()], reverse=True)
print(sum([v for k,v in enumerate(a) if k % 2 == 0]) - sum([v for k,v in enumerate(a) if k % 2 != 0]))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n = int(sys.stdin.readline())
    a = sorted(map(int, sys.stdin.readline().split()), reverse=True)
    s = [[], []]
    for i, b in enumerate(a):
        s[i % 2].append(b)
    print(sum(s[0]) - sum(s[1]))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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:
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
div = 0

for i in range(N):
    div += ((-1)**i) * A[i]

print(div)

Submission status: Accepted

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

a.sort(reverse=True)

al = 0
bo = 0

if N % 2 == 1:
	N -= 1
	al += a[-1]

for i in range(0,N,2):
	al += a[i]
	bo += a[i+1]

print(al-bo)

Submission status: Accepted

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

cards.sort(reverse=True)
cards
Alice,Bob = 0,0
flg = 0

while len(cards) != 0:
    if flg == 0: 
        Alice += cards.pop(0)
        flg = 1
    else:
        Bob += cards.pop(0)
        flg = 0
print(Alice-Bob)

Submission status: Accepted

Solution code:
from math import ceil
n = int(input())
a = map(int, input().split())
a = sorted(a,reverse=True)
ans = 0
for i,j in enumerate(a):
    if i % 2 == 0: ans += j
    else: ans -= j
print(ans)

Submission status: Accepted

Solution code:
def B_Card_Game_for_Two():
    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))

B_Card_Game_for_Two()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

alice, bob = 0, 0
for i, a in enumerate(A):
    if i & 1:
        bob += a
    else:
        alice += a

print(alice-bob)

Submission status: Accepted

Solution code:
# coding=utf-8

N = int(input())
a = []

for x in input().split(" "):
    a.append(int(x))

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)
A = 0
B = 0

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

print(A-B)

Submission status: Accepted

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

diff = 0

for idx, i in enumerate(cards):
	if idx % 2 == 0:
		diff += i
	else:
		diff -= i

print(diff)

Submission status: Accepted

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

l = list(reversed(sorted(a)))

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

print(alice-bob)

Submission status: Accepted

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

list_a = sorted(list_a, reverse=True)

Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__=='__main__':
    N = int(input())
    a = list(map(int, input().split(' ')))
    a.sort()
    a = a[::-1]

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

    print(sum(Alice)-sum(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:
n = input()
cards = list(map(int, input().split()))
cards.sort(reverse = True)

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

print(alice-bob)

Submission status: Accepted

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

alice = 0
bob = 0
c = 0
while len(a) > 0:
    m = max(a)
    i = a.index(m)
    a.pop(i)
    if c % 2 == 0:
        alice += m
    else:
        bob += m
    c += 1

print(alice - bob)

Submission status: Accepted

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

A = 0
B = 0
i = 0
while len(a) > 0:
    if i % 2 == 0:
        A += a.pop()
    else:
        B += a.pop()
    i += 1
print(A - B)

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): #合計N回引く
    if i%2 == 0:#偶数回＝Alice
        alice += max(a)
        del a[-1]
    else:
        bob += max(a)
        del a[-1]
print(alice - bob)

Submission status: Accepted

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

for i in range(n):
    if(alice_flag):
        alice += max(a)
    else:
        bob += max(a)
    a[a.index(max(a))] = 0
    alice_flag = not(alice_flag)

print(alice-bob)

Submission status: Accepted

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

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())
A=[int(x) for x in input().split()]

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

Submission status: Accepted

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

print(main())

Submission status: Accepted

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

n = int(input())
a = [int(s) for s in input().split(" ")]
a.sort()
alice = sum(a[-1::-2])
bob = sum(a[-2::-2])

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

AS = sorted(A,reverse=True)
ans = 0
for i in range(len(AS)):
    if(i%2==0):
        ans += AS[i]
    else:
        ans -= AS[i]

print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
p = [0, 0]
for i in range(n):
    p[i%2]  += a[np.argmax(a)]
    a[np.argmax(a)] = 0
print(p[0]-p[1])

Submission status: Accepted

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

    A.sort(reverse=True)
    alice = [A[i] for i in range(N) if not i & 1]
    bob = [A[i] for i in range(N) if i & 1]

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

main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
flag = 0
alice = 0
bob = 0
for i in a:
    if flag == 0:
        alice += i
        flag = 1
    else:
        bob += i
        flag = 0
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: UTF-8
#@document_it
from collections import deque
def document_it(func):
    def new_function(*args,**kwargs):
        print('Running function:', func.__name__)
        print('Positional arguments:', args)
        print('Kewword arguments:', kwargs)
        result = func(*args,**kwargs)
        print('Result:', result)
        return result
    return new_function


def exe():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    s = deque(A)
    alice =0
    bob = 0
    for i in range(N):
        if i % 2 == 0:
            alice += s.pop()
        else:
            bob += s.pop()
    print(alice-bob)

if __name__ == '__main__':
    exe()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://abc088.contest.atcoder.jp/tasks/abc088_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(cards):
    score_a = 0
    score_b = 0
    cards.sort(reverse=True)
    for i, c in enumerate(cards):
        if i % 2 == 0:
            score_a += c
        else:
            score_b += c
    return score_a - score_b


def main(args):
    N = int(input())
    cards = [int(x) for x in input().split()]
    ans = solve(cards)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().split())
a.sort()
ct = 0

alice = 0
bob = 0
for i in reversed(a):
    if ct % 2 == 0:
        alice += i
    else:
        bob += i
    ct += 1

print alice - bob

Submission status: Accepted

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

a_s = sorted(a_s)

alice = 0
bob = 0
for i in range(N):
    if i % 2 == 0:
        alice += a_s.pop()
    else:
        bob += a_s.pop()

print(alice-bob)

Submission status: Accepted

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

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

Submission status: Accepted

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

Alice = []
Bob = []
a.sort()
a.reverse()

for x in range(N):
    if x % 2 == 0:
        Alice.append(a[x])
    else:
        Bob.append(a[x])

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    x, y = 0, 0
    for i, z in enumerate(sorted(a)):
        if i % 2 == (n-1) % 2:
            x += z
        else:
            y += z
    print(x - y)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=0
d=0
a.sort()
e=len(a)-1
f=0
while(e>=0):
	if(f==0):
		c+=a[e]
		f=1
	elif(f==1):
		d+=a[e]
		f=0
	e-=1
print(c-d)

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort(reverse=True)
a.append(0)

for i in range(0, n, 2):
    ans += a[i] - a[i + 1]

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 0
a.sort()
a.reverse()
for i in xrange(n):
 if i%2:
  ans -=a[i] 
 else:
  ans+=a[i]
print ans

Submission status: Accepted

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

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

    ans = alice - bob
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
al=[]
bo=[]
a=sorted(a)
a=a[::-1]
for i in range(n):
 if i%2==0:
  al.append(a[i])
 else:
  bo.append(a[i])
print(sum(al)-sum(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())
A = sorted(map(int, input().split()))[::-1]
ans = 0
for i, ai in enumerate(A):
    if i % 2:
        ans -= ai
    else:
        ans += ai
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
flag=0
A=0
B=0
for i in a:
  if flag==0:
    A+=i
    flag=1
  else:
    B+=i
    flag=0
print(A-B)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
s = sum(a)
sa = sum(a[::2])
print(2*sa-s)

Submission status: Accepted

Solution code:
# B

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

alice = 0
bob = 0
flag = 0
while len(A):
    i = A.index(max(A))
    if flag == 0:
        alice += A[i]
        flag = 1
        del A[i]
    else:
        bob += A[i]
        flag = 0
        del A[i]

print(alice - bob)

Submission status: Accepted

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

n_a = 0
n_b = 0
for i, x in enumerate(A_LIST):
    if i % 2 == 0:
        n_a += x
    else:
        n_b += x
        
print(n_a - n_b)

Submission status: Accepted

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

s=0

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

print(s)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a= sorted(a)
alice = sum(a[::2])
bob = sum(a[1::2])

print(abs(alice-bob))

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in 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:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N = int(input())
A = sorted(inpl(), 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()
a.reverse()

ans1=0
ans2=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(raw_input())
N=(sorted(map(int,raw_input().split())))
N.reverse()
a=b=0
for i in range(n):
	if i%2==0:
		a+=N[i]
	else:
		b+=N[i]
print abs(a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()
a = map(int, raw_input().split())
a.sort(reverse=True)
s1 = 0
s2 = 0
for i, k in enumerate(a):
    if i % 2 == 0:
        s1 += k
    else:
        s2 += k
print s1 - s2

Submission status: Accepted

Solution code:
N = int(input())
a = [int(_) for _ in 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 = sorted(a, reverse=True)
A, B = 0, 0
for i in range(N):
    if i % 2 == 0:
        A += a[i]
    else:
        B += a[i]

print(A - B)

Submission status: Accepted

Solution code:
N = int(input())

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

a = b = 0
for i,v in enumerate(src):
    if i%2 == 0:
        a += v
    else:
        b += v
print(a - b)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
s = 1
for x in xs:
  ans += s * x
  s *= -1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
f = lambda :[int(i) for i in input().split()]

N = int(input())
a = f()

a.sort()
alice = 0
bob = 0
while a:
    alice += a.pop()
    if not(a):
        break
    bob += a.pop()
print(alice - bob)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""

# --------------------------------------------

dp = None

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

    Alice = 0
    Bob = 0

    while len(A) != 0:
        Alice += max(A)
        A.remove(max(A))

        if len(A) == 0:
            break

        Bob += max(A)
        A.remove(max(A))

    print(Alice - Bob)

main()

Submission status: Accepted

Solution code:
N = input()
A = map(int, raw_input().split())
A.sort(key=lambda x:-x)

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

print a - b

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def sort_reverse(n):
    n.sort(reverse=True)
    return n

N_Even = list(range(0, N+1, 2))
N_Odd = list(range(1, N+1, 2))
a1 = sort_reverse(a)
sum1 = 0
sum2 = 0

for i in N_Even:
    sum1 += a1[i]
for j in N_Odd:
    sum2 += a1[j]

print(sum1 - sum2)

Submission status: Runtime Error

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

def sort_reverse(n):
    n.sort(reverse=True)
    return n

N_Even = list(range(0, N+1, 2))
N_Odd = list(range(1, N+1, 2))
a1 = sort_reverse(a)
sum1 = 0
sum2 = 0

for i in N_Even:
    sum1 += a1[i]
for j in N_Odd:
    sum2 += a1[i]

print(sum1 - sum2)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    n = int(input())
    a = input().split()

    bob = 0
    alice = 0
    sort_a = sorted(a, reverse=True)
    count = 0
    for m in sort_a:
        if m % 2 == 0:
            alice = alice + int(m)
        else:
            bob = bob + int(m)

    print(alice - bob)

Submission status: Runtime Error

Solution code:
N = input()
A = list(input().split())
A = list(map(int,A))
A = sorted(A,reverse = True)
a = 0
b = 0
while len(A) != 0 :
  a += A.pop(0)
  b += A.pop(0)
print(a-b)

Submission status: Runtime Error

Solution code:
N = int(input())

li = [int(input()) for i in range(N)]
li.sort()

A = sum([li[i] for i in range(len(li)) if i % 2 == 0])
B = sum(li) - A

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int N;
  cin >> N;
	vector<int> a(N);
	rep(i,N) cin>>a[i];
	sort(a.rbegin(),a.rend());
	long int ans=0;
	rep(i,N){
	  if (i%2==0)ans+=a[i];
	  else ans-=a[i];
	}
	cout << ans << "\n";
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(int,input().split())
al=[a[2*i] for i in range(n//2)]
bo=[a[2*i+1] for i in range(n//2)]
print(sum(al)-sum(bo))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

nums.sort()
while nums:
    alice+=nums.pop()
    bob+=nums.pop()

print(alice-bob)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [map(int, input().split()) for _ in range(N)]
a = sorted(a)[::-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: Runtime Error

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

Submission status: Runtime Error

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

if n%2 != 0:
  a.append(0)
  n += 1
 
a.sort()
d = 0

for i in range(int(n/2):
               d += a[2*i+1]-a[2*i]
           
print(d)

Submission status: Runtime Error

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

if n%2 != 0:
  a.append(0)
  n += 1
 
a.sort()
d = 0

for i in range(int(n/2):
               d += a[2i+1]-a[2i]
           
print(d)

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(map(int, input().split()))
if len(a)%2 !=0:
  a.append(0)
  
a.sort()
d = 0

for i in range(n/2):
  d += a[2i+1] - a[2i]
 
print(d)

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(map(int, input().split()))
if len(a)%2 !=0:
  a.append(0)
  
a.sort()
d = 0

for i in range(n/2):
  d += a[2i+1] - a[2i]
 
pritn(d)

Submission status: Runtime Error

Solution code:
#  ABC 088 B - Card Game for Two
N = int(input())
an = list(map(int, input().split()))

Alice = []
Bob = []
while len(an) > 0:
    Alice.append(max(an))
    del an[an.index(max(an))]
    Bob.append(max(an))
    del an[an.index(max(an))]

k = 0
j = 0
for i in range(len(Alice)):
    k += Alice[i]
for i in range(len(Bob)):
    j += Bob[i]

print(str(k-j))

Submission status: Runtime Error

Solution code:
n=int(input())
A=[int(x) for x in input().split()]
B=sorted(A)
Alice=[]
Bob=[]
while len(B)!=0 or len(B)!=1:
  Alice.append(B[-1])
  B.pop()
  Bob.append(B[-1])
  B.pop()
if len(B)==1:
  Alice.append(B[0])
  B.pop()
print(sum(Alice)-sum(Bob))

Submission status: Runtime Error

Solution code:
n=int(input())
A=[int(x) for x in input().split()]
B=sorted(A)
Alice=[]
Bob=[]
while len(B)!=0 or len(B)!=1:
  Alice.append(B[-1])
  B.pop()
  Bob.append(B[1-])
  B.pop()
if len(B)==1:
  Alice.append(B[0])
  B.pop()
print(sum(Alice)-sum(Bob))

Submission status: Runtime Error

Solution code:
n,*t=map(int,open(0).read().split())
print(sum([i*(-1)**i for i in t])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.reverse(key=int)
Ali=0
Bob=0
for i in range(n):
	if i%2==0:
       Ali+=a[i]
	else:
       Bob+=a[i]
ans(Ali-Bob)

Submission status: Runtime Error

Solution code:
n,s = int(raw_input()),map(int,raw_input().split())
s.sort(key = x:-x)
print sum(s[0:n:2]) - sum(s[1:n:2])

Submission status: Runtime Error

Solution code:
n,s = int(raw_input()),map(int,raw_input().split())
s.sort(key = x:-x)
print sum(s[1:n:2]) - sum(s[2:n:2])

Submission status: Runtime Error

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

alice = 0
bob = 0

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

print(alice - bob)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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