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(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)
s,t=0,0
if len(a)%2==1:
    a.append(0)
for i in range((len(a)+1)//2):
    s+=a[2*i]
    t+=a[2*i+1]
print(s-t)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
Alice = 0
for i in range(0, n, 2):
    Alice += l[i]
Bob = sum(l) - Alice
print(abs(Bob - Alice))

Submission status: Accepted

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

a = 0
b = 0
for i in range(0,N,2):
  a += A[i]
for i in range(1,N,2):
  b += A[i]
print(a-b)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
Alice = 0
Bob = 0
for i in range(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 = a[::-1]
alice = 0
bob = 0
i = 0
while i < len(a):
    alice += a[i]
    i += 1
    if i >= len(a):
        break
    bob += a[i]
    i += 1
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num_list.sort()
num_list.reverse()

for i in range(N):
  if i==0:
    sum = num_list[0]
  elif i%2==0:
    sum = sum + num_list[i]
  else:
    sum = sum - num_list[i]

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()
sum_Alice = 0
sum_Bob = 0

for i in range(N):
  A[i] = int(A[i])
A.sort()
A.reverse()

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

Submission status: Accepted

Solution code:
N = input()
a = [ int(n) for n in input().split()]
a.sort(reverse=True)
A = B = 0
while len(a) > 0:
	A += a.pop(0)
	if len(a) < 1:
		break
	else:
		B += a.pop(0)
print(str(A-B))

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, key=lambda x: -x)
    a, b = 0, 0
    for i in range(N):
        if i % 2 == 0:
            a += A[i]
        else:
            b += A[i]
    print(a-b)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = 0
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
for i in range(N):
  S += a[::-1][i] * (-1) ** i
print(S)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
num = int(input())
input_str_list = input().split()
input_list = []
for i in input_str_list:
	input_list.append(int(i))
input_list.sort(reverse=True)

A = 0
B = 0
A_list = input_list[::2]
B_list = input_list[1::2]
for i in A_list:
	A += i
for i in B_list:
	B += i
print(A-B)

Submission status: Accepted

Solution code:
def calc(al,bo,a):
  if len(al)-len(bo) != 0:
    bo.append(a)
  else :
    al.append(a)
  return al,bo
    
N=int(input())
a=input().split()
a=[int(k) for k in a]
a.sort()

alice = []
bob = []

while(N!=0):
  alice,bob = calc(alice,bob,a[N-1])
  N -= 1
  
print(sum(alice)-sum(bob))

Submission status: Accepted

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

a.sort(reverse = True)

su = 0

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

Submission status: Accepted

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

alice = 0
bob = 0

for i in range((len(a) + 1 )// 2) :
    alice += max(a)
    a.remove(max(a))
    if len(a) != 0 :
        bob += max(a)
        a.remove(max(a))
print(alice - bob)

Submission status: Accepted

Solution code:
# coding: utf-8
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:
from sys import stdin

n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
a.sort()
a.reverse()

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())
l=list(map(int,input().split(" ")))
i=0
a=0
b=0

while len(l)!=0:
    if i%2==0:
        a+=max(l)
        l.remove(max(l))
    else:
        b+=max(l)
        l.remove(max(l))
    i+=1
print(a-b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()    #ソート

alice =[]
bob = []

i = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc088/tasks/abc088_b
n = int(input())
a = [int(x) for x in input().split()]
alice = 0
bob = 0
for i, v in enumerate(sorted(a, reverse=True)):
    if (i % 2 == 0):
        alice += v
    else:
        bob += v
print(alice - bob)

Submission status: Accepted

Solution code:
N = int(input())
score = list(map(int, input().split()))
score.sort()
score.reverse()
a = []
b = []
for i in range(N):
  if(i % 2 == 1):
    a.append(score[i])
  else:
    b.append(score[i])
             
print(sum(b) - sum(a))

Submission status: Accepted

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

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

print(alice - bob)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
n = int(input())
a = list(map(int, readline().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(str(alice-bob))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 27 21:41:45 2019

@author: yuta
"""

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

def main(a):
        card = sorted(a,reverse = True)
        Alice = sum(card[::2])
        Bob = sum(card[1::2])
        print(Alice - Bob)

main(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(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()))
Alice = []
Bob = []
while a != []:
    get = max(a)
    Alice.append(get)
    a.remove(get)
    if a != []:
        get = max(a)
        Bob.append(get)
        a.remove(get)
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[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=1)

ans=[0, 0]
p = 0
for i in range(n) :
    ans[p] += A[i]
    p = (p+1) % 2

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
side = 0 # alice
for game_time in range(n):
    max_card = max(a)
    max_index = a.index(max_card)
    del a[max_index]
    if side == 0:
        alice += max_card
        side = 1
    else:
        bob += max_card
        side = 0
print(alice-bob)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),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())
l = list(map(int, input().split()))
l.sort(reverse=True)
Alice = 0
Bob = 0
tf = 0
for i in l:
    if tf == 0:
        Alice += i
        tf = 1
    else:
        Bob += i
        tf = 0
ans = Alice - Bob
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

player_a=[]
player_b=[]

for i in range(len(a)):
	if(i==0 or i%2==0):
		player_a.append(a[i])
	else:
		player_b.append(a[i])

sum_a=sum(player_a)
sum_b=sum(player_b)

ans=sum_a-sum_b

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lis = input().split()
num_lis = [int(x) for x in lis]

def Turn(AB, l):
    m = max(l)
    AB += m
    l.remove(m)

    return (AB, l)

Alice = 0
Bob = 0

while num_lis:
    Alice, num_lis = Turn(Alice, num_lis)
    
    if num_lis:
        Bob, num_lis = Turn(Bob, num_lis)
    
print(Alice - Bob)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split());b=sorted(a,reverse=True)
c=len(b);print(sum(b[i]for i in range(0,c,2))-sum(b[i]for i in range(1,c,2)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
A = sorted(A)
Alice_card = []
Bob_card = []
for i in range(n):
        if i%2 == 0:
                Alice_card.append(A[i])
        else:
                Bob_card.append(A[i])
Alice_total = sum(Alice_card)
Bob_total = sum(Bob_card)
print(abs(Alice_total - Bob_total))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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(n):
    tmp=a.pop(a.index(max(a)))
    if(i%2==0):
        alice+=tmp
    else:
        bob+=tmp
print(alice-bob)

Submission status: Accepted

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

num.sort(reverse=True)

A = 0
B = 0
t=0
for i in num:
    if t%2==0:
        A+=int(i)
    else:
        B+=int(i)
    t+=1
print(A-B)

Submission status: Accepted

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

sa=0
sb=0

a=sorted(a,reverse=True)

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

print(sa-sb)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int,input().split()))
A = []
B = []
lsn = sorted(ls,reverse = True)

A = lsn[0::2]
B = lsn[1::2]
print(sum(A)-sum(B))

Submission status: Accepted

Solution code:
int_n = int(input())
int_array = list(map(int, input().split()))

int_array.sort(reverse=True)

alice = int_array[::2]

bob = int_array[1::2]

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)[::-1]
# print(A)
ans = sum(A[::2]) - sum(A[1::2])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=max(l)
        del l[l.index(max(l))]
    else:
        b+=max(l)
        del l[l.index(max(l))]
print(a-b)

Submission status: Accepted

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

Alice, Bob = 0, 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()))

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

Submission status: Accepted

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

N = int(input())
deck = list(map(int, input().split()))
Alice = 0
Bob = 0

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

print(Alice - Bob)

Submission status: Accepted

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

N = int(input())
deck = list(map(int, input().split()))
Alice = 0
Bob = 0

for i in range(len(deck)):
    if i % 2 == 0:
        Alice += deck.pop(deck.index(max(deck)))
    else:
        Bob += deck.pop(deck.index(max(deck)))

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
""" AtCoder """

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

a.sort(reverse = True)
f = 1
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("Three")
    else:print("Four")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())




n = ip()                              #入力整数1つ
#a,b= (int(i) for i in input().split())      #入力整数横2つ
#k,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
a.sort(reverse=True)
s = 0
for i in range(1,len(a),2):
    a[i]*=-1
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
a.reverse()
c = 0
d = 0
for i in range(0,len(a),2):
    c += a[i]
for j in range(1,len(a),2):
    d += a[j]
    
print(c-d)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
tuple=input()
list=tuple.split()
list_int=[int(i) for i in list]
list=sorted(list_int)
Alice_Score=0
Bob_Score=0
for num in list[-1::-2]:
    Alice_Score+=num
for num in list[-2::-2]:
    Bob_Score+=num
difference=Alice_Score-Bob_Score
print(difference)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
a = list(map(int, input().split()))
a.sort(reverse=True)
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())
cards=list(map(int,input().split()))
cards.sort(reverse=True)

Alice_score=0
Bob_score=0

isAliceTurn=True
for i in range(N):
    if(isAliceTurn):
        Alice_score+=cards.pop(0)
    else:
        Bob_score+=cards.pop(0)
    isAliceTurn = not isAliceTurn

print(Alice_score-Bob_score)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
alice = 0
bob = 0
a.sort()
f = 0
while(len(a) != 0):
    if f == 0:
        alice = alice + a.pop(-1)
        f = 1
    else:
        bob = bob + a.pop(-1)
        f = 0
print(alice - bob)

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:
# -*- coding: utf-8 -*-

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

a_list.sort()
a_list.reverse()

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

    if i + 1 < len(a_list):
        bob += a_list[i + 1]

print(alice - bob)

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

turn = 0
point = [0,0]
while A:
    t = max(A)
    A.remove(t)
    point[turn%2] += t
    turn += 1

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

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())
l = list(map(int,input().split()))
l.sort(reverse=True)
a = sum(l[::2])
b = sum(l[1::2])
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(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int, input().split()))
alice = []
bob = []
for i in range(N):
    max_card = cards.pop(cards.index(max(cards)))
    if i % 2 == 0:
        alice.append(max_card)
    else:
        bob.append(max_card)
print(sum(alice) - sum(bob))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    ai = list(map(int, input().split()))

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

Submission status: Accepted

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

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

result = alice - Bob
result = abs(result)

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
s=[0,0]
t=0
for c in sorted(map(int,input().split()),reverse=True):
  s[t]+=c
  t=not t
print(s[0]-s[1])

Submission status: Accepted

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

N = int(input())
a_arr = [int(i) for i in input().split()]
a_arr2 = sorted(a_arr, reverse=True)
Alice = []
Bob = []

for j in range(len(a_arr2)):
  if j % 2 == 0:
    Alice.append(a_arr2[j])
  else:
    Bob.append(a_arr2[j])

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

Submission status: Accepted

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


sorted_a = sorted(a,reverse=True)

bob=0
alice=0

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

print(alice-bob)

Submission status: Accepted

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

a.sort()

suma, sumb = 0, 0
for i in range(n):
  if n % 2 != 0:
    if i % 2 == 0:
      suma += a[i]
    elif i % 2 != 0:
      sumb += a[i]
  elif n % 2 == 0:
    if i % 2 == 0:
      sumb += a[i]
    elif i % 2 != 0:
      suma += a[i]
      
print(suma - sumb)

Submission status: Accepted

Solution code:
N = input()

data = map(int,raw_input().split())

data.sort(reverse=True)

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

print ans

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
cards = list(map(int,input().split()))

cards.sort(reverse=True)

sum = 0
sum += np.sum(cards[0::2])
sum -= np.sum(cards[1::2])
print(sum)

Submission status: Accepted

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


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

Submission status: Accepted

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

a.sort(reverse=True)

alice = sum([s for idx,s in enumerate(a) if idx%2==0])
bob   = sum([s for idx,s in enumerate(a) if idx%2==1])

print(alice-bob)

Submission status: Accepted

Solution code:
# ABC 088
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
a = getIntList()
a.sort()
a.reverse()
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())
card = list(map(int, input().split()))
card.sort(reverse = True)

A = 0
B = 0

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

print(A - B)

Submission status: Accepted

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

A = 0
B = 0

for i in range(1, N+1):
    if i % 2 == 1:
        A += card[i-1]
    else:
        B += card[i-1]

print(A -B)

Submission status: Accepted

Solution code:
N = int(input())
alice = []
bob = []
L = sorted(list(map(int, input().split())))[::-1]
for i in range(N):
  if i%2==0:
    alice.append(L[i])
  else:
    bob.append(L[i])
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[0::2]) - sum(A[1::2]))

Submission status: Accepted

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

sorted_list = sorted(a,reverse = True)

Alice,Bob = 0,0 #アリスとボブの点数の宣言

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

ans = Alice - Bob
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

alice_score = 0
bob_score = 0

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

print(alice_score - bob_score)

Submission status: Accepted

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

    alice = 0
    bob = 0

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

    print(alice - bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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