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:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlt():
    return(list(map(int, input().split())))


n = inp()

arr = inlt()

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

Submission status: Accepted

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

a = sorted(a, reverse=True)
ans = a[0]
m = 1
for i in range(1,n):
    m *= -1
    ans += m * a[i]

print(ans)

Submission status: Accepted

Solution code:
a=int(input())

b=list(map(int, input().split()))
b.sort(reverse=True)
alice=0
bob=0
c=iter(b)
for i in c:
    alice+=i
    try:
    	bob+=next(c)
    except:
      break
print(alice-bob)

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
a = readInts()
a.sort(reverse=True)
if len(a)%2:
	a.append(0)
alice = 0
bob = 0
for i in range(0,len(a),2):
	alice+=a[i]
	bob+=a[i+1]
print(alice-bob)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split()))) * (-1)
a.sort()
print(-1 * (sum(a[0::2]) - sum(a[1::2])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Alice=0
Bob=0
a.sort()
#print(a)
h=len(a)
for i in range(h):
    if len(a)>0:
        Alice+=a[-1]
        del a[-1]
        h-=1
    if len(a)>0:
        Bob+=a[-1]
        del a[-1]
        h-=1
print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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

aliceSum = sum(cards[-1::-2])
bobSum = sum(cards[-2::-2])

print(aliceSum - bobSum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    a=list(map(int,input().strip().split()))
    
    a.sort(reverse=True)
    
    alice=sum(a[n] for n in range(N) if n%2==0)
    bob=sum(a[n] for n in range(N) if n%2==1)
    return alice-bob

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    k = [int(i) for i in input().split()]
    a = 0
    b = 0
    k.sort(reverse=True)
    flag = True
    for i in k:
        if flag == True:
            a+=i
            flag=False
        else:
            b+=i
            flag=True
    print(a-b)

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:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    alice = 0
    bob = 0
    loop = 0
    while(a):
        loop = loop + 1
        get = max(a)
        a.remove(get)
        if loop % 2:
            alice = alice + get
        else:
            bob = bob + get
    return(alice - bob)


# 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]"
    print(solve(N, a))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

diff = A - B
print(diff)

Submission status: Accepted

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

Submission status: Accepted

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

alice = []
bob = []

for tmp in range(num):
    if tmp % 2 == 0:
        alice.append(max(cards))
        cards.pop(cards.index(max(cards)))
        continue
    bob.append(max(cards))
    cards.pop(cards.index(max(cards)))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

Alice = []
Bob = []
for i in range(N):
  if i%2==0:
    Alice.append(max(A))
    A.remove(max(A))
  else:
    Bob.append(max(A))
    A.remove(max(A))

Alice = np.array(Alice)
Bob = np.array(Bob)

ans = np.abs(np.sum(Alice) -np.sum(Bob))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a = [0]*n


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

alice = 0
bob = 0
m = 0

for i in range(0,n):
  if(i%2 == 0):
    m = max(b)
    alice = alice + m
    k = b.index(m)
    del b[k]
  else:
    m = max(b)
    bob = bob + m
    k = b.index(m)
    del b[k]
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())
  
n=i()
a=intl()
a.sort()
alice=0
bob=0
for i in range(1,n+1):
	if i%2==1:
		alice+=a[-i]
	else:
		bob+=a[-i]
print(alice-bob)

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())
  
n=i()
a=intl()
a.sort()
alice=0
bob=0
for i in range(-1,-n-1,-1):
	if i%2==1:
		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:
import sys
import math
import bisect

def main():
    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)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
for i in range(n):
    a_max = max(a)
    a.remove(a_max)
    if int(i)%2== 0:
        alice+=a_max
    else:
        bob += a_max
answer = alice - bob
print(answer)

Submission status: Accepted

Solution code:
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n= int(input())
a = li()
sa = sorted(a)
sa.reverse()
ans = 0
for i in range(n):
    if i%2==0:
        ans += sa[i]
    else:
        ans -= sa[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
Alice = 0
Bob = 0
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()))

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())
a=list(map(int,input().split()))
alice=0
bob=0
a=sorted(a,reverse=True)
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)

s = sum(a)
al = sum(a[::2])
bo = s - al
print(abs(al-bo))

Submission status: Accepted

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

Alice = 0
Bob = 0
A.sort(reverse=True)
Alice += sum(A[::2])
Bob += sum(A[1::2])
print(Alice - Bob)

Submission status: Accepted

Solution code:
from heapq import heapify, heappop
def main():
    card_num = int(input())
    cards = list(map(lambda x: -int(x), input().split()))
    heapify(cards)

    A_score = 0
    B_score = 0
    As_turn = True

    for i in range(card_num):
        card = - heappop(cards)
        if As_turn:
            A_score += card
        else:
            B_score += card
        As_turn = not As_turn

    diff = A_score - B_score
    print(diff)

main()

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
alice=sum(l[::2])
Bob=sum(l[1::2])

ans=alice-Bob

print(ans)

Submission status: Accepted

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

Alice = a[:n:2]
Bob = a[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)

t=0

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

print(t)

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

Submission status: Accepted

Solution code:
n = input()
a = 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())
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()))

al = 0
bo = 0
a.sort(reverse=True)
for i in range(len(a)):
    if i%2 == 0:
        al += a[i]
    else:
        bo += a[i]

print(al - bo)

Submission status: Accepted

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

A,B = 0,0
for i in range(n):
    if i%2 == 0:
        A += L[i]
    else:
        B += L[i]
print(A-B)

#print(sum(L[::2]) - sum(L[1::2]))

Submission status: Accepted

Solution code:
input()
values = sorted(tuple(map(int, input().split(' '))), reverse=True)

pa = sum(values[::2])
pb = sum(values[1::2])

print(pa - pb)

Submission status: Accepted

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

a.sort()

even = sum(a[0::2])
odd = sum(a[1::2])

print(abs(even-odd))

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
A.sort(reverse=True)

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

print(res)

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(0,N,2):
    Alice += A[i]
    if i+1 <= N-1:
        Bob += A[i+1]
print(Alice-Bob)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = 0
while len(A)>= 2:
  ans += A[0]-A[1]
  A = A[2:]
if len(A) == 1:
  ans += A[0]
print(ans)

Submission status: Accepted

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

# Initialize
Alice = 0
Bob = 0

for i in range(0, n):
    # print(i, A[i])
    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 = list(sorted(A, reverse=True))

ret = 0

for i in range(0, n):
    if i % 2 == 0:
        ret += A[i]
    else:
        ret -= A[i]

print(ret)

Submission status: Accepted

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

Alice = 0
Bob = 0

A = list(sorted(A, reverse=True))

while True:
    if A != []:
        Alice += A.pop(0)
    else:
        break
    if A != []:
        Bob += A.pop(0)
    else:
        break

print(Alice-Bob)

Submission status: Accepted

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

a_score = 0
b_score = 0

A.sort(reverse=True)

for i in range(len(A)):
  if i % 2 == 0:
    a_score += A[i]
  else:
    b_score += A[i]

print(a_score - b_score)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
x = sum(a[0::2])
y = sum(a[1::2])
print(abs(x - y))

Submission status: Accepted

Solution code:
N=int(input())
A= list(map(int,input().split()))
list.sort(A,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:
def draw_max_card(card_list):
    max_card = max(card_list)
    card_list.remove(max_card)
    return max_card

n = int(input())
card_list = list(map(int, input().split(" ")))
points_alice = 0
points_bob  = 0
for count in range(1, n + 1):
    if count % 2 != 0:
        points_alice += draw_max_card(card_list)
    else:
        points_bob += draw_max_card(card_list)

print(points_alice - points_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 = input()
A = [int(hoge) for hoge in input().split()]
A.sort(reverse=True)
Alice = A[::2]
Bob = A[1::2]
print(sum(Alice)-sum(Bob))

Submission status: Accepted

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

a = sorted(a, reverse=True)

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

print(Alice-Bob)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

Submission status: Accepted

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

a.sort(reverse=True)

#print(n, a)

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

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

a.sort(reverse=True)

a=[(-1)**i*j for i,j in enumerate(a)]

print(sum(a))

Submission status: Accepted

Solution code:
input()
A = list(map(int, input().split()))
A.sort(reverse=True)
print(sum([A[i] * ((-1) ** (i % 2)) for i in range(len(A))]))

Submission status: Accepted

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

A.sort(reverse=True)
print(sum([A[i] for i in range(len(A)) if i % 2 == 0]) - sum([A[i] for i in range(len(A)) if i % 2 == 1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string,decimal
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a = LI()
a.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0
a = 0
b = 0
n = iin()
x = [int(x) for x in input().split()]
x.sort(reverse=True)
for i in range(n):
    if i%2 :
        a = a + x[i]
    else:
        b = b + x[i]
print(b-a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
a = [int(s) for s in sys.stdin.readline().split()]
a.sort(reverse=True)
a_sum = 0
b_sum = 0
for i in range(n):
    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())
A = sorted(list(map(int, input().split())), reverse=True)
if N == 1:
  print(A[0])
  exit()
print(sum(A[0::2]) - sum(A[1::2]))

Submission status: Accepted

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

alice = 0
bob = 0
fnum = 0
snum = 0

for i in range(int((n + 1)/2)):
    fir = 0
    sec = 0
    for j in range(int(n - i * 2)):
        if int(a[j]) > fir:
            sec = fir

            fir = int(a[j])
        elif int(a[j]) > sec:
            sec = int(a[j])
    alice += fir
    bob += sec
    a.remove(str(fir))
    if sec == 0:
        break
    else:
        a.remove(str(sec))

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

alice = 0
bob = 0

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

print(abs(alice - bob))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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]

ans = alice - bob
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
count = 1
index = len(a)
for i in range(len(a)):
    ans += a[index-1]*count
    index -= 1
    count *= -1

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:
def resolve():
  N = int(input())
  A = [int(i) for i in input().split()]
  
  A = sorted(A, reverse=True)
  alice = 0
  bob = 0
  for i in range(0, len(A), 2):
    alice += A[i]
    if i+1 < len(A):
      bob += A[i+1]

  print(alice - bob)
  
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def main():
    n = int(input())
    cards = list(map(int, input().split()))
    alice_point = 0
    bob_point = 0

    cards.sort()
    for i in range(0, n):
        if i%2 == 0:
            alice_point += cards[i]
        else:
            bob_point += cards[i]

    print(abs(alice_point - bob_point))

if __name__ == '__main__':
    main()

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)
alice = sum(a[::2])
bob = sum(a[1::2])
ans = alice - bob
print(ans)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#なお、任意の整数 M に対して M の −2 進数表現が一意に定まることが証明できます。
#2桁ごとに見るとよかった（もう実験したよ）
def resolve():
    N,=pin()
    A=lispin()
    A.sort()
    ans=0
    for i in range(N):
        t=A.pop()
        if i%2==0:ans+=t
        else: ans-=t
    print(ans)
#%%submit!
resolve()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A_list = sorted(list(map(int, input().split())))[::-1]
a_sum = 0
b_sum = 0

for i in range(N):
    if i % 2 == 0:
        a_sum += A_list[i]
    else:
        b_sum += A_list[i]
print(a_sum - b_sum)