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

a_sum=0
b_sum=0

for i in range((N+1)//2):
    max_value=max(card)
    max_index=card.index(max_value)
    a_sum+=max_value
    card[max_index]=0

    max_value=max(card)
    max_index=card.index(max_value)
    b_sum+=max_value
    card[max_index]=0

print(a_sum-b_sum)

Submission status: Accepted

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

a_sum=0
b_sum=0

for i in range((N+1)//2):
    max_value=max(a)
    max_index=a.index(max_value)
    a_sum+=max_value
    a[max_index]=0

    max_value=max(a)
    max_index=a.index(max_value)
    b_sum+=max_value
    a[max_index]=0

print(a_sum-b_sum)

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range(N):
   for j in reversed(range(i+1,N)):
        #print(i,j)
        if a[j] > a[j-1]:
            temp = a[j]
            a[j] = a[j-1]
            a[j-1] = temp

Alice = 0
Bob = 0

k = 0
count =1
while k < N:
    if count % 2 == 0:
        Bob += a[k]
    else:
        Alice += a[k]
    k += 1
    count += 1

print(Alice-Bob)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a=sorted(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:
import math
n=int(input())
a=(list(map(int,input().split())))
a.append(0)
al=0
bo=0
for i in range(0,(n+1)//2,1):
    al+=max(a)
    a.remove(max(a))
    
    bo+=max(a)
    a.remove(max(a))
print(al-bo)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = input()
a=a.split()
a=[int(s) for s in a]
list.sort(a, reverse=True)
alice = 0
bob = 0

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

Submission status: Accepted

Solution code:
n = input()
a = list(map(int,input().split()))
alice = 0
bob = 0
while(a != []):
    alice += max(a)
    a.remove(max(a))
    if(a == []):
        break
    bob += max(a)
    a.remove(max(a))

print(alice-bob)

Submission status: Accepted

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

print(abs(ans))

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())
l = list(map(int, input().split()))
l.sort(reverse=True)

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

Submission status: Accepted

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

ary = sorted(ary, reverse=True)
scores = [0, 0]
turn = 0
while len(ary) > 0:
    s = ary.pop(0)
    scores[turn] += s
    turn = (turn + 1) % 2

diff = scores[0] - scores[1]
print(diff)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
Aseq=input().split()
A=[]
for i in range(n):
    A.append(int(Aseq[i]))
A.sort(reverse=True)
AA=A[0::2]
AB=A[1::2]
print(sum(AA)-sum(AB))

Submission status: Accepted

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

alice = 0
bob = 0

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

print (alice - bob)

Submission status: Accepted

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

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

print(Alice-Bob)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys


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

    a.sort()
    a.reverse()

    alice = sum(a[::2])
    bob = sum(a[1::2])
    ans = alice - bob
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

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()))
a.sort(reverse=True)
ab=list(a[::2])
ac=list(a[1::2])
print(sum(ab)-sum(ac))
#print(ab)
#print(ac)

Submission status: Accepted

Solution code:
# atcoder では WAになる。なんで。
n = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse =True)
#
alice = []
bob = []
alice_total = 0
bob_total = 0
ans = 0
#
if n%2 == 0:
    for i in range(int(n/2)):
        alice.append(a[2*i])
        bob.append(a[2*i + 1])
elif n!=1:
    for j in range(int((n - 1)/2)):
        alice.append(a[2*j])
        bob.append(a[2*j + 1])
    alice.append(a[n - 1])
else:
    alice = a
#
alice_total = sum(alice)
bob_total = sum(bob)
ans = alice_total - bob_total
#
print(ans)

Submission status: Accepted

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

a_desc = sorted(a, reverse=True)
ans = sum(a_desc[::2]) - sum(a_desc[1::2])
print(ans)

Submission status: Accepted

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

cards = sorted(cards, reverse=True)

Alice = 0
Bob = 0

for i, card in enumerate(cards):
    if i % 2 ==0:
        Alice += card
    else :
        Bob += card
        
print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
li = list(map(int, input().split()))
li.sort(reverse=True)
alice = sum([i for index,i in enumerate(li) if index % 2 == 0])
ans = alice * 2 - sum(li)
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    input()
    num = list(map(int, input().split()))
    num.sort(reverse=True)
    count = 1
    alice = 0
    bob = 0
    for val in num :
        if count % 2 == 0:
            bob += val
        else:
            alice += val
        count += 1
    print(alice - bob if alice >= bob else bob - alice)

if __name__ == '__main__':
        resolve()

Submission status: Accepted

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

Submission status: Accepted

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

card.sort(reverse=True)
alice = []
bob = []

for i in range(len(card)):
    if i % 2 == 0:
        alice.append(card[i])
    else:
        bob.append(card[i])

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

Submission status: Accepted

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

aa = sorted(a,reverse=True)
Alice = 0
Bob = 0

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

print(Alice-Bob)

Submission status: Accepted

Solution code:
n = int(input())

num = [int(i) for i in input().split()]
nums = sorted(num,reverse = True)
print(sum(nums[::2]) - sum(nums[1::2]))

Submission status: Accepted

Solution code:
n = int(input())

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

sortList = sorted(a,reverse=True)

alice = []
bob = []

for i in range(n):
    if i % 2 ==0:
      alice.append(sortList[i])
    if i % 2 != 0:
      bob.append(sortList[i])
        
        
print(sum(alice)-sum(bob))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)
alice = sum(a[i] for i in range(len(a)) if i % 2 ==0)
bob = sum(a[i] for i in range(len(a)) if i % 2 ==1)

print(alice - bob)

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

Submission status: Accepted

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

Alice = 0
Bob = 0
while not sorted_a == []:
  Alice += sorted_a[0]
  sorted_a.pop(0)
  if sorted_a == []:
    break
  Bob += sorted_a[0]
  sorted_a.pop(0)

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

p = 0
q = 0

a = sorted(a, reverse=True)

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

print(p - q)

Submission status: Accepted

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

Submission status: Accepted

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

Alice_sum = 0
Bob_sum = 0

if N % 2 == 0:
    Alice_sum = sum(A[1::2])
    Bob_sum = sum(A[0::2])
else:
    Alice_sum = sum(A[0::2])
    Bob_sum = sum(A[1::2])

result = Alice_sum - Bob_sum

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort(reverse=True)

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

print(alice - bob)

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(a)

x = 0
y = 0

for i in range(len(a)):
    if i % 2 == 0:
        x += heapq.heappop(a)
    else:
        y += heapq.heappop(a)

print(abs(x - y))

Submission status: Accepted

Solution code:
n = int(input())
import collections
dat = list(map(int, input().split()))
dat.sort(reverse=True)
dat = collections.deque(dat)
resa , resb = 0,0

while len(dat) != 0:
    resa += dat.popleft()
    if len(dat) ==0:
        break
    resb += dat.popleft()

print(resa - resb)

Submission status: Accepted

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

A.sort(reverse=True)
Alice = 0
Bob = 0

for i in range(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()

alice=0
bob=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_lis = list(map(int, input().split()))
a_lis.sort(reverse=True)
alice = True
al_lis = []
bo_lis = []
for i in a_lis:
    if alice:
        al_lis.append(i)
    else:
        bo_lis.append(i)
    alice = not alice
print(sum(al_lis) - sum(bo_lis))

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()))
a.sort(reverse=True)
print(sum([a[i] for i in range(n) if i%2 == 0])-sum([a[i] for i in range(n) if i%2!=0]))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = 0
for k in range(len(a)):
    ans += a[k]*((-1)**k)

print(ans)

Submission status: Accepted

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

alice = 0
bob = 0
is_bob_turn = 0

for _ in range(len(a)):
  if not is_bob_turn:
    is_bob_turn = 1
    alice += max(a)
    del a[a.index(max(a))]
  else:
    is_bob_turn = 0
    bob += max(a)
    del a[a.index(max(a))]
print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: -utf8

N = int(input())
A = input().split(" ")
Alice = []
Bob = []

max = 0
mnum = 0
turn = 0
for i in range(N):
  A[i] = int(A[i])
  if(max < A[i]):
    max = A[i]
    mnum = i

Alice.append(max)
A.pop(mnum)
turn = 1

N = N -1

for i in range(N):
  max = 0
  mnum = 0
  for j in range(N):
    if(max < A[j]):
      max = A[j]
      mnum = j
  if(turn == 0):
    Alice.append(max)
    A.pop(mnum)
    turn = 1
  elif(turn == 1):
    Bob.append(max)
    A.pop(mnum)
    turn = 0
  N = N - 1

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

Submission status: Accepted

Solution code:
n = int(input())

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

a = 0
b = 0

A = list(reversed(sorted(A)))

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())
array = []
array_ = input().split()
for i in range(N):
    array.append((int)(array_[i]))
array.sort(reverse=True)
sum = 0
for i in range(N):
    sum = sum + array[i] * (-1)**i

print(sum)

Submission status: Accepted

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

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort(reverse=True)
    alice = sum([v for i, v in enumerate(a_list) if i % 2 == 0])
    bob = sum([v for i, v in enumerate(a_list) if i % 2 == 1])
    print(alice - bob)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

lst.sort(reverse = True)

a = lst[::2]
b = lst[1::2]
print(sum(a)-sum(b))

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    A.reverse()
    ans = 0
    for i in range(0, N-1, 2):
        ans += A[i] - A[i+1]
    if N % 2 == 1:
        ans += A[-1]
    return ans

print(solve())

Submission status: Accepted

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


for i in range(N//2):
  s+=A[2*i]-A[2*i+1]
if N%2==1:
  s+=A[N-1]
print(s)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n % 2 == 0:
  A = sum(a[1::2])
  B = sum(a[::2])
else:
  A = sum(a[::2])
  B = sum(a[1::2])

print(A-B)

Submission status: Accepted

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

one =[]
two =[]
count = 0
if N%2 ==0:
  while count <= N-1:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
else:
  while count <= N-2:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
  one.append(max(B))
  B.remove(max(B))

print(sum(one)-sum(two))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    card_num = int(input())
    cards = list(map(int, input().split(" ")))
    cards.sort(reverse=True)
    answer = 0
    for i in range(card_num):
        if i % 2:
            answer -= cards[i]
        else:
            answer += cards[i]
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

# ソートを行う
sortList = sorted(A, reverse=True)

# 配列
alice = []
bob = []

# 奇数がAlice
for i in range(len(sortList)):
        if i % 2 == 0:
                alice.append(sortList[i])
        if i % 2 != 0:
                bob.append(sortList[i])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = sorted(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(abs(Alice - Bob))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse = True)
i = 0
a = 0
b = 0
while i < n: 
    a = a +l[i]
    i += 2
i = 1
while i < n:
    b = b +l[i]
    i += 2
print(a -b)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
n = int(input())
lis = [int(x) for x in input().split(" ")]
lis.sort(reverse=True)
lis_Alice = []
lis_Bob = []

if n % 2 == 0:
  for a in range(0, n, 2):
    lis_Alice.append(lis[a])
  for b in range(1, n+1, 2):
    lis_Bob.append(lis[b])
else:
  for a in range(0, n+1, 2):
    lis_Alice.append(lis[a])
  for b in range(1, n, 2):
    lis_Bob.append(lis[b]) 

print(sum(lis_Alice) - sum(lis_Bob))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = input()
card = list(map(int, input().split()))
l = sorted(card, reverse=1)
Alice, Bob = 0, 0
for i in range(len(l)):
    if i % 2:
        Bob += l[i]
    else:
        Alice += l[i]
print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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


s = 0
for i, n in enumerate(data):
    s = s + int(math.pow((-1),(i%2)))*n
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())),reverse=True)
ANS=0
for i,v in enumerate(l):
  if i % 2 == 0:
    ANS += v
  else:
    ANS -= v
print(ANS)

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A_sort=sorted(A)
Alice=[]
Bob=[]
if N%2==0:
    for i in range(int(N/2)):
        Alice.append(A_sort[2*i+1])
        Bob.append(A_sort[2*i])
else:
    for i in range(int(N/2+1)):
        Alice.append(A_sort[2*i])
    for i in range(int(N/2)):
        Bob.append(A_sort[2*i+1])
Alice_sum=sum(Alice)
Bob_sum=sum(Bob)
ans=Alice_sum-Bob_sum
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cards=numpy.sort(a)
alice=sum(cards[::-2])
bob=sum(cards[-2::-2])
ans=alice-bob
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

is_alice_turn = True

alice_point = 0
bob_point = 0

while len(A) != 0:
    picked_num = max(A)
    if is_alice_turn:
        alice_point += picked_num
    else:
        bob_point += picked_num

    A.remove(picked_num)
    is_alice_turn = not is_alice_turn

print(alice_point - bob_point)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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:
N = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
res = 0
for i, x in enumerate(a):
    if i%2==0:
        res+=x
    else:
        res-=x
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()], 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個（リスト内包表記で）
N = int(input())
list_a = [int(x) for x in input().split()]

# 大きい順にソートして、交互にとったときの差
list_a.sort(reverse = True)

Alice = 0
Bob = 0

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

print(Alice-Bob)

Submission status: Accepted

Solution code:
n=int(input())
*a,=map(int,input().split())
a.sort(reverse=True)
A=a[::2]
B=a[1::2]
print(sum(A)-sum(B))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
card=list(map(int, input().split()))
card.sort(reverse=True)
#print(card)
sum=0
turn=0
for i in card:
	if turn ==0:
		sum += i
		turn = 1
	else:
		sum -= i
		turn =0
print(sum)

Submission status: Accepted

Solution code:
N = int(input())

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

data = sorted(L, reverse=True)
count_A = 0
count_B = 0

for i, d in enumerate(data):
    if i%2 == 0:
        count_A += d
    else:
        count_B += d
        
print(count_A - count_B)

Submission status: Accepted

Solution code:
num=int(input())
values=[int(str) for str in input().split()]

values=sorted(values,reverse=True)


sumA=0
sumB=0
for i,val in enumerate(values):
    if i%2==0:
        sumA+=val
    else:
        sumB+=val

print(sumA-sumB)

Submission status: Accepted

Solution code:
def main(n,a):
    #カードを大きい順に並び替える
    a.sort(reverse = True)
    #奇数番目がアリス、偶数番目がボブ
    alis = a[0::2]
    bob = a[1::2]
    return sum(alis) - sum(bob)

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

Submission status: Accepted

Solution code:
N = int(input())
ans_Alice = 0
ans_Bob = 0

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

a_new = sorted(a, reverse = True)


for i in range(0, N, 2):
	ans_Alice += a_new[i]
	
for j in range(1, N, 2):
	ans_Bob += a_new[j]


print(str(ans_Alice - ans_Bob))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
A_total = 0
B_total = 0
A_current = 0
B_current = 0
count = 0
while not len(a) == 0:
  if count%2 == 0:
    A_current = max(a)
    a.remove(A_current)
    A_total += A_current
    count += 1
  else:
    B_current = max(a)
    a.remove(B_current)
    B_total += B_current
    count += 1

print(A_total - B_total)

Submission status: Accepted

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

points_alice = 0
points_bob = 0
for i in range(0, N, 2):
    points_alice += A[i]

for i in range(1, N, 2):
    points_bob += A[i]

print(points_alice - points_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())
l = list(map(int, input().split()))
l.sort(reverse=True)

a = 0
b = 0

for i, num in enumerate(l):
    if i % 2 == 0:
        a += num
    else:
        b += num

print(a-b)

Submission status: Accepted

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

Submission status: Accepted

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

alice=a[0:n:2]
bob=a[1:n:2]

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

Submission status: Accepted

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

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()))
a.sort(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.sort(reverse = True)
print(sum(A[0:len(A):2])-sum(A[1:len(A):2]))

Submission status: Accepted

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

    A.sort(reverse=True)

    Alice = 0
    Bob = 0

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

    print(Alice - Bob)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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