Problem:


Score: 200 points

Problem Statement

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

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:  

N
a_1 a_2 a_3 ... a_N

Output

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

Sample Input 1

2
3 1

Sample Output 1

2

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

Sample Input 2

3
2 7 4

Sample Output 2

5

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

Sample Input 3

4
20 18 2 18

Sample Output 3

18



Sample input:
2
3 1


Sample output:
2

Submission status: Accepted

Solution code:
#coding:utf-8

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

A_lis = sorted(A)
c = 1
score = 0

for i in range(N):
    n = A_lis.pop()
    if c%2 == 0:
        score -= n
    elif c%2 == 1:
        score += n
    c += 1

print(score)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.sort()
sum = 0
al = 0
s = 0
for i in range(n):
    sum+=li[n-i-1]
    if ((i%2)==0):
        al +=li[n-i-1]
s = al -(sum -al)
print(s)

Submission status: Accepted

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

a.sort()
a=a[::-1]

A=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())
data = list(map(int, input().split(' ')))
data.sort(reverse = True)
score = 0
is_Alices_turn = True

for data in data:
    if is_Alices_turn:
        score += data
    else:
        score -= data
    is_Alices_turn = not is_Alices_turn

print(score)

Submission status: Accepted

Solution code:
a = int(input())
b = [int(i) for i in (input().split())]
b.sort()
b.reverse()
sum = 0
for i in range(a):
    if i % 2 == 0:
        sum += b[i]
    else:
        sum -=b[i]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
list_x= list(map(int, input().split(' ')))
Alice, Bob= 0, 0
x = 0
for i in range(N):
    x = max(list_x)
    list_x.remove(x)
    if i % 2 == 0:
        Alice += x
    else:
        Bob += x
print(str(Alice - Bob))

Submission status: Accepted

Solution code:
n = input()
a = [int(i) for i in raw_input().split(" ")]
a.sort()
i = n - 1
x, y = 0, 0
k = 0
while i >= 0:
  if k == 0: x += a[i]
  else: y += a[i]
  i -= 1
  k = 1 - k
print x - y

Submission status: Accepted

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

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

AList.sort()
AList.reverse()

alice = 0
bob = 0

count = 0
for a in AList :
    if (count % 2) == 0 :
        alice += a
    else :
        bob += a
    count += 1

print(alice-bob)

Submission status: Accepted

Solution code:
def main():
    N = int(input().strip())
    A = [int(x) for x in input().strip().split()]
    A.sort(reverse=True)
    alice = sum(A[0::2])
    bob = sum(A[1::2])
    return alice - bob

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
a.sort()
a.reverse()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
N = input()
N = int(N)
l = input().split()
l = list(map(int, l))

if N != len(l):
    print('Error')
    sys.exit()
Alice = []
Bob = []

while len(l) > 0:
    if len(l) > 0:
        saidai = max(l)
        Alice.append(saidai)
        l.remove(saidai)
    if len(l) > 0:
        saidai = max(l)
        Bob.append(saidai)
        l.remove(saidai)

Alice_num = 0
for i in range(0, len(Alice)):
    Alice_num += Alice[i]
Bob_num = 0
for i in range(0, len(Bob)):
    Bob_num += Bob[i]
kekka = Alice_num - Bob_num
print(kekka)

Submission status: Accepted

Solution code:


def solve():
    N = int(raw_input())
    cards = map(int, raw_input().split())

    points = [0, 0]
    for i in xrange(N):
        max_point = max(cards)
        points[i % 2] += max_point
        cards.remove(max_point)

    print points[0] - points[1]

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort()
c=a[0::2]
e=sum(c)
d=a[1::2]
f=sum(d)
print(abs(f-e))

Submission status: Accepted

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

a.sort()
m = n % 2

alice = 0
bob = 0

while n > 0:
    if n % 2 == m:
        alice += a[-1]
    else:
        bob += a[-1]
    a.pop()
    n -= 1

print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = input().strip().split()
a = [ int(a[i]) for i in range(len(a)) ]

a.sort(reverse=True)

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

Submission status: Accepted

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

total_sum = sum(a_list)
a_list = sorted(a_list,reverse=True)

a_sum = 0
for i in range(0,len(a_list),2):
    a_sum += a_list[i]

print(a_sum - total_sum + a_sum)

Submission status: Accepted

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

sign = +1
diff = 0
for i in range(n):
  diff += sign * a[n - i - 1]
  sign *= -1

print(diff)

Submission status: Accepted

Solution code:
n=int(raw_input())
s=raw_input().split(' ')
l=[]
for i in range(0,n):
	l.append(int(s[i]))
l.sort()
l.reverse()
a=0
b=0
for i in range(0,n):
	if(i%2==0):
		a=a+l[i]
	else:
		b=b+l[i]

print a-b

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
sum_a = sum(a)
x_sum = 0
for x in range(0,len(a),2):
    x_sum += a[x]

y_sum = sum_a - x_sum

print(x_sum - y_sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
a = sorted(list(map(int, raw_input().split())), reverse=True)
print sum([a[i] for i in xrange(n) if not i % 2])-sum([a[i] for i in xrange(n) if i % 2])

Submission status: Accepted

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

b = sorted(a,reverse=True)
ans = sum([b[x] for x in range(N) if x % 2 ==0]) - sum([b[x] for x in range(N) if x % 2 ==1])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(abs(alice-bob))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

with sys.stdin as f:
    s_input = f.read()

    in_list = s_input.splitlines()
    n = int(in_list[0])
    a = in_list[1].split()
    a = [int(i) for i in a]

    a.sort(reverse=True)

    sc_a = 0
    sc_b = 0
    for alc in a[0::2]:
        sc_a += alc

    for bob in a[1::2]:
        sc_b += bob

    print(sc_a - sc_b)
        
sys.exit(0)

Submission status: Accepted

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

asum = 0
bsum = 0

for i in range(N) :
    ma = max(A)
    if i % 2 == 0:
        asum += ma
    else:
        bsum += ma
    A.remove(ma)

print(asum - bsum)

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-
#input number
num = int(input())
str = input()
#change to list distinguished by space
str_list = str.split()
#change list all item to "int"
list_up = list( map((lambda x:int(x)),str_list))

#arrange number from high number to low number
list_up.sort(reverse=True)
sum = 0
for (i, v) in enumerate(list_up):
  if(i % 2 == 0):
    sum += int(v)
  elif(i % 2 == 1):
    sum -= int(v)
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(k) for k in input().split()]
a.sort()
s=0
for i in range(len(a)):
    s+=(pow(-1,i)*a[len(a)-1-i])
print(abs(s))

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, n):
    if i % 2 == 1:
        Bob += a[i]
    else:
        Alice += a[i]
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0
flag = 0
for i in range(N):
    if flag == 0:
        alice += max(a)
        del a[a.index(max(a))]
        flag = 1
    else:
        bob += max(a)
        del a[a.index(max(a))]
        flag = 0

print(alice - bob)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

# 降順ソート
a.sort()
a.reverse()

tmp = int(len(a) / 2 + 0.5) - 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:
n = int(input())
a = list(map(int, input().split()))

def quicksort(array):
    if len(array) < 2:
        return(array)
    else:
        pivot = array[0]
        less = [i for i in array[1:] if i <= pivot]
        greater = [i for i in array[1:] if i > pivot]

        return quicksort(greater) + [pivot] + quicksort(less)


sorted_a = quicksort(a)
alice = []
bob = []
for i in range(len(sorted_a)):
    if i % 2 == 0:
        alice.append(sorted_a[i])
    else:
        bob.append(sorted_a[i])
print(sum(alice) - sum(bob))

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
o=0
zen = input()
#print(zen)
card = list(map(int,input().split()))
card1 = sorted(card)
#print(sorted(card1))
#print(int(int(zen)/2))
if int(zen)%2 == 0:
    for i in range(int(int(zen)/2)):
        o += int(card1[int(zen)-int(i)*2-1])-int(card1[int(zen)-int(i)*2-2])#        print(o)
#        print(o)    
#        print(card1[int(zen)-int(i)*2-2])
else:
    for i in range(int((int(zen)-1)/2)):
        o += int(card1[int(zen)-int(i)*2-1])-int(card1[int(zen)-int(i)*2-2])#        print(o)
    o += int(card1[0]) 
print(o)

Submission status: Accepted

Solution code:
N = int(input())
data = input().split()
data = data[:N]

for i in range(N):
	data[i] = int(data[i])

data.sort(reverse=True)

listA = []
listB = []
for i in range(N):
	if(i % 2 == 0):
		listA.append(data[i])
	else:
		listB.append(data[i])

print(sum(listA) - sum(listB))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = sorted(LI(), reverse=True)
    b = 0
    c = 0
    for i in range(n):
        if i % 2 == 0:
            b += a[i]
        else:
            c += a[i]

    return b - c


print(main())

Submission status: Accepted

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

l.sort()
l.reverse()
alice = sum(l[::2])
bob = sum(l[1::2])
print(alice - bob)

Submission status: Accepted

Solution code:
N=int(input()) 
a = list(map(int, input().split()))
sum=0
a.sort()
a.reverse()
if(N>2 and N%2 == 0):
  for i in range(0,N-1,2):
    sum=sum+a[i]-a[i+1]
if(N>2 and N%2 != 0):
  for i in range(0,N-1,2):
    sum=sum+a[i]-a[i+1]
  sum=sum+a[N-1]
elif(N==1):
  sum=a[0]
elif(N==2):
  sum=a[0]-a[1]
print(sum)

Submission status: Accepted

Solution code:
N=int(input())
A=input().split(" ")
A = list(map(int, A))
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.sort(reverse = True)
Alice = 0
Bob = 0
for i in range((n - 1) // 2 + 1):
    Alice = Alice + a[2 * i]
for i in range(n // 2):
    Bob = Bob + a[2 * i + 1]
gap = Alice - Bob
print(gap)

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(raw_input())
list = map(int,raw_input().split())
list = np.sort(list)[::-1]
list2 = np.array([1 if i % 2 == 0 else -1 for i in range(N)])
x = np.sum(list * list2)
print x

Submission status: Accepted

Solution code:
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    a_list = []
    input_raw = read_func().strip().split()
    for i in range(N):
       
        a_list.append(int(input_raw[i]))

    a_list.sort(reverse = True)

    alice_score = 0
    bob_score = 0
    for i in range(N):
        if i % 2 == 0:
            alice_score += a_list[i]
        else:
            bob_score += a_list[i]

    print alice_score - bob_score



if __name__ == '__main__':
    main()

Submission status: Accepted

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

revA = sorted(A, reverse=True)

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

print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
nS = [0 for i in range(N)]
nV = [0 for i in range(N)]
nS  = input().rstrip().split(' ')

for i in range(N):
    nV[i] = int(nS[i])

nV = sorted(nV, reverse = True)

nA = 0
nB = 0


for i in range(N):
    Tmp = i % 2
    if Tmp == 0:
        nA += nV[i]
    else:
        nB += nV[i]
        
Ans = nA - nB

print(Ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(raw_input())
a = map(int,raw_input().split())
a.sort()
a.reverse()
Bob = 0
Alice = 0
A = 0
B = 1
while A < N:
    Alice += a[A]
    A += 2
while B < N:
    Bob += a[B]
    B += 2
print Alice-Bob

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    card_count = int(input())

    card_numbers = [int(i) for i in input().split()]
    card_numbers.sort(reverse=True)

    alice_score = 0
    bob_score = 0

    alice_cards = card_numbers[::2]
    bob_cards = card_numbers[1::2]

    for i in range(len(alice_cards)):
        alice_score += alice_cards[i]

    for j in range(len(bob_cards)):
        bob_score += bob_cards[j]

    diff = alice_score - bob_score
    print(diff)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
aSum = 0
bSum = 0
ans = 0
cards = [int(x) for x in input().split()]

for j in range(1,n+1):
    if j % 2 == 1:
        aSum += max(cards)
        cards.remove(max(cards))
    else:
        bSum += max(cards)
        cards.remove(max(cards))
ans = aSum - bSum
print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    alice_sum = 0
    bob_sum = 0
    A.sort()
    A.reverse()
    for i in range(N):
        if i % 2 == 0:
            alice_sum += A[i]
        else:
            bob_sum += A[i]
    print(alice_sum - bob_sum)

Submission status: Accepted

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

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

print(Alice - Bob)

Submission status: Accepted

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

def main(N, a):
    alis_score = sum(a[0::2])
    bob_score = sum(a[1::2])

    print(alis_score - bob_score)

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

Submission status: Accepted

Solution code:
N = int(input()) # 入力数
L1 = input().split(" ")
# print(L1)
L2 = list(map(int, L1))
A = []
B = []


# print("modeB")
for n in range(N - 1):
    A.append(max(L2))
    L2.remove(max(L2))
    # print(A)
    if L2 == []:
        break
    B.append(max(L2))
    # print(B)
    L2.remove(max(L2))
    if L2 == []:
        break
    n += 1

# print(A, "f")
# print(B, "f")
PA = sum(A)
PB = sum(B)
print(PA - PB)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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 = []
astr = input().split()
for i in astr:
    a.append(int(i))

sorteda = sorted(a)

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

print(Alice-Bob)

Submission status: Accepted

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

alice = 0
bob = 0


while(N !=0) :
    
        
        maxa = max(a)
        max_index = a.index(max(a))
        del a[max_index]

        alice = alice + maxa
        N = N -1

        if (N == 0):
            break
    
        
        
        maxa = max(a)
        max_index = a.index(max(a))
        del a[max_index]

        bob = bob + maxa
        N = N -1

print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(_) for _ in 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()) 
card = [int(i) for i in input().split()] 
card.sort(reverse=True)
alice = 0
bob = 0
for i in range(0,N):
    if(i&1):
        #print(card[i])
        bob+=card[i]
    else:
        #print(card[i])
        alice+=card[i]
ans = alice - bob
print(ans)

Submission status: Accepted

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

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

A = 0
B = 0
if n%2 == 0:
    r = int(n/2)
    for i in range(0,r):
        A += max(a)
        a.remove(max(a))
        B += max(a)
        a.remove(max(a))
else:
    r = int(n/2)
    for i in range(0,r):
        A += max(a)
        a.remove(max(a))
        B += max(a)
        a.remove(max(a))
    A += max(a)

print(A-B)

Submission status: Accepted

Solution code:

def solve():
    n = int(input())
    a = map(int, input().split())

    a = sorted(a)[::-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)

solve()

Submission status: Accepted

Solution code:
n = input()
a = raw_input().split(' ')
b = []
for x in a:
    b.append(int(x))
b.sort()
b.reverse()
w = 0
f = 1
for x in b:
    if f == 1:
        w += x
    else:
        w -= x
    f = 1 - f
print w

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 x in range(n):
    if x % 2 == 0:
        alice += a[x]
    else:
        bob += a[x]

res = alice - bob
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

A,B =0,0

a.sort()

b = a[::-1]

S = math.floor(N/2)

if (N%2) == 0:
	for i in range (S):
		A = A + b[2*i]
		B = B + b[2*i+1]
else:
	for i in range (S):
		A = A + b[2*i]
		B = B + b[2*i+1]
	A = A + b[N-1]
print(A-B)

Submission status: Accepted

Solution code:
#金額
moto = int(input())
num   = int((moto + 1 ) / 2)
retu    = input().split()
card = list( map((lambda x:int(x)),retu))
cardList = sorted(card, reverse=True)
Alice = 0
Bob = 0

for w in range(num):
    Alice = Alice + cardList[w*2]
    if moto > (w*2+1):
        Bob = Bob + cardList[w*2+1]

print(Alice - Bob)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split(' ')))
A.sort()
a=0
b=0
i=0
while i < n:
    if i%2==0:
        a+= A[i]
    else:
        b += A[i]
    i += 1
print(abs(a-b))

Submission status: Accepted

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

Submission status: Accepted

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

ans = sum(a for a in A[::2]) - sum(a for a in A[1::2])

print(ans)

Submission status: Accepted

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

a.sort()
a.reverse()
b = []
c = []
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        c.append(a[i])
b_sum = 0
c_sum = 0
for i in b:
    b_sum += i
for i in c:
    c_sum += i

print(b_sum - c_sum)

Submission status: Accepted

Solution code:
N = int(input())
As = [int(n) for n in input().split()]

Alice = []
Bob = []

while len(As):
    ma = max(As)
    Alice.append(ma)
    As.remove(ma)
    if len(As):
        mb = max(As)
        Bob.append(mb)
        As.remove(mb)

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

Submission status: Accepted

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

print(a_sum-b_sum)

Submission status: Accepted

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

As.sort(reverse=True)

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

Submission status: Accepted

Solution code:
N = int(input())

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

a.sort(reverse=True)

ans = 0
tmp = 1
for ai in a:
    ans += tmp * ai
    tmp *= -1

print(ans)

Submission status: Accepted

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

a.sort()
while len(a) > 0:
    A += a.pop()

    if len(a) > 0:
        B += a.pop()

print(A-B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if((i % 2) == 0):
        alice += max(ls)
    else:
        bob += max(ls)
    ls[ls.index(max(ls))] = 0

out = alice - bob
print(out)

Submission status: Accepted

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

a.sort(reverse=True)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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


if __name__ == "__main__":
    n = int(input())
    a = input().split(" ")
    a_lst = []
    for i in range(n):
        a_lst.append(int(a[i]))
    a_lst.sort()
    a_lst.reverse()
    print(slove(n, a_lst))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    diff = 0
    for i, ai in enumerate(reversed(a)):
        if i % 2 == 0:
            diff += ai
        else:
            diff -= ai
    print(diff)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import numpy as np #1.11.0
#import matplotlib as plt #1.5.1
import copy 
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

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

cards = sorted(cards,reverse=True)
ali = 0
bob = 0
for i in range(maisu):
    if i%2 == 0:
        ali += cards[i]
    else:
        bob += cards[i]

print(str(ali-bob))

Submission status: Accepted

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

AL=0
BO=0

for i in range(N):
    if i%2==0:
        AL+=a.pop()
    else:
        BO+=a.pop()
print(AL-BO)

Submission status: Accepted

Solution code:

def main():
    N = int(input())
    S = list(map(int, input().split()))
    S = sorted(S, reverse=True)
    a = []
    b = []

    flg = 0
    for s in S:
        if flg == 0:
            a.append(s)
            flg = 1
        else:
            b.append(s)
            flg = 0

    print (sum(a) - sum(b))

if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Submission status: Accepted

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

print(abs(a-b))

Submission status: Accepted

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

alice = []
bob = []

while len(A) > 0:
    a = A.pop()
    alice.append(a)
    if len(A) > 0:
        b = A.pop()
        bob.append(b)
    

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

Submission status: Accepted

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
As = Is()
As.sort(reverse=True)
alice = As[::2]
bob = As[1::2]
print(sum(alice)-sum(bob))

Submission status: Accepted

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
a = 0
b = 0
d.sort()
for x in range(n):
    if(x%2==0):
        a+=d[n-1-x]
    else:
        b+=d[n-1-x]
print(str(a-b))

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))

a.sort()
a.reverse()

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

print(alice-bob)

Submission status: Accepted

Solution code:
N=input()
a=map(int,raw_input().split())
b=sorted(a, key=lambda x:x,reverse=True)
ans=0
for ind, i in enumerate(b):
	if ind%2==0:
		ans+=i
	else:
		ans-=i
print ans

Submission status: Accepted

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