Problem:


Score: 200 points

Problem Statement

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

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:  

N
a_1 a_2 a_3 ... a_N

Output

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

Sample Input 1

2
3 1

Sample Output 1

2

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

Sample Input 2

3
2 7 4

Sample Output 2

5

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

Sample Input 3

4
20 18 2 18

Sample Output 3

18



Sample input:
2
3 1


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
Alice = []
Bob = []
for i in range(1,N+1):
    if i % 2 != 0:
        Alice.append(A[i-1])
    else:
        Bob.append(A[i-1])
print(sum(Alice)-sum(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:
# ABC088 B

def main():
    n = int(input())
    A = list(map(int, input().split()))

    Alice = 0
    Bob = 0
    A_sorted = sorted(A)[::-1]

    for i in range(n):
        if i % 2:
            Bob += A_sorted[i]
        else:
            Alice += A_sorted[i]
    
    print(Alice - Bob)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

lines = 2
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())

a_lst = [int(i) for i in inp[1].split()]

alice = 0
bob = 0

for idx, i in enumerate(sorted(a_lst, reverse=True)):
    if idx % 2 == 0:
        alice += i
        continue
    bob += i

print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
roundnum=0
alice=0
bob=0
def game():
    global roundnum
    global alice
    global bob
    if roundnum%2==0:
        alice+=a.pop()
    else:
        bob+=a.pop()
    roundnum+=1
        
while a:
    game()
    
print(alice-bob)

Submission status: Accepted

Solution code:

n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_list.sort(reverse = True)

a_point = 0
b_point = 0

for i in range(n):
  if i % 2 == 0:
    a_point += a_list[i]
  else:
    b_point += a_list[i]

print(a_point - b_point)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

s2 = sorted(s, reverse=True)

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

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

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

print(abs(alice - bob))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
alice = 0
bob = 0
ban = 0
while len(a) > 0:
    if ban % 2 == 0:
        alice += a.pop()
    else:
        bob += a.pop()
    ban += 1
print(alice - bob)

Submission status: Accepted

Solution code:

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

a.sort(reverse = True)

a_score, b_score = 0, 0

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

print(a_score - b_score)

Submission status: Accepted

Solution code:
url = "https://atcoder.jp/contests/abc088/tasks/abc088_b"

def main():
    g = input()
    lis = list(map(int, input().split()))
    lis.sort(reverse=True)
    a = 0
    b = 0
    for i in range(len(lis)):
        if i % 2 == 0:
            a += lis[i]
        else:
            b += lis[i]
    print(a - b)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Alice = 0
Bob = 0

while A:
    Alice += A.pop()
    if A:
        Bob += A.pop()

print(Alice - Bob)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Alice = 0
Bob = 0
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:
# -*- coding: utf-8 -*-

N = int(input())
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
S = sum(a)
s = 0
for i in range(0, N, 2):
  s = s + a[i]

print(s - (S - s))

Submission status: Accepted

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

alicePointList = a[::2]
bobPointList = a[1::2]

print(sum(alicePointList)-sum(bobPointList))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in 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[0::2])-sum(A[1::2]))

Submission status: Accepted

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

card = sorted(a, reverse=True)

alice = sum(card[0::2])
bob = sum(card[1::2])
print(alice - bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_, a = int(input()), 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(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)
p=0
q=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
cardList = list(map(int,input().split()))
a = 0
b = 0
cardList.sort(reverse=True)
while len(cardList) > 0:
    if len(cardList) > 0:
        a += cardList.pop(0)
    if len(cardList) > 0:
        b += cardList.pop(0)
print(a-b)

Submission status: Accepted

Solution code:
input()
A = sorted(map(int, input().split()))[::-1]
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)
score_a = 0
score_b = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def nyu():
    num1 = input()
    #num2 = input().
    num2 = list(map(int,input().split()))
    num1 = int(num1)
    return num1,num2

def kansu(N,a):
    a_sum = 0
    b_sum = 0

    list.sort(a,reverse = True)
 
    
    for n in range(N):
        if n%2 == 0:
            a_sum += a[n]
        else:
            b_sum += a[n]
    
    print(a_sum - b_sum)
        
N,a = nyu()
kansu(N,a)

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

alice = []
bob = []

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

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

Submission status: Accepted

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

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

print(Alice_sum - Bob_sum)

Submission status: Accepted

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

Submission status: Accepted

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

A = sorted(a)

ans = 0
for i in range(N):
  if i % 2 == 0:
    ans += A[-1]
  else:
    ans -= A[-1]
  A.pop()
print(ans)

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:
alice=0
bob=0
n=int(input())
a=list(map(int,input().split()))
def delete():
    del a[a.index(Max)]
while n>=1:
    Max=max(a)
    alice=alice+Max
    n=n-1
    delete()
    if n>=1:
        Max=max(a)
        bob=bob+Max
        n=n-1
        delete()
else:
    print(alice-bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = sorted(iil(),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 = sorted(A, reverse=True)

b = sum(A[::2])
c = sum(A[1::2])
print(b-c)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import fractions
import copy
import bisect
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter


N=3
M=3
i=0
j=0
k=0
n=3
r=1
a=[0]*5
b=[]
c=[]
N=int(input())
#real=math.sqrt(N)
#r=int(input())
#print(real)
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
card_list=sorted(number_list, reverse=True)
#print(card_list)
for i in range(N//2):
    b.append(card_list[2*i])
    c.append(card_list[2*i+1])
if N%2 ==1:
    b.append(card_list[-1])
print(sum(b)-sum(c))
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき 

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation


#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b 

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''





########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

Submission status: Accepted

Solution code:
# coding: utf-8

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

a = sorted(a, reverse=True)

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

diff = sum_a - sum_b
print(diff)

Submission status: Accepted

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

INF = float('inf')


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

    alice = 0
    bob = 0

    A = sorted(A, reverse=True)

    for _ in range(N):
        if len(A) != 0:
            alice += A.pop(0)
        if len(A) != 0:
            bob += A.pop(0)

    print(alice - bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

INF = float('inf')


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

    alice = 0
    bob = 0

    for _ in range(N):
        if len(A) != 0:
            alice += A.pop(A.index(max(A)))
        if len(A) != 0:
            bob += A.pop(A.index(max(A)))

    print(alice - bob)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum_A = 0
sum_B = 0

for i in range(0,n,2):
	sum_A += li[i]
#print(sum_A)
for i in range(1,n,2):
	sum_B += li[i]
#print(sum_B)

print(sum_A-sum_B)

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())
a=list(map(int,input().split()))
a.sort()
e=[]
b=[]
turn=1
for i in range(n):
    if turn==1:
        e.append(a.pop(-1))
        turn-=1
    else:
        b.append(a.pop(-1))
        turn+=1
print(sum(e)-sum(b))

Submission status: Accepted

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

Submission status: Accepted

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

bob   = 0
alice = 0

for i in range(len(new_arr)):
    if i % 2 ==0:
        alice += new_arr[i]
    elif i % 2 ==1:
        bob += new_arr[i]

print(alice-bob)

Submission status: Accepted

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

bob   = 0
alice = 0

for i in range(len(new_arr)):
    if i % 2 ==0:
        alice += new_arr[i]
    elif i % 2 ==1:
        bob += new_arr[i]

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

Submission status: Accepted

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

M = sorted(M,reverse=True)

alice = 0
bob = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,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 = int(input())
a_list = list(map(int, input().split()))
Alice = 0
Bob = 0
while n > 0:
    max_Alice = max(a_list)
    s = str(max_Alice)
    a_list[a_list.index(max(a_list))] = 0
    Alice += int(s)
    n -= 1
    if n == 0:
        break
    else:
        max_Bob = max(a_list)
        t = str(max_Bob)
        a_list[a_list.index(max(a_list))] = 0
        Bob += int(t)
        n -= 1
print(Alice - Bob)

Submission status: Accepted

Solution code:
n = 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()))
Alice = [0] * n
Bob = Alice[:]

A.sort(reverse = True)

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

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

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

alice, bob = 0, 0
for i in range(n):
    if i & 1:
        bob += a[i]
    else:
        alice += a[i]

print(alice-bob)

Submission status: Accepted

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

diff = 0
s = 1

while(len(c) > 0):
  diff = diff + (s * c.pop(c.index(max(c))) )
  s = s * -1

print(diff)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=a[1::2]#偶数番目
print(sum(a)-sum(b)*2)

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 math
import itertools
import statistics
#import collections
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())
a = list(map(int,input().split()))
a.sort()
ans = 0
nl = list(range(1,n+1))
for i in a:
  if nl.pop(0)%2 == 0:
    ans -= i
  else:
    ans += i
print(abs(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# B - Card Game for Two
# 標準入力の取得
N = int(input())
A_list = list(map(int, input().split()))

# リストを照準にソートしておく
sorted_A_list = sorted(A_list)

# AliceとBobの差の算出
Alice = 0
Bob = 0

if N % 2 == 0:
    # カード数が偶数の場合、a_2, a_4,・・・, a_NをAliceは取得する
    Alice = sum([sorted_A_list[i] for i in range(N) if i % 2 != 0])
    Bob = sum([sorted_A_list[i] for i in range(N) if i % 2 == 0])
else:
    # カード数が奇数の場合、a_1, a_3,・・・, a_NをAliceは取得する
    Alice = sum([sorted_A_list[i] for i in range(N) if i % 2 == 0])
    Bob = sum([sorted_A_list[i] for i in range(N) if i % 2 != 0])

print(Alice - Bob)

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n = I()
    a_list = LI()

    Alice = 0
    Bob = 0
    a_list.sort()
    while len(a_list) != 0:
        Alice += a_list.pop()
        if len(a_list) != 0:
            Bob += a_list.pop()

    print(Alice - Bob)
    pass


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(Alice - Bob)

Submission status: Accepted

Solution code:
N = int(input()) 
a = sorted(list(map(int, input().split())))[::-1]
f = int(0)
Ali = int(0)
Bob = int(0)

for i in range(N):
  if f == 0:
    Ali = Ali + a[0]
    del a[0]
    f = 1
  else:
    Bob = Bob + a[0]
    del a[0]
    f = 0
print(Ali-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,2):
    ans += a[i]
print(ans*2-sum(a))

Submission status: Accepted

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


a.sort(reverse=True)

sum1 = 0
sum2 = 0

for i in range(0,n,2):
    sum1 += a[i]

for i in range(1, n, 2):
    sum2 += a[i]

print(sum1 - sum2)

Submission status: Accepted

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

a.sort()
a.reverse()
count=0
for i in range(n):
  count+=a[i]*(-1)**i
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 26 18:51:52 2020

@author: 藤原聖士
"""

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

list.sort(a,reverse=True)

fugou=1
count=0

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

print (count)

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()))
ans=0
a.sort()

while n>0:
  ans+=a[n-1]
  n-=1
  if n==0:
    break
  ans-=a[n-1]
  n-=1
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

list = input().split()
list_int = [int(s) for s in list]
list_int.sort(reverse=True)

A = 0
B = 0

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

ans = A - B
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
C = list(map(int, input().split()))
A = []
B = []
while C != [0] * N:
    a = max(C)
    A.append(a)
    for i in range(len(C)):
        if C[i] == a:
            C[i] = 0
            break
    a = max(C)
    B.append(a)
    for i in range(len(C)):
        if C[i] == a:
            C[i] = 0
            break
print(sum(A)-sum(B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

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

total_a = 0
total_b = 0

count = 0

while len(a) > 0:
    if count % 2 == 0:
        max_value = max(a)
        total_a += max_value
        a.remove(max_value)
        count += 1
    else:
        max_value = max(a)
        total_b += max_value
        a.remove(max_value)
        count += 1
    
print(total_a - total_b)

Submission status: Accepted

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

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 main():
    n = int(input())
    As = sorted(list(map(int, input().split())))[::-1]

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

    ans = alice - bob
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

print(Alice-Bob)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = [int(x) for x in input().split()]
    apoints = 0
    bpoints = 0
    for i in range(N):
        if i%2 == 0:
            apoints += max(a)
        else:
            bpoints += max(a)
        a.remove(max(a))
    print(apoints - bpoints)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(num) for num in list(input().split(" "))]

a_list.sort(reverse = True)

total_dif = 0
for a in range(0,n,2):
    if a+1 ==n:
        total_dif += a_list[a]
    else:
        total_dif += a_list[a]-a_list[a+1]
print(total_dif)