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: Runtime Error

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

alice = 0
bob = 0

A_rev = sorted(A, reverse=True)

while True:
    alice += A_rev.pop(0)
    bob += A_rev.pop(0)

    if len(A_rev) == 0:
        break

print(alice - bob)

Submission status: Runtime Error

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
N = int (input ())
L = input ().split ()
l = [int(s) for s in L]
list.sort (l, reverse=True)
a = 0
x = 0
m = math.ceil(N/2)
for i in range (m):
    x += int (l[a])
    a += 2
a = 1
y = 0
for i in range (N-m):
    y += int (l[a])
    b += 2
print (x-y)

Submission status: Runtime Error

Solution code:
import math
N = int (input ())
l = input ().split ()
l = [int(s) for s in l]
list.sort (l, reverse=True)
a = 0
x = 0
m = math.ceil(N/2)
for i in range (m):
    x += int (l[a])
    a += 2
a = 1
y = 0
for i in range (N-m):
    y += int (l[a])
    b += 2
print (x-y)

Submission status: Runtime Error

Solution code:
N = int (input ())
l = input ().split ()
list.sort (l, reverse=True)
a = 0
x = 0
for i in range (round(N/2)):
    x += int (l[a])
    a += 2
b = 1
y = 0
for i in range (N-(round(N/2))):
    y += int (l[b])
    b += 2
print (x-y)

Submission status: Runtime Error

Solution code:
N = int (input ())
l = input ().split ()
list.sort (l, reverse=True)
a = 0
x = 0
for i in range (round(N/2)):
    x += int (l[a])
    a += 2
a = 1
y = 0
for i in range (N-(round(N/2))):
    y += int (l[a])
    a += 2
print (x-y)

Submission status: Runtime Error

Solution code:
N = int (input ())
l = input ().split ()
list.sort (l, reverse=True)
a = 0
x = 0
for i in range (round(N/2)):
    x += l[a]
    a += 2
a = 1
y = 0
for i in range (N-(round(N/2))):
    y += l[a]
    a += 2
print (x-y)

Submission status: Runtime Error

Solution code:
N = int (input ())
l = []
for i in range (N):
    a = int (input ())
    l.append (a)
list.sort (l, reverse=True)
a = 0
x = 0
for i in range (round(N/2)):
    x += l[a]
    a += 2
a = 1
y = 0
for i in range (N-(round(N/2))):
    y += l[a]
    a += 2
print (x-y)

Submission status: Runtime Error

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

a.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
res = 0
for x in X:
    res += 2 * min(x, K - x)
print(res)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;  cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    int Alice(0),Bob(0);
    for(int i=0;i<n;i++){
        if(i%2==0)
            Alice += a[i];
        else
            Bob += a[i];
    }
    
    cout << Alice-Bob << endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;  cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    int Alice(0),Bob(0);
    for(int i=0;i<n;i++){
        if(i%2==0)
            Alice += a[i];
        else
            Bob += a[i];
    }
    
    cout << Alice-Bob << endl;
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

new_a=list.sort(a, reverse=True)

a=0
b=0

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

Submission status: Runtime Error

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

new_a=list.sort(a, reverse=True)

a=0
b=0

for i in range(0,len(new_a),2);
	a+=new_a[i]
for i in range(1,len(new_a),2);
	b+=new_a[i]
print(a-b)

Submission status: Runtime Error

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

new_a=list.sort(x, reverse=True)

a=0
b=0

for i in range(0,len(new_a),2);
	a+=new_a[i]
for i in range(1,len(new_a),2);
	b+=new_a[i]
print(a-b)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

alice_point = 0
bob_point = 0

def pick_card(card_list):
    # print(card_list)
    max = 0
    max_index = 0
    for i in range(card_list.__len__()):
        # print('-------', i)
        if card_list[i] > max:
            # print('@', i, ':', max, '<', card_list[i])
            max = card_list[i]
            max_index = i
    
    del card_list[max_index]

    # print('----', card_list)

    return max, card_list

def sort_card(card_list: list):
    return sorted(card_list)

turn = 0
sorted_list = sort_card(card_list)
while turn < n:
    # print('--', turn)
    if turn % 2 == 0:
        # alice_get, remain_list = pick_card(card_list)
        # alice_point += alice_get
        alice_point += sorted_list.pop(turn)
    else:
        # bob_get, remain_list = pick_card(card_list)
        # bob_point += bob_get
        bob_point += sorted_list.pop(turn)

    # card_list = remain_list
    print(alice_point, bob_point, card_list)

    turn += 1

print(alice_point - bob_point)

Submission status: Runtime Error

Solution code:

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

alice_point = 0
bob_point = 0

def pick_card(card_list):
    # print(card_list)
    max = 0
    max_index = 0
    for i in range(card_list.__len__()):
        # print('-------', i)
        if card_list[i] > max:
            # print('@', i, ':', max, '<', card_list[i])
            max = card_list[i]
            max_index = i
    
    del card_list[max_index]

    # print('----', card_list)

    return max, card_list

def sort_card(card_list: list):
    return card_list.sort()

turn = 0
while turn < n:
    # print('--', turn)
    sorted_list = sort_card(card_list)
    if turn % 2 == 0:
        # alice_get, remain_list = pick_card(card_list)
        # alice_point += alice_get
        alice_point += sorted_list.pop()
    else:
        # bob_get, remain_list = pick_card(card_list)
        # bob_point += bob_get
        bob_point += sorted_list.pop()

    card_list = remain_list
    # print(alice_point, bob_point, card_list)

    turn += 1

print(alice_point - bob_point)

Submission status: Runtime Error

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

cards.sort(reverse=True)
 
sum_A = 0
sum_B = 0
 
for i in range(N):
    if i % 2 == 0:
        sum_A += cards[i]
    else:
        sum_B += cards[i]

a = sum_A - sum_B
print(a)

Submission status: Runtime Error

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

cards.sort(reverse=True)
 
sum_A = 0
sum_B = 0
 
for i in range(N):
    if i % 2 == 0:
        sum_A += cards[i]
    else:
        sum_B += cards[i]

print(sum_A - sum_B)

Submission status: Runtime Error

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

cards.sort(reverse=True)
 
sum_A = 0
sum_B = 0
 
for i in range(N):
    if i % 2 == 0:
        sum_A += cards[i]
    else:
        sum_B += cards[i]

print(sum_A - sum_B)

Submission status: Runtime Error

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

num = cards.sort(reverse=True)

sum_A = 0
sum_B = 0

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

print(sum_A - sum_B)

Submission status: Runtime Error

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

L.sort(reverse=Ture)
print(sum(L[0::2]) - sum(L[1::2]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
x=x.sort()
x=x.reverse()
cnt=0
a=0
b=0
for i in x:
  if cnt%2==0:
    a+=i
    cnt+=1
  else:
    b+=i
    cnt+=1
print(a-b)

Submission status: Runtime Error

Solution code:
N=int(input())
alise=0
bob=0
a_list=list(map(int,input().split()))
a_sort=sorted(a_list)[::-1]
for i in range(N//2+N%2):
    alise+=a_sort.pop(0)
    bob+=a_sort.pop(0)
print(alise-bob)

Submission status: Runtime Error

Solution code:
n-int(input())
x=list(map(int,input().split()))
a=0
b=0
for i in range(n//2):
  a+=max(x)
  x.remove(max(x))
  b+=max(x)
  x.remove(max(x))

if n%2:
  a+=x[0]
dif=b-a
print(dif)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
4
20 18 2 18

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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
    bob+=next(c)
print(alice-bob)

Submission status: Runtime Error

Solution code:
a=int(input())

b=list(map(int, input().split()))
b.sort()
alice=0
bob=0

c=iter(b)
for i in c:
    alice=i
    bob=next(c)
print(alice-bob if alice>bob else bob-alice)

Submission status: Runtime Error

Solution code:
import nummpy as np

N = 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.sum(Alice) -np.sum(Bob)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A.sorted()
print(sum(A[::-2]) - sum(A[-2::-2])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Alice = 0
Bob = 0
while len(A)>0:
    Alice += max(A)
    A.remove(max(A))
    Bob += max(A)
    A.remove(max(A))
print(Alice - Bob)

Submission status: Runtime Error

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]
    Bob += A[i+1]
print(Alice-Bob)

Submission status: Runtime Error

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: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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 == 1:
        a_sum += a[i]
    else:
        b_sum += b[i]
print(a_sum - b_sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A_list = list(map(int, input().split())
 
a_sum = 0
b_sum = 0
for i in range(N//2):
  a,b = (A_list[2*i], A_list[2*i + 1]) if A_list[2*i] > A_list[2*i + 1] else (A_list[2*i + 1], A_list[2*i])
  a_sum += a
  b_sum += b
 
print(a_sum - b_sum)

Submission status: Runtime Error

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

a_sum = 0
b_sum = 0
for i in range(N//2):
  a,b = (A_list[2*i], A_list[2*i + 1]) if A_list[2*i] > A_list[2*i + 1] else (A_list[2*i + 1], A_list[2*i])
  a_sum += a
  b_sum += b

print(a_sum - b_sum)

Submission status: Runtime Error

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
s_a_list = sorted(a_list)
alice = 0
bob = 0
while len(s_a_list)>0:
  alice += s_a_list.pop(-1)
  bob += s_a_list.pop(-1)
print(alice-bob)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

card.sort()

ans = 0
for i in range(n//2+1):
            ans += card[2*i]-card[2*i+1]
if n%2==1:
            ans += card[-1]

print(ans)

Submission status: Runtime Error

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

card.sort()

for i in range(n//2):
            ans += card[2*i]-card[2*i+1]
if n%2==1:
            ans += card[-1]

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
a = 0
b = 0
for i in range(n):
  if i % 2 == 0:
    a += max(l)
    l = l.remove(max(l))
  elif i % 2 == 1:
    b += max(l)
    l = l.remove(max(l))
print(a-b)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split()
A.sort()
B = A[0::1]
b = sum(B)
C = A[1::1]
c = sum(C)
if b >= c:
  print(b-c)
else:
  print(c-b)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
numbers = []
A = 0
B = 0
num = 2
N= int(input())
for i in range(N):
    numbers.append(int(input()))
for i in range(N):
    if num%2==0:
        A += max(numbers)
        numbers.remove(max(numbers))
        num+=1
    else:
        B += max(numbers)
        numbers.remove(max(numbers))
        num+=1

print(A-B)

Submission status: Runtime Error

Solution code:
numbers = []
A = 0
B = 0
num = 2
N= int(input())
for i in range(N):
    numbers.append(int(input()))
print(numbers)
for i in range(N):
    if num%2==0:
        A += max(numbers)
        numbers.remove(max(numbers))
        num+=1
    else:
        B += max(numbers)
        numbers.remove(max(numbers))
        num+=1

print(A-B)

Submission status: Runtime Error

Solution code:
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    sumA=0
    sumB=0
    B = sorted(A, reverse=True)
    turnB = False

    for i in B:
        if turnB == False:
            sumA += i
            turnB = True
        else:
            sumB += i
            turnB = False

    print(int(sumA - SumB))


resolve()

Submission status: Runtime Error

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

if N == 1:
	print(A[0])
else:
	Alice = sum(A[0::2])
	Bob = sum(A[1::2])
    print(Alice-Bob)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=[map(int, input().split())]
sortedA=sorted(A, reverse=True)
Bob=0
Alice=0
for i in range(len(A)):
  # print(i)
  if i == 0 or i%2==0:
    Alice+=sortedA[i]
  else:
    Bob +=sortedA[i]
print(Alice-Bob)

Submission status: Runtime Error

Solution code:
N=int(input())
A=map(int, input().split())
sortedA=sorted(A, reverse=True)
Bob=0
Alice=0
for i in range(len(A)):
  # print(i)
  if i == 0 or i%2==0:
    Alice+=sortedA[i]
  else:
    Bob +=sortedA[i]
print(Alice-Bob)

Submission status: Runtime Error

Solution code:
N=int(input())
A=map(int, input())
sortedA=sorted(A, reverse=True)
Bob=0
Alice=0
for i in range(len(A)):
  # print(i)
  if i == 0 or i%2==0:
    Alice+=sortedA[i]
  else:
    Bob +=sortedA[i]
print(Alice-Bob)

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#6
N = int(input())
a = reversed(sorted(list(map(int, input().split()))))
Alice_list = []
Bob_list = []
for i in range(N):
    if i%2==0:     
        Alice_list.append(a[i])
    else:
        Bob_list.append(a[i])
print(sum(Alice_list)-sum(Bob_list))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

a.sort(reverse=True)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

A = S[0:n+1:2]
B = S[1:n+1:2]

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
S = s.sort(reverse=True)
A = S[0:n+1:2]
B = S[1:n+1:2]
sum_A = sum(A)
sum_B = sum(B)
print(sum_A - sum_B)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
S = s.sort()
S_re = S.reverse()
A = S_re[0:n+1:2]
B = S_re[1:n+1:2]
sum_A = sum(A)
sum_B = sum(B)
print(sum_A - sum_B)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
S = s.sort(Reverse=True)
A = S[0:n+1:2]
B = S[1:n+1:2]
sum_A = sum(A)
sum_B = sum(B)
print(sum_A - sum_B)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int, input()))
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: Runtime Error

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

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
# スペース区切りの整数の入力
b, c = map(int, input().split())
# 文字列の入力
s = input()
# 出力
print("{} {}".format(a+b+c, s))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
nums = sorted(list(map(int, input().split()))[::-1])
A = 0
B = 0
for n in range(N):
  A = A + nums[2n]
  B = B + nums[2n+1]
print(A - B)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
score = list(map(int, input().split()))
total = 0
 
score.sort(reverse=True)
for i in range(0, N, 2):
  if score[i+1] == None:
    total += score[i]
  else:
    total += score[i]-score[i+1]

print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
score = list(map(int, input().split()))
total = 0
 
score.sort(reverse=True)
for i in range(N):
  if score[i+1] == None:
    total += score[i]
  else:
    total += score[i]-score[i+1]
 
print(total

Submission status: Runtime Error

Solution code:
N = int(input())
score = [0]*N
score = map(int, input().split())
total = 0

score.sort(reverse=True)
for i in range(N):
  if score[i+1] == None:
    total += score[i]
  else:
    total += score[i]-score[i+1]

print(total)

Submission status: Runtime Error

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

if len(cards) % 2 == 0:
    alice = 0
    for i in range(int(N/2)):
        alice = alice + cards[2 * i]
        
    bob = 0
    for j in range(int(N/2)):
        bob = bob + cards[2 * j + 1]
    else:
        alice = 0
    for i in range(int(N/2) + 1):
        alice = alice + cards[2 * i]
        
    bob = 0
    for j in range(int(N/2)):
        bob = bob + cards[2 * j + 1]
    
print(alice - bob)

Submission status: Runtime Error

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

#Aliceの得点（偶数番目の総和）
alice = 0
for i in range(int(N/2) + 1):
    alice = alice + cards[2 * i]

#Bobの得点（奇数番目の総和）
bob = 0
for j in range(int(N/2)):
    bob = bob + cards[2 * j + 1]
    
print(alice - bob)

Submission status: Runtime Error

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

ab=[0]*2

i=0
for a in aa:
  ab[i%2]+=a
  i+=1

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

Submission status: Runtime Error

Solution code:
N = int(input()) #入力値
lists = []
Bob=0
Alice=0

for i in range(0,N):
    A = input()
    lists.append(A) #入力した値をどんどん入れていく
    
lists.reverse() #入力した値ソート

for j in range(0,N):
      if j % 2 == 0: # Bobが偶数なら実行
         Bob=Bob+int(lists[j])
      else:
         Alice=Alice+int(lists[j])
print(Alice-Bob)

Submission status: Runtime Error

Solution code:
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
#define ll long long
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> pii;
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false);
int main(){fast;
	
	int n; cin>>n;
	vector<int> a(n);
	rep(i, n){
		cin>>a[i];
	}	
	sort(all(a));
	int alice = 0, bob = 0;
	bool ok = true;
	for(int i = n - 1; i >=0; i--){
		if(ok){
			alice += a[i];
			ok = false;
		}
		else {
			bob += a[i];
			ok = true;
		}
	}
	cout<<alice - bob<<endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split())
a = 0
b = 0
while len(A)>= 1:
    a = a + max(A)
    A.remove(max(A))
    b = b + max(A)
    A.remove(max(A))
print(a-b)