Problem:


Score : 400 points

Problem Statement

There are N dishes of cuisine placed in front of Takahashi and Aoki.
For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.

When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.

Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat.
Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".

Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".

Sample Input 1

3
10 10
20 20
30 30

Sample Output 1

20

In this sample, both of them earns 10 points of happiness by eating Dish 1, 20 points by eating Dish 2, and 30 points by eating Dish 3.

In this case, since Takahashi and Aoki have the same "taste", each time they will choose the dish with which they can earn the greatest happiness. Thus, first Takahashi will choose Dish 3, then Aoki will choose Dish 2, and finally Takahashi will choose Dish 1, so the answer is (30 + 10) - 20 = 20.

Sample Input 2

3
20 10
20 20
20 30

Sample Output 2

20

In this sample, Takahashi earns 20 points of happiness by eating any one of the dishes 1, 2 and 3, but Aoki earns 10 points of happiness by eating Dish 1, 20 points by eating Dish 2, and 30 points by eating Dish 3.

In this case, since only Aoki has likes and dislikes, each time they will choose the dish with which Aoki can earn the greatest happiness. Thus, first Takahashi will choose Dish 3, then Aoki will choose Dish 2, and finally Takahashi will choose Dish 1, so the answer is (20 + 20) - 20 = 20.

Sample Input 3

6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 3

-2999999997

Note that the answer may not fit into a 32-bit integer.



Sample input:
3
10 10
20 20
30 30


Sample output:
20

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    s = ip.SILS()

    for i in r(n):
        s[i].append(s[i][0] + s[i][1])

    id.S(s, 1, 2)

    print(sum(s[i][0] for i in r(0, n, 2)) - sum(s[i][1] for i in r(1, n, 2)))


main()

Submission status: Runtime Error

Solution code:
n = int(input())
ab = []
bsum = 0
for i in range(n):
    a,b = map(int,input().split(' '))
    ab.append(a + b)
    bsum += b
ad.sort(reverse = True)
print(sum(ab[0::2]) - bsum)

Submission status: Runtime Error

Solution code:
import numpy as np


class Person:
    def __init__(self, list_score_my, list_score_other, list_eatable):
        self.list_score_my = list_score_my
        self.list_score_other = list_score_other
        self.list_eatable = list_eatable
        self.eatable = True
        self.score_sum = 0

    # other
    def get_score_max_other(self):
        return np.max(self.list_score_other)

    def get_score_max_other_eatable(self):
        return np.max(self.list_score_other * self.list_eatable)

    def get_index_of_score_max_other_eatable(self):
        return np.where(self.list_score_other == self.get_score_max_other_eatable())

    def is_other_has_same_max_score(self):
        flag = 0
        score_other_max = np.max(self.list_score_other)
        for i in self.list_score_other:
            if(self.list_score_other[i] == self.score_other_max):
                flag += 1

        if(flag > 1):
            return True
        else:
            return False

    # my
    def get_score_max_my(self):
        return np.max(self.list_score_my)

    def get_score_max_my_eatable(self):
        return np.max(self.list_score_my * self.list_eatable)

    def get_index_of_score_max_my_eatable(self):
        return np.where(self.list_score_my == self.get_score_max_my_eatable())

    def is_i_have_same_max_score(self):
        flag = 0
        self.score_my_max = np.max(self.list_score_my)
        for i in range(len(self.list_score_my)):
            if(self.list_score_my[i] == self.score_my_max):
                flag += 1
        if(flag > 1):
            return True
        else:
            return False

    def eat(self, index):
        self.list_eatable[index] = False
        self.score_sum += self.list_score_my[index]

    def print_score(self):
        print(self.list_score_my)


def get_data(ryouri_goukei_num):
    list_score_a = np.empty(ryouri_goukei_num)
    list_score_b = np.empty(ryouri_goukei_num)
    list_ryouri_is_eatable = np.empty(ryouri_goukei_num)

    for i in range(ryouri_goukei_num):
        inputData = input()
        splitData = inputData.split()
        a_data = int(splitData[0])
        b_data = int(splitData[1])
        list_score_a[i] = a_data
        list_score_b[i] = b_data
        list_ryouri_is_eatable[i] = True

    return list_score_a, list_score_b, list_ryouri_is_eatable


def main():
    ryouri_goukei_num = int(input())
    list_score_a, list_score_b, list_ryouri_is_eatable = get_data(
        ryouri_goukei_num)

    takahashi = Person(list_score_a, list_score_b, list_ryouri_is_eatable)
    aoki = Person(list_score_b, list_score_a, list_ryouri_is_eatable)

    takahashi.print_score()
    aoki.print_score()

    for i in range(ryouri_goukei_num):
        if(takahashi.eatable):
            if(takahashi.is_i_have_same_max_score()):
                takahashi.eat(takahashi.get_index_of_score_max_other_eatable())
            else:
                takahashi.eat(takahashi.get_index_of_score_max_my_eatable())

            takahashi.eatable = False
            aoki.eatable = True
            list_ryouri_is_eatable = takahashi.eatable
            continue

        if(aoki.eatable):
            if(aoki.is_i_have_same_max_score()):
                aoki.eat(aoki.get_index_of_score_max_other_eatable())
            else:
                aoki.eat(aoki.get_index_of_score_max_my_eatable())

            takahashi.eatable = True
            aoki.eatable = False
            list_ryouri_is_eatable = aoki.eatable
            continue

    print(int(takahashi.score_sum - aoki.score_sum))


main()

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
x = []
for i in range(N):
    x.extend(input().split())

a = np.array(x, dtype = 'int').reshape((3, 2))
s = a[:,0:1] + a[:,1:2]
a = np.hstack((a, s))
a = a[np.argsort(a[:, 2])][::-1, :]
n = np.sum(a[0::2, 0]) - np.sum(a[1::2, 1])
print(n)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
li = []
for i in range(n):
    a, b = map(int, input().split())
    li.append([a+b, a, b])

li = sorted(li)
li = reversed(li)
for i in range(n):
    if i%2 == 0:
        ans += li[i][1]
    else:
        ans -= li[i][2]

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A, B = [], []
Z = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

    Z.append((a + b, a, b))

Z = sorted(Z, reverse=True)
ans = 0
for v, i in enumerate(Z):
    if i % 2 == 0:
        ans += v[1]
    else:
        ans -= v[2]

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A, B = [], []
Z = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

    Z.append((a + b, a, b))

Z = sort(Z, reverse=True)
ans = 0
for v, i in enumerate(Z):
    if i % 2 == 0:
        ans += v[1]
    else:
        ans -= v[2]

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

dishes = list()

for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    sum = a + b
    dishes.append([a, b, sum])

takahashi = 0
aoki = 0
dishes.sort(key=lambda x: x[2], reverse=True)

for i in range(0, n):
    if i % 2 == 0:
        j = dishes[0]
        dishes.pop(0)
        takahashi = takahashi + j[0]
    else:
        j = dishes[0]
        dishes.pop(0)
        aoki = aoki + j[1]

print(takahashi - aoki)

Submission status: Runtime Error

Solution code:
n = int(input())
ab = []
x = 0
for i in range(n):
  a,b = map(int,input().split())
  x -= b
  ab.append(a+b)
ab.sort()
for i in range(raound(n/2)):
  x += ab[i]
print(x)

Submission status: Runtime Error

Solution code:
N = int(input())
idx_to_AB = {}
for i in range(N):
    idx_to_AB[i] = list(map(int, input().split()))

A_to_idx = {value[0]: key for key, value in idx_to_AB.items()}
B_to_idx = {value[1]: key for key, value in idx_to_AB.items()}

A = sorted(A_to_idx, reverse=True)
B = sorted(B_to_idx, reverse=True)

cntA, cntB = 0, 0
while (len(idx_to_AB)):
    # 先行

    if A[0] > B[0]:
        cntA += A[0]
        B.remove(idx_to_AB[A_to_idx[A[0]]][1])
        del idx_to_AB[A_to_idx[A[0]]]
        A = A[1:]

    else:
        cntA += idx_to_AB[B_to_idx[B[0]]][0]
        A.remove(idx_to_AB[B_to_idx[B[0]]][0])
        del idx_to_AB[B_to_idx[B[0]]]
        B = B[1:]
    # print(idx_to_AB)
    # print(A, B)

    if len(idx_to_AB) == 0:
        break
    # 後攻
    if A[0] < B[0]:
        cntB += B[0]
        A.remove(idx_to_AB[B_to_idx[B[0]]][0])
        del idx_to_AB[B_to_idx[B[0]]]
        B = B[1:]
    else:
        cntB += idx_to_AB[A_to_idx[A[0]]][1]
        B.remove(idx_to_AB[A_to_idx[A[0]]][1])
        del idx_to_AB[A_to_idx[A[0]]]
        A = A[1:]

print(cntA-cntB)

Submission status: Runtime Error

Solution code:
from operator import itemgetter, attrgetter
#input
n = int(input())
H = []
for i in range(n):
    a, b = map(int, input().split())
    H.append([i, a, b])

C = sorted(H, key = itemgetter(1, 2), reverse = True)
A = sorted(H, key = itemgetter(2, 1), reverse = True)
 
ans_c = 0
ans_a = 0
turn = 0
 
while H != []:
    C = sorted(H, key = itemgetter(1, 2), reverse = True)
    A = sorted(H, key = itemgetter(2, 1), reverse = True)
    if turn % 2 == 0: #chokudai 
        if C[0][1] - A[0][1] >= A[0][2] - C[0][2]:
            chokudai = C.pop(0)
        else:
            chokudai = A.pop(0)
        ans_c += chokudai[1]
        H.pop(chokudai[0])
    else: #aoki
        if A[0][2] - C[0][2] >= C[0][1] - A[0][1]:
            aoki = A.pop(0)
        else:
            aoki = C.pop(0)
        ans_a += aoki[2]
        H.pop(aoki[0])
    turn += 1
 
print(ans_c - ans_a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 27 20:47:32 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
    
all(nstr.count(c) for c in '753')
"""

N = int(input())

A = [0]*N
B = [0]*N
dA = [0]*N
dB = [0]*N
totAB = [0]*N
for n in range(N):
    A[n], B[n] = map(int, input().split())
    totAB[n] = A[n] + B[n]

ABT = zip(A, B, totAB)
n = 0
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
ABT.sort(key=itemgetter(2))
A, B, totAB = zip(*ABT)
"""
while len(A) != 0:
    iT = totAB.index(max(totAB))
    if n % 2 == 0:
        result += A.pop(iT)
        del B[iT]
        del totAB[iT]
    else:
        result -= B.pop(iT)
        del A[iT]
        del totAB[iT]
    n +=1    
"""
resultA = sum(totAB[1::2])

resultB = sum(totAB[0::2]) 
result = resultA- resultB
print(result)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list()
    b = list()
    used = [False for i in range(n)]
    flag = True
    a_point = 0
    b_point = 0
    for i in range(n):
        data = input()
        data = data.split()
        data = [int(s) for s in data]
        a.append(data[0])
        b.append(data[1])
        if flag:
            while True:
                index = a.index(max(a))
                if (used[index]):
                    a.pop(index)
                    continue
                else:
                    flag = !flag
                    print(flag)
                    a_point += a[index]
                    used[index] = True
                    break
        else:
            while True:
                index = b.index(max(b))
                if (used[index]):
                    b.pop(index)
                    continue
                else:
                    flag = !flag
                    b_point += b[index]
                    used[index] = True
                    break
                    
    print(a_point)
    print(b_point)
    print(a_point - b_point)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
B=[]
C=[]
D=[]
x=[]
y=[]
k=0
j=0
for i in range(0,N):#N×2の行列を読み込む
    x=input().split(" ")
    y=int(x[0])-int(x[1])
    A.append(int(x[0]))
    B.append(int(x[1]))
    C.append(abs(y))#Ci=Ai-Bi
    #DはABCを格納するN×3行列
D=[A,B,C]
#3列目の成分でソート
D.sort(key=lambda p:p[2])
print(D)
i=N//2
p=0
for i in  range(0,p):
    if N%2==0:
        k=A[2*i]+k
        j=B[2*i+1]+j
        X=k-j
    else:
        k=A[2*i]+k
        j=B[2*i+1]+j
        X=k-j+A[N-1]
print(X)

Submission status: Runtime Error

Solution code:
la=[]
lb=[]
n=int(input())
kari=[]
tak=0
ao=0
for i in range(n):
    a,b=map(int,input().split())
    la.append(a)
    lb.append(b)
    kari.append(a-b)
while la!=[]:
    if max(kari)+min(kari)>0:
        tak+=la[kari.index(max(kari))]
        kari.remove(max(kari))
        la.remove(la[kari.index(max(kari))])
        lb.remove(lb[kari.index(max(kari))])
    else:
        tak+=la[kari.index(min(kari))]
        kari.remove(min(kari))
        la.remove(la[kari.index(min(kari))])
        lb.remove(lb[kari.index(min(kari))])
    if la==[]:
        break
    if max(kari)+min(kari)>0:
        ao+=la[kari.index(min(kari))]
        kari.remove(max(kari))
        la.remove(la[kari.index(min(kari))])
        lb.remove(lb[kari.index(min(kari))])
    else:
        ao+=la[kari.index(min(kari))]
        kari.remove(max(kari))
        la.remove(la[kari.index(max(kari))])
        lb.remove(lb[kari.index(max(kari))])
print(int(tak-ao))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
B=[]
C=[]
D=[]
x=[]
y=[]
k=0
j=0
for i in range(0,N):#N×2の行列を読み込む
    x=input().split(" ")
    y=int(x[0])-int(x[1])
    A.append(int(x[0]))
    B.append(int(x[1]))
    C.append(abs(y))#Ci=Ai-Bi
    #DはABCを格納するN×3行列
D=[A,B,C]
#3列目の成分でソート
D.sort(key=lambda p:p[2])
print(D)
i=N//2
for i in  range(0,p):
    if N%2==0:
        k=A[2*i]+k
        j=B[2*i+1]+j
        X=k-j
    else:
        k=A[2*i]+k
        j=B[2*i+1]+j
        X=k-j+A[N-1]
print(X)

Submission status: Runtime Error

Solution code:
N = int(input())
a = []
b = []
for i in range(N):
  w,q = map(int, input().split())
  a.append(w)
  b.append(q)
#勝負
x = 0
y = 0

for p in range(N):
  ma = max(max(a), max(b))
  indea = [i for i, x in enumerate(a) if x == ma]
  indeb = [i for i, x in enumerate(b) if x == ma]
  
  c = []
  ci = []
  for i in indea:#(3,4,5) index
      c.append(a[i] - b[i])#(10,100,12)
  if c != []:

    d = max(c)#(100)
    dm = c.index(d)#1

    
  
  e = []
  ei = []
  for i in indeb:
      e.append(b[i] - a[i])
  if f != []:

    f = max(e)
    fm = e.index(f)
  
  if d <= f:
    final_index = indeb[fm]
  else:
    final_index = indea[dm]
    
  if p%2 == 0:
    x += a[final_index]
  else:
    y += b[final_index]
  a.pop(final_index)
  b.pop(final_index)
print(x-y)

Submission status: Runtime Error

Solution code:
la=[]
lb=[]
n=int(input())
kari=[]
tak=0
ao=0
for i in range(n):
    a,b=map(int,input().split())
    la.append(a)
    lb.append(b)
    kari.append(a-b)
while la!=[]:
    if max(kari)+min(kari)>0:
        tak+=la[kari.index(max(kari))]
        kari.remove(max(kari))
        la.remove(la[kari.index(max(kari))])
        lb.remove(lb[kari.index(max(kari))])
    else:
        tak+=la[kari.index(min(kari))]
        kari.remove(min(kari))
        la.remove(la[kari.index(min(kari))])
        lb.remove(lb[kari.index(min(kari))])
    if max(kari)+min(kari)>0:
        ao+=la[kari.index(min(kari))]
        kari.remove(max(kari))
        la.remove(la[kari.index(min(kari))])
        lb.remove(lb[kari.index(min(kari))])
    else:
        ao+=la[kari.index(min(kari))]
        kari.remove(max(kari))
        la.remove(la[kari.index(max(kari))])
        lb.remove(lb[kari.index(max(kari))])
print(int(tak-ao))

Submission status: Runtime Error

Solution code:
from sys import stdin

def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

    disha = sorted(AB)
    dishb = sorted(disha, key=lambda x: x[1])
    taka, aoki = 0, 0
    dish = set()
    for i in range(N):
        if i % 2:
            while dishb[-1] in dish:
                dishb.pop(-1)
            aoki += dishb[-1][1]
            dish.add(dishb[-1])
            dishb.pop(-1)
        else:
            while disha[-1] in dish:
                disha.pop(-1)
            taka += disha[-1][0]
            dish.add(disha[-1])
            disha.pop(-1)
    print(taka - aoki)

input = lambda: stdin.readline()
main()

Submission status: Runtime Error

Solution code:
N=int(input())
a=[]
b=[]
A_SCORE=0
B_SCORE=0
for _ in range(N):
    A=[int(_) for _ in input().split()]
    a.append(A[0])
    b.append(A[1])

for _ in range(N):
    A=max(a)
    if a.count(max(a))==1:
        A_SCORE=A_SCORE+A
        a[a.index(max(a))]=0
        b[a.index(max(a))]=0
    else:
        A_SCORE=A_SCORE+A
        ENEMY=[b[i] for i, x in enumerate(a) if x == max(a)]
        a[b.index(max(ENEMY))]=0
        b[b.index(max(ENEMY))]=0
        ENEMY=[]

    B=max(b)
    if b.count(max(b))==1:
        B_SCORE=B_SCORE+B
        a[b.index(max(b))]=0
        b[b.index(max(b))]=0

    else:
        B_SCORE=B_SCORE+B
        ENEMY=[a[i] for i, x in enumerate(b) if x == max(b)]
        a[a.index(max(ENEMY))]=0
        b[a.index(max(ENEMY))]=0
        ENEMY=[]

print(abs(A_SCORE-B_SCORE))

Submission status: Runtime Error

Solution code:


N = int(input())

k_t = []
k_a = []

for n in range(N):
    a,b = map(int, input().split(" "))
    k_t.append(a)
    k_a.append(b)

ta_goukei = 0
ao_goukei = 0

N = int(N/2+0.5)

for j in range(N):
    ta_i = []
    ta_i  = [i for i, x in enumerate(k_t) if x == max(k_t)]

    #print(ta_i)
    #ta = max(k_t)
    #ta_i = k_t.index(max(k_t))

    ao = 0  
    for l in range(len(ta_i)):
        if ao < k_a[ta_i[l]]:
            ao =  k_a[ta_i[l]]
            ao_in = ta_i[l]

    ta_max = k_t[ao_in]
    k_t[ao_in] = 0
    k_a[ao_in] = 0

    #ao = max(k_a)
    #ao_i = k_a.index(max(k_a))
    ao_i = []
    ao_i  = [o for o, x in enumerate(k_a) if x == max(k_a)]

    ta = 0
    
    for m in range(len(ao_i)):
        if ta < k_t[ao_i[m]]:
            ta =  k_t[ao_i[m]]
            ta_in= ao_i[m]

    ao_max = k_a[ta_in]
    k_t[ta_in] = 0
    k_a[ta_in] = 0
    
    ta_goukei = ta_goukei + ta_max
    ao_goukei = ao_goukei + ao_max

print(ta_goukei - ao_goukei)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
ApB = []
ApB_dict = {}

for i in range(N):
	temp1, temp2 = map(int, input().split())
	s = temp1 + temp2
	ApB.append([s, temp1, temp2, i])
	ApB_dict.setdefault(s, 0)
	ApB_dict[s] += 1

ApB.sort()
ApB.reverse()
score = 0
for i in range(N):
	len_ApB = len(ApB)
	temp_ApB = ApB[0][0]
	num = ApB_dict[temp_ApB]
	if i % 2 == 0:
		if num == 1:
			score += ApB.pop(0)[1]
		else:
			l = ApB[0:len_ApB][1]
			Ind = np.argmax(l)
			score += ApB.pop(Ind)[1]
			ApB_dict[temp_ApB] -= 1
	else:
		if num == 1:
			score -= ApB.pop(0)[2]
		else:
			l = ApB[len_ApB-num:len_ApB][2]
			Ind = np.argmax(l)
			score -= ApB.pop(Ind)[2]
			ApB_dict[temp_ApB] -= 1
	#print("score:", score,"ApB:", ApB)

print(score)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(0, n):
  a.append(list(map(int, input().split())))
b = []
c = []
sumb = 0
sumc = 0
for i in range(0, n):
  b.append(a[i][0] - a[i][1])
  c.append(a[i][1] - a[i][0])
if n % 2 == 0:
  for i in range(0, int(n/2)):
    
    maxindb = b.index(max(b))
    sumb += a[maxindb][0]
    del b[maxindb]
    del c[maxindb]
    del a[maxindb]
    
    maxindc = c.index(max(c))
    sumc += a[maxindc][1]
    del b[maxindc]
    del c[maxindc]
    del a[maxindc]
    
if n % 2 != 0:
  for i in range(0, n//2):
    
    for i in range(0, int(n/2)):
    
    maxindb = b.index(max(b))
    sumb += a[maxindb][0]
    del b[maxindb]
    del c[maxindb]
    del a[maxindb]
    
    maxindc = c.index(max(c))
    sumc += a[maxindc][1]
    del b[maxindc]
    del c[maxindc]
    del a[maxindc]
    
  maxindb = b.index(max(b))
  sumb += a[maxindb][0]

result = sumb - sumc
print(result)

Submission status: Runtime Error

Solution code:
n = int(input())

a = [0  for i in range(n)]
b = [0  for i in range(n)]
x = [[0,0,0]  for i in range(n+2)]

for i in range(n):
    a[i],b[i]=map(int,input().split())
    x[i][0]=abs(a[i]-b[i])
    x[i][1]=a[i]
    x[i][2]=b[i]

s=sorted(x,reverse=True)


nu=n//2
mod=n%2

count=0
for i in range(nu):
    count+=x[i*2][1]

    count-=x[i*2+1][2]


if mod==1:
    counta=x[2*nu][1]

    

    

print(counta)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    diff_positive = dict()
    diff_negaitive = dict()
    pos_max = 0
    nega_max = 0
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]

    for i in range(n):
        ai, bi = map(int, input().split())
        a[i] = ai
        b[i] = bi

        if ai - bi >= 0:
            diff_positive[i] = ai - bi
            pos_max = max(pos_max, ai - bi)
        else:
            diff_negaitive[i] = bi - ai
            nega_max = max(nega_max, abs(ai - bi))

    posi = sorted(diff_positive.items(), key=lambda x: x[1], reverse=True)
    nega = sorted(diff_negaitive.items(), key=lambda x: x[1], reverse=True)
    taka_point = 0
    aoki_point = 0

    if len(posi) % 2 == 0:
        taka = posi[::2] + nega[::2]
        aoki = posi[1::2] + nega[1::2]

        for t in taka:
            taka_point += a[t[0]]

        for a in aoki:
            aoki_point += b[a[0]]

        print(taka_point - aoki_point)
    else:
        taka = posi[::2] + nega[1::2]
        aoki = posi[1::2] + nega[::2]

        for t in taka:
            taka_point += a[t[0]]

        for a in aoki:
            aoki_point += b[a[0]]

        ans1 = taka_point - aoki_point

        taka = posi[1::2] + nega[::2]
        aoki = posi[::2] + nega[1::2]

        for t in taka:
            taka_point += a[t[0]]

        for a in aoki:
            aoki_point += b[a[0]]

        ans2 = taka_point - aoki_point
        print(max(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N1 = int(input())
A1 = [0] * N
B1 = [0] * N
for i in range(N1):
    A1[i], B1[i] = map(int, input().split())
def solution(N, A, B):
    A_score=[]
    B_score=[]
    for n in range(0, N):
        if n > 0:
            tmp = A
            A = B
            B = tmp
        max_index_list = [i for i, x in enumerate(A) if x == max(A)]
        j = max_index_list[0]
        if len(max_index_list) > 1:
            maxim = 0
            for i in max_index_list:
                if B[i] > maxim:
                    j = i
                    maxim = B[i]
        if n%2==0:
            A_score.append(A[j])
        else:
            B_score.append(A[j])
        A.pop(j)
        B.pop(j)
    return(sum(A_score)-sum(B_score))

print(solution(N1, A1, B1))

Submission status: Runtime Error

Solution code:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))
b=copy.deepcopy(a)





def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)

def remove(a, data,tag):
    if tag:
        tag=0
    else:
        tag=1
    n = len(a)
    first = 0
    last = n - 1

    while first <= last:
        mid = int(first + ((last - first) / 2))

        if a[mid][tag] < data[tag]:
            last = mid - 1
        elif a[mid][tag] > data[tag]:
            first = mid + 1
        else:
            del a[mid]
            return

def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]

        remove(a,tmp,tag)
        remove(b,tmp,not tag)
        tag=not tag
        a,b=b,a

    return pa-pb
    
print(func(a,b))

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import sys
input_ = sys.stdin.readline()
n = int(input_())

points = []
a_point = 0
b_point = 0

for i in range(n):
    p_ = input_().split()
    p = [int(s) for s in p_]
    points.extend([[p[0], p[1]]])

for i in range(n):
    if i % 2 == 0:
        points.sort(key=itemgetter(0))
        a_point += points[0][0]
        points.pop(0)
    else:
        points.sort(key=itemgetter(1))
        b_point += points[0][1]
        points.pop(0)

print(a_point - b_point)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(0, n):
  a.append(list(map(int, input().split())))
b = []
c = []
result = 0
for i in range(0, n):
  b.append(a[i][0] - a[i][1])
  c.append(a[i][1] - a[i][0])
if n % 2 == 0:
  for i in range(0, n/2):
    
    result += max(b)
    maxindb = b.index(max(b))
    del b[maxindb]
    del c[maxindb]
    
    result -= max(c)
    maxindc = c.index(max(c))
    del b[maxindc]
    del c[maxindc]
    
if n % 2 != 0:
  for i in range(0, n//2):
    
    result += max(b)
    maxindb = b.index(max(b))
    del b[maxindb]
    del c[maxindb]
    
    result -= max(c)
    maxindc = c.index(max(c))
    del b[maxindc]
    del c[maxindc]

  result += max(b)
print(result)

Submission status: Runtime Error

Solution code:
from sys import stdin

def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

    disha = sorted(AB)
    dishb = sorted(disha, key=lambda x: x[1])
    taka, aoki = 0, 0
    for i in range(N):
        if i % 2:
            if dishb[-1] == 0:
                dishb.pop(-1)
            aoki += dishb[-1][1]
            j = disha.index(dishb[-1])
            disha[j] = 0
            dishb.pop(-1)
        else:
            if disha[-1] == 0:
                disha.pop(-1)
            taka += disha[-1][0]
            j = dishb.index(disha[-1])
            dishb[j] = 0
            disha.pop(-1)
    print(taka - aoki)

input = lambda: stdin.readline()
main()