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: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort(reverse=True)

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

print(ret)

Submission status: Wrong Answer

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

a.sort()

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

print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

S=0
N = int(input())
l = map(int, input().split())

l = list(sorted(l))

for i in range(1, N+1):
    print(i)
    if i%2 == 1:
        S+=l[N-i]
        #print(S)
    else:
        S-=l[N-i]
        #print(S)
            

#print('--------')
print(S)

Submission status: Wrong Answer

Solution code:

B=0
A=0
N = int(input())
l = map(int, input().split())

l = list(sorted(l))
#print(l)
for i in range(1, N):
    B+=l[N-i]
    A+=l[N-i-1]

    
print(B-A)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split(' ')

def choice(a):
    x=max(a)
    a.remove(max(a))
    return x
    
alice=0
bob=0

while len(a)!=0:
    alice+=int(choice(a))
    if len(a)==0:
        break
    bob+=int(choice(a))
    
print(alice-bob)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a = [int(i) for i in input().split()] 
a.sort()
p1=a[0:N:2]
p2=a[1:N:2]
sum1=0
sum2=0
for i in p1:
	sum1+=i
for i in p2:
	sum2+=i

print(sum1-sum2)

Submission status: Wrong Answer

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

alice = []
bob = []
for i in range(1, n):
    val = max(card)
    del card[card.index(val)]
    if i % 2 == 1:
        alice.append(val)
    else:
        bob.append(val)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = input().split()
alist = sorted(alist, reverse=True)
count = 1
alice = 0
bob = 0

for a in alist:
    if count % 2:
        alice += int(a)
    else:
        bob += int(a)
    count = count + 1
print(alice - bob)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = input().split()
alist = sorted(alist, reverse=True)
count = 1
alice = 0
bob = 0

for a in alist:
    if count % 2:
        alice += int(a)
    else:
        bob += int(a)
    count+=1
print(alice - bob)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = input().split()
alist = sorted(alist, reverse=True)
count = 0
alice = 0
bob = 0

for a in alist:
    if count % 2:
        alice += int(a)
    else:
        bob += int(a)
    count+=1
print(alice - bob)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = input().split()
alist = sorted(alist, reverse=True)
print(alist)
count = 1
alice = 0
bob = 0

for a in alist:
    if count % 2:
        alice += int(a)
    else:
        bob += int(a)
    count+=1
print(alice - bob)

Submission status: Wrong Answer

Solution code:
N = int(input("Input N: "))
a = input("Input numbers(length={}): ".format(N)).split()
a = [int(i) for i in a]

a_sorted = sorted(a,reverse=True)
Total = sum(a_sorted)
A = sum(a_sorted[i] for i in range(0,len(a_sorted),2))
B = Total - A

print(A - B)

Submission status: Wrong Answer

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

a.sort()
a.reverse()
print(a)

Alice = 0
Bob  = 0

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

print(Alice - Bob)

Submission status: Wrong Answer

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

a.sort()

Alice = 0
Bob  = 0

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

print(Alice - Bob)

Submission status: Wrong Answer

Solution code:
#ABC088B

n=int(raw_input())
a=map(int,raw_input().split())
b=sorted(a,reverse=True)
print b
al=0
bo=0
for i in xrange(n):
 if i%2==0:
  al+=b[i]
 else:
  bo+=b[i]
print al-bo

Submission status: Wrong Answer

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

l.sort()
l.reverse()

result = 0

for e in enumerate(l):
    result += e[1] if e[0] % 2 else -e[1]

print(result)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a=sorted(a,reverse=True)
alice=bob=0
for i in range(N):
    if i%2==0:
        alice=alice+int(a[i])
        print("alice"+a[i])
    else:
        bob=bob+int(a[i])
print(alice-bob)

Submission status: Wrong Answer

Solution code:

N=int(input())
a=input().split()

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

Submission status: Wrong Answer

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]
sumn-summ

Submission status: Wrong Answer

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

tmp_lst1=input_lines.split()
tmp_lst2=list(map(int,tmp_lst1))
tmp_lst2.sort()
tmp_lst2.reverse()
#print(tmp_lst2)

alice=0
bob=0
for i in tmp_lst2:
    if tmp_lst2.index(i)%2==0:
        alice=alice+i
    else:
        bob=bob+i

sub=alice-bob
print(sub)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#input number
num = int(input())
str = input()
#change to list distinguished by space
list = str.split()

#arrange number from high number to low number
list.sort(reverse=True)

sum = 0
for (i, v) in enumerate(list):
  if i == num:
    break
  else:
    if(i % 2 == 0):
      sum += int(v)
    elif(i % 2 == 1):
      sum -= int(v)
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#-*-cording:utf-8-*-
N = int(input())
A = input().split()
A.sort()
A.reverse()
a=list(map(int,A))
Alice = a[0::2]
Bob = a[1::2]
allA=sum(Alice)
allB=sum(Bob)
Ans=allA-allB
print(Ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#input number
num = int(input())
str = input()
#change to list distinguished by space
list = str.split()

#arrange number from high number to low number
list.sort(reverse=True)

sum = 0
for (i, v) in enumerate(list):
  if(i % 2 == 0):
    sum += int(v)
  elif(i % 2 == 1):
    sum -= int(v)
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(map(int,input().split()))
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: Wrong Answer

Solution code:
#-*-cording:utf-8-*-
N = int(input())
A = input().split()
A.sort()
A.reverse()
print(A)
a=list(map(int,A))
Alice = a[1::2]
Bob = a[0::2]
allA=sum(Alice)
allB=sum(Bob)
Ans=allB-allA
print(Ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#-*-cording:utf-8-*-
N = int(input())
A = input().split()
A.sort()
A.reverse()
a=list(map(int,A))
Alice = a[1::2]
Bob = a[0::2]
allA=sum(Alice)
allB=sum(Bob)
Ans=allA-allB
print(-Ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split(" ")))
# A.sort()
A = sorted(A,reverse=True)
print(A)
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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=sorted(a)
m=int((n+1)//2)
s=0
for i in range(m):
  s+=b[2*i]
print(s)

Submission status: Wrong Answer

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

print(abs(a-b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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: Wrong Answer

Solution code:
N = int(input())
itemList = input().split(' ')
itemList.sort()
itemList.reverse()

A = 0
B = 0

for i in range(0, len(itemList)):
    if i % 2 == 0:
        A += int(itemList[i])
    else:
        B += int(itemList[i])

print(A-B)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = 0
b = 0
while True:
    if len(A) >= 2:
        a = a + max(A)
        A.remove(max(A))
        b = b + max(A)
        A.remove(max(A))
    elif len(A) == 1:
        a = a + A[0]
    else:
        break
print(a-b)

Submission status: Accepted

Solution code:
n=int(input())
n_list=list(map(int,input().split()))
alice=[]
bob=[]
while(n_list!=[]):
    a=max(n_list)
    alice.append(a)
    n_list.remove(a)
    if(n_list==[]):
        break
    b=max(n_list)
    bob.append(b)
    n_list.remove(b)
print(sum(alice)-sum(bob))

Submission status: Accepted

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

alice=0
bob=0

lst.sort()
for i in range(n):
    if i%2==0 :
        alice+=lst.pop()
    else :
        bob+=lst.pop()
print(alice-bob)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
Alice = 0
Bob = 0
while 1:
    try:
        Alice += A.pop(-1)
    except IndexError:
        break
    try:
        Bob += A.pop(-1)
    except IndexError:
        break
print(Alice-Bob)

Submission status: Accepted

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

a.sort(reverse=True)

ans = 0

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

  
print(ans)

Submission status: Accepted

Solution code:
from typing import List


def answer(n: int, a: List[int]) -> int:
    alice = 0
    bob = 0

    a.sort(reverse=True)
    for i in range(0, len(a), 2):
        alice += a[i]
    for j in range(1, len(a), 2):
        bob += a[j]

    return abs(alice - bob)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    print(answer(n,a))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():

    n = int(input())
    cards = list(map(int, input().split()))
    cards.sort(reverse=True)
    alice, bob = 0, 0
    if n % 2 == 0:
        for i in range(int(n / 2)):
            alice += cards[2 * i]
            bob += cards[2 * i + 1]
    else:
        for j in range(int(n / 2)):
            alice += cards[2 * j]
            bob += cards[2 * j + 1]
        alice += cards[n - 1]
    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(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:
def solve1(n, lst):
    alice, bob = 0, 0

    #print(" i |a[i]|Alice|Bob")
    # print("------------------")

    for i in range(n):
        if i % 2 == 0:
            alice += lst[i]
        else:
            bob += lst[i]
        # print(f"{i:3d}|{a[i]:3d}|{alice:5d}|{bob:5d}")

    return alice - bob


n = int(input())
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
print(solve1(n, a))

Submission status: Accepted

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

Submission status: Accepted

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

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

a.sort(reverse=True)
alice=0
bob=0
tf=True
for i in a:
    if tf:
        alice+=i
    else:
        bob+=i
    tf=not tf
print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
a=list(map(int, input().split()))
a.sort()
A = []
B = []
for i in range(1,n+1):
    if i % 2 != 0:
        A.append(a[-i])
    else:
        B.append(a[-i])
print(sum(A) - sum(B))

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]

diff = A - B
print(diff)

Submission status: Accepted

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

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())
lst = input().split()

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

Alice = 0
Bob = 0

for i in range(N // 2):
   Alice += lst[2 * i]
   Bob += lst[(2 * i) + 1]

if N % 2 == 1:
   Alice += lst[-1]

print(Alice - Bob)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
a = LI()

# n枚のカードでaとbが勝負。
# i番目のカードにはaiの整数が書かれている。
# それぞれ1枚ずつカードをとる。aが先行してカードをとる。
# 2人がすべてのカードをとったときゲーム終了、合計数がそれぞれの特典。
# 二人とも自分の特典を最大化するとき、AがBより何点多く取るか。
# つまりカードが見えている。

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())
card_list=list(map(int,input().split()))
#各自が自分の数字を最大化するように選択するのが前提なのでAliceが確実に勝つ。
#Aliceは１番目、３番目、５番目、７番目・・・に取っていく
#Bobは２番目、４番目、６番目、８番目・・・に取っていく
#sort関数には、「reverse」という引数が存在します。reverseをTrueに指定することで「降順」を示すことになります。

card_list.sort(reverse=True)
#print(card_list)

card_list_Alice=card_list[::2]
#print(card_list_Alice)
Alice_score=sum(card_list_Alice)
#print(Alice_score)
Bob_score=sum(card_list)-Alice_score
#print(Bob_score)
#Alice_score=card_list[1]+card_list[3]+
#Bob_score=card_list[2]+card_list[4]+

print(Alice_score-Bob_score)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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))
    if len(A) == 0:
        break

print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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, 2))
N_Odd = list(range(1, N, 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: Accepted

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

a_sort = sorted(a, reverse=True)

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

print(alice-bob)

Submission status: Accepted

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

a = 0
b = 0
x = sorted(x)

for i in range(n):
    if i % 2 == 0:
        a += x.pop()
    else:
        b += x.pop()

print(a-b)

Submission status: Accepted

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

while True:
    Alice += a[count]
    count += 1
    if count == n:
        print(Alice - Bob)
        exit()
    Bob += a[count]
    count += 1
    if count == n:
        print(Alice - Bob)
        exit()

Submission status: Accepted

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

# Sort arr, firstly
arr.sort(reverse=True)

a_arr = []
b_arr = []

for (i, ele) in enumerate(arr):
    # Alice
    if i % 2 == 0:
        a_arr.append(ele)
    # Bob
    else:
        b_arr.append(ele)

print(sum(a_arr) - sum(b_arr))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc088/tasks/abc088_b

_ = int(input())
A = sorted(list(map(int, input().split())))[::-1]

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

print(ans)

Submission status: Accepted

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


def solve(N: int, a: "List[int]"):
    a = list(reversed(sorted(a)))
    alice = [a_[1] for a_ in enumerate(a) if a_[0] % 2 == 0]
    bob = [a_[1] for a_ in enumerate(a) if a_[0] % 2 == 1]
    # print(alice, bob)
    print(sum(alice) - sum(bob))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
num = len(a)
alice = []
bob = []
coun = 1
for i in a:
    if coun % 2 == 1:
        alice.append(i)
    else:
        bob.append(i)
    coun += 1
ans = abs(sum(alice) - sum(bob))
print(ans)

Submission status: Accepted

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

al=list()
bl=list()

i = 0
j = 0
while 2*i < N:
    al.append(l[2*i])
    i = i + 1
while 2*j+1 < N:
    bl.append(l[2*j+1])
    j = j+1
    
print(sum(al)-sum(bl))

Submission status: Accepted

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

print(abs(s))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
a.sort()
s=sum(a[:n:2])-sum(a[1:n:2])
if s>0:
    print(s)
else:
    print(-s)

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(0,n,2):
    alice += a[i]
    if i == n-1:
        break
    bob += a[i+1]
print(alice-bob)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    an = sorted([int(n) for n in input().split()], reverse=True)

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
for a in sorted(map(int,[*open(c:=0)][1].split())):c=a-c
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

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

a.sort(reverse=True)

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

print(x-y)

Submission status: Accepted

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

a = sorted(a, reverse=True)
alice = 0
bob = 0
for i in range(len(a)):
    if i%2==0:
        alice += a[i]
    if i%2==1:
        bob += a[i]
print(alice-bob)

Submission status: Accepted

Solution code:
n = int(input())
cards = list(map(int,input().split()))
cards = sorted(cards,reverse=True)
alice = bob = 0
for i in cards[::2]:
    alice += i
for j in cards[1::2]:
    bob += j
print(alice - bob)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(s) for s in input().split()]
a.sort(reverse=True)
alice = sum(a[0:n:2])
bob = sum(a[1:n:2])

print(alice - bob)

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)
sum1=0
sum2=0
for num in range(N):
  if num % 2 == 0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1 - sum2)

Submission status: Accepted

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

dl = list(sorted(l))
dl = list(reversed(dl))

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

list1.sort(reverse=True)

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

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i 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:
mycode = r'''
# distutils: language=c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: infer_types=True
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

# define 
ctypedef long long LL
ctypedef LL[:] Arr


import numpy as np

# 読み込みはpython側で行う
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.readline #文字列読み込む時はこっち


cdef LL a_int(): return int(readline())

def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

cdef LL N=a_int()
cdef Arr A = ints() #memoryviewはnumpyの引数が使えます
A=np.sort(A)[::-1] 
print(np.sum(A[0::2]) - np.sum(A[1::2])) #なんとmemoryviewでもスライスが使える

'''

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    import os
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode