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: Wrong Answer

Solution code:
def main(N, A, B, C):
    a, b = 0, 0
    index = list(i[1] for i in sorted(zip(C, range(N)), key=lambda x: x[0], reverse=True))
    t = 0
    for _ in range(N):
        i = index.pop()
        if t == 0:
            a += A[i]
        else:
            b += B[i]
        t += 1
        t %= 2
    print(a - b)


if __name__ == "__main__":
    N = int(input())
    A, B = [], []
    C = []
    for _ in range(N):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append(a+b)
    main(N, A, B, C)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
from operator import itemgetter
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = []
for i in range(N):
    a,b = IL()
    l.append([a,b,a-b])

l.sort(key=itemgetter(2))

dp = [0]*N
dp[0] = 0

chokudai = 0
aoki = 0
for i in range(N):
    if i%2 == 0:
        chokudai += l[i][0]
    else:
        aoki += l[i][1]

print(chokudai-aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()]+[i])
"""d = []
for i in range(n):#h:高さ
    d.append([c[i][1], c[i][0], i])"""
tans = 0
aans = 0
e = []
a = []
b = []
for i in range(2 * n):
    if i < n:
        e.append([c[i][0], i])
        a.append([c[i][0], i])
    else:
        e.append([c[i - n][1], i - n])
        b.append([c[i - n][1], i - n])
#c.sort(reverse=True)
e.sort(reverse=True)

#d.sort(reverse=True)

numset = set()
i = 0
k = 0
wa = 0
wb = 0
while wa < n and wb < n:
    if k % 2 == 0:#t
        while True:
            if a[wa][1] not in numset and b[wb][1] not in numset:
                if c[a[wa][1]][0] - c[b[wb][1]][1] >= c[b[wb][1]][0] - c[a[wa][1]][1]:

                    tans += c[a[wa][1]][0]
                    numset.add(a[wa][1])
                    wa += 1
                    k += 1
                    break
                else:
                    tans += c[b[wb][1]][0]
                    numset.add(b[wb][1])
                    wb += 1
                    k += 1
                    break

            elif a[wa][1] in numset and b[wb][1] not in numset:
                wa += 1
                if wa == n:
                    break
            elif b[wb][1] in numset and a[wa][1] not in numset:
                wb += 1
                if wb == n:
                    break
            else:
                wa += 1
                wb += 1
                if wa == n or wb == n:
                    break
    else:
        while True:
            if a[wa][1] not in numset and b[wb][1] not in numset:
                if c[b[wb][1]][1] - c[a[wa][1]][0] >= c[a[wa][1]][1] - c[b[wb][1]][0]:

                    aans += c[b[wb][1]][1]
                    numset.add(a[wb][1])
                    wb += 1
                    k += 1
                    break
                else:
                    aans += c[a[wa][1]][1]
                    numset.add(a[wa][1])
                    wa += 1
                    k += 1
                    break

            elif a[wa][1] in numset and b[wb][1] not in numset:
                wa += 1
                if wa == n:
                    break
            elif b[wb][1] in numset and a[wa][1] not in numset:
                wb += 1
                if wb == n:
                    break
            else:
                wa += 1
                wb += 1
                if wa == n or wb == n:
                    break
"""while i < 2 * n:
    if k % 2 == 0:#t
        while True:
            if e[i][1] not in numset:
                tans += c[e[i][1]][0]
                numset.add(e[i][1])
                i += 1
                k += 1
                break
            else:
                i += 1
                if i == 2 * n:
                    break
    else:
        while True:
            if e[i][1] not in numset:
                aans += c[e[i][1]][1]
                numset.add(e[i][1])
                i += 1
                k += 1
                break
            else:
                i += 1
                if i == 2 * n:
                    break"""
print(tans -aans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = []
b = []
amb = []
for i in range(n):
    ai,bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    amb.append(abs(ai - bi))

ia = sorted(range(n), key=lambda k: a[k])
ib = sorted(range(n), key=lambda k: b[k])

selected_set = set()
selected_list = []
at = 0
bt = 0
acour = n - 1
bcour = n - 1
while len(selected_set) < n:
    while ia[acour] in selected_set:
        acour -= 1
    while ib[bcour] in selected_set:
        bcour -= 1
    if amb[ia[acour]] >= amb[ib[bcour]]:
        selected = ia[acour]
    else:
        selected = ib[bcour]
    selected_set.add(selected)
    selected_list.append(selected)
for i in range(n):
    selected = selected_list[i]
    if i % 2 == 0:
        at += a[selected]
    else:
        bt += b[selected]

print(at - bt)

Submission status: Wrong Answer

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)

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

    taka_point = 0
    aoki_point = 0

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

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

    print(taka_point - aoki_point)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

N = int(input())
aList = []
bList = []
sa =[]
for i in range(N):
  a,b = map(int, stdin.readline().rstrip().split())
  aList.append(a)
  bList.append(b)
  sa.append(abs(a-b))

sa=np.array(sa)
saSort = np.sort(sa)
saIndex=np.argsort(sa)[-1::-1]
print(sa)
print(saIndex)

score = 0
for i in range (N):
  if i % 2==0:
    score += aList[saIndex[i]]
  else:
    score -= bList[saIndex[i]]

print(score)

Submission status: Wrong Answer

Solution code:
base = int(input())

data = [[0 for i in range(2)] for j in range(base)]

for num in range(base):
    _num = input()
    _num = _num.split()
    data[num][0] = float(_num[0])
    data[num][1] = float(_num[1])


takahashi = 0
aoki = 0

data.sort()
data.reverse()

_num = 0
for num in range(base):
    if(_num == 0):
        takahashi += data[num][0]
        _num = 1
    elif(_num == 1):
        aoki += data[num][1]
        _num = 0

print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = sorted([list(map(int, input().split())) for _ in range(n)])

res = 0
for i in range(n):
    if i % 2 == 0:
        abi = ab.pop(len(ab)-1)
        res += abi[0]
    else:
        minus = 0
        t_shock = 0
        pop_j = 0
        for j in range(len(ab)):
            if minus < ab[j][1]:
                t_minus = ab[j][1]
                if t_shock < ab[j][0]:
                    pop_j = j
        abi = ab.pop(pop_j)
        res -= abi[1]

print(res)
print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[]
takahashi=0
aoki=0
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b,abs(b-a)])
AB.sort(key=lambda AB:(AB[2],AB[1],AB[0]),reverse=True)
for i in range(N):
    if i%2==0:
        takahashi+=AB[i][0]
    else:
        aoki+=AB[i][1]
print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[]
takahashi=0
aoki=0
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b,b-a])
AB.sort(key=lambda AB:(AB[2],AB[1],AB[0]),reverse=True)
for i in range(N):
    if i%2==0:
        takahashi+=AB[i][0]
    else:
        aoki+=AB[i][1]
print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input().strip())
    arr = [0] * N
    for n in range(N):
      A, B = list(map(int, input().split()))
      arr[n] = A + B - A
    
    arr = sorted(arr, reverse=True)
    t = sum(arr[::2])
    a = sum(arr[1::2])
    print(t - a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
dsum = []
for _ in range(N):
    a_tmp,b_tmp = map(int, input().split())
    A.append(a_tmp)
    B.append(b_tmp)
    dsum.append(abs(a_tmp + b_tmp))
A_score = 0
B_score = 0
dsum.sort(reverse=True)
A.sort(key=dict(zip(A, dsum)).get)
B.sort(key=dict(zip(B, dsum)).get)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

ryouri = [list(map(int, input().split())) for _ in range(n)]
score_t = 0
score_a = 0

for i in range(n):
    if i % 2 == 0:
        ryouri = sorted(ryouri, key=lambda x: (x[0]-x[1]))
        score_t += ryouri[0][0]
        ryouri.pop(0)
    else:
        ryouri = sorted(ryouri, key=lambda x: (x[1]-x[0]))
        score_a += ryouri[0][1]
        ryouri.pop(0)
        
print(score_t - score_a)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    c = []
    d = []
    e = []
    
    for i in range(0, n):
        a, b = map(int, input().split())
        c.append(a)
        d.append(b)
        e.append(abs(a - b))
    
    li1, li2 = sorted(e), sorted(range(len(e)), key=lambda k: e[k])
    
    turn = 0
    happy = 0

    for i in range(n - 1, -1, -1):
        now = li1[i]
        if (turn == 0):
            max = 0
            maxKey = 0
            for j in range(i, -1, -1):
                if (now == li1[j] and max < c[li2[j]]):
                    max = c[li2[j]]
                    maxKey = j
                else:
                    li2[i], li2[maxKey] = li2[maxKey], li2[i]
                    break
            happy += c[li2[i]]
        else:
            max = 0
            maxKey = 0
            for j in range(i, -1, -1):
                if (now == li1[j] and max < d[li2[j]]):
                    max = d[li2[j]]
                    maxKey = j
                else:
                    li2[i], li2[maxKey] = li2[maxKey], li2[i]
                    break
            happy -= d[li2[i]]
        turn = (turn + 1) % 2
    print(happy)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [list(map(int,input().split()))+[k] for k in range(N)]

T = sorted(D, key = lambda x: (-x[0],-x[1]))
A = sorted(D, key = lambda x: (-x[1],-x[0]))
U = [1 for k in range(N)]

ans = 0
l = 0
m = 0
for k in range(N):
    if k%2 == 0:
        while U[T[l][2]] == 0:
            l += 1
        ans += T[l][0]
        U[T[l][2]] = 0
    else:
        while U[A[m][2]] == 0:
            m += 1
        ans -= A[m][1]
        U[A[m][2]] = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy
import collections
N = int(input())
A,B = [],[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

AA = collections.deque(numpy.argsort(A)[::-1])
BB = collections.deque(numpy.argsort(B)[::-1])
aans,bans = 0,0
while True:
    try:
        a = AA.popleft()
        aans += A[a]
        if BB[0] == a:
            BB.popleft()
        b = BB.popleft()
        bans += B[b]
        if AA[0] == b:
            AA.popleft()
    except:
        break

print(aans - bans)

Submission status: Wrong Answer

Solution code:
N = int(input())

A_list = []
B_list = []
dif_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)
    dif_list.append(B - A)

my_list = [[dif, a, b] for dif, a, b in zip(dif_list, A_list, B_list)]
my_list.sort(reverse=True)

takahashi_score = 0
aoki_score = 0

for i, list_items in enumerate(my_list):
    a = list_items[1]
    b = list_items[2]
    if i % 2 == 0:
        takahashi_score += a
    else:
        aoki_score += b

print(takahashi_score - aoki_score)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = [], []
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

x = y = 0
for t in sorted(range(n), key=lambda i: a[i] + b[i], reverse=True):
    if t % 2 == 0:
        x += a[t]
    else:
        y += b[t]
print(x - y)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = []
A = []
B = []
m = 1000000000
res = 0
for i in range(n):
    a,b = map(int,input().split())
    diff = a-b
    D.append([diff,i])
    A.append(a)
    B.append(b)
else:
    D.sort()

for i in range(n//2):
    res += A[(D[i][1])]
    res -= B[(D[i+1][1])]
else:
    if n%2 ==1:
        res += A[D[n-1][1]]
    print(res)

Submission status: Wrong Answer

Solution code:
# C 2nd
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
dia,dib = zeros(N),zeros(N)
for i in range(N):
    a,b = getIntList()
#    dia[i] = [abs(a-b),a,b,i]
#    dib[i] = [abs(a-b),b,a,i]
    dia[i] = [a,b,i]
    dib[i] = [b,a,i]
db(dia)
dia.sort()
dia.reverse()
db(dia)
db(dib)
dib.sort()
dib.reverse()
db(dib)
p = 0
eaten = set([])
ia,ib = 0,0
for i in range(N):
    if i%2==0:
        while dia[ia][2] in eaten: ia += 1
        p += dia[ia][0]
        eaten.add(dia[ia][2])
        db(('a',dia[ia][2]))
    else:
        while dib[ib][2] in eaten: ib += 1
        p -= dib[ib][1]
        eaten.add(dib[ib][2])
        db(('b',dib[ib][2]))
print(p)

Submission status: Wrong Answer

Solution code:
from operator import sub


def read():
    N = int(input().strip())
    A = []
    B = []
    for i in range(N):
        a, b = input().strip().split()
        A.append(int(a))
        B.append(int(b))
    return N, A, B


def solve(N, A, B):
    diff_list = list(map(sub, A, B))
    # sort A-B from max to min
    sorted_diff_index = sorted(range(N), key=lambda k: -diff_list[k])
    A_score = 0
    B_score = 0
    for i in range(N):

        # A's turn
        if i % 2 == 0:
            if sorted_diff_index[0] >= sorted_diff_index[-1]:
                k = sorted_diff_index.pop(0)
            else:
                k = sorted_diff_index.pop(-1)
            A_score += A[k]
        # B's turn
        else:
            if sorted_diff_index[0] <= sorted_diff_index[-1]:
                k = sorted_diff_index.pop(-1)
            else:
                k = sorted_diff_index.pop(0)
            B_score += B[k]
    return A_score - B_score

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
print("Enter Data: ")
n = int(input().strip())
array1 = []
array2 = []
for i in range(n):
  inputstr = input().strip()
  array1.append(int(inputstr.split(" ")[0]))
  array2.append(int(inputstr.split(" ")[1]))

s1 = 0
s2 = 0
j = 0
for i in range(n):
  ai = array1.index(max(array1))
  bi = array2.index(max(array2))
  if (array1[ai]-array1[bi]) > (array2[ai]-array2[bi]):
    s1 = s1 + array1[ai]
    array1.pop(ai)
    array2.pop(ai)
  else:
    s1 = s1 + array1[bi]
    array1.pop(bi)
    array2.pop(bi)
  j = j+1
  if j >= n:
    break
  ai = array1.index(max(array1))
  bi = array2.index(max(array2))
  if (array1[ai]-array1[bi]) > (array2[ai]-array2[bi]):
    s2 = s2 + array2[ai]
    array1.pop(bi)
    array2.pop(bi)
  else:
    s2 = s2 + array2[bi]
    array1.pop(ai)
    array2.pop(ai)
  j = j+1
  if j >= n:
    break

print (str(s1-s2))

Submission status: Wrong Answer

Solution code:
n=int(input())
array1=[]
c=[]
for i in range(n):
    a,b=map(int,input().split())
    array1.append([a,b])
array1.sort(reverse=True)    
for i in range(n):
    array1[i].insert(0,i) 
sum1=0
sum2=0
for i in range(n):
    if(i%2==0):
        sum1+=array1[i][1]
    else:
        sum2+=array1[i][2]            
print(sum1-sum2)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import copy
N = int(input())
T = [list(map(int,input().split()))+[k] for k in range(N)]
A = copy.deepcopy(T)

T.sort(key = itemgetter(0,1), reverse = True)
A.sort(key = itemgetter(1,0), reverse = True)

U = [1 for k in range(N)]

ans = 0
l = 0
m = 0
for k in range(N):
    if k%2 == 0:
        while U[T[l][2]] == 0:
            l += 1
        ans += T[l][0]
        U[T[l][2]] = 0
    else:
        while U[A[m][2]] == 0:
            m += 1
        ans -= A[m][1]
        U[A[m][2]] = 0

print(ans)

Submission status: Wrong Answer

Solution code:
base = int(input())
Amax = 0
Bmax = 0
data = [[0 for i in range(2)] for j in range(base)]

for num in range(base):
    _num = input()
    _num = _num.split()
    data[num][0] = int(_num[0])
    data[num][1] = int(_num[1])
    if(data[num][0] > Amax):
        Amax = data[num][0]
    if(data[num][1] > Bmax):
        Bmax = data[num][1]


takahashi = 0
aoki = 0

data.sort()
data.reverse()
_num = 0
for num in range(base):
    if(_num == 0):
        takahashi += data[num][0]
        _num = 1
    elif(_num == 1):
        aoki += data[num][1]
        _num = 0

print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[]
takahashi=0
aoki=0
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b,a-b])
AB.sort(key=lambda AB:(AB[2],AB[1],AB[0]),reverse=True)
for i in range(N):
    if i%2==0:
        takahashi+=AB[i][0]
    else:
        aoki+=AB[i][1]
print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = []
A = []
B = []
m = 1000000000
res = 0
for i in range(n):
    a,b = map(int,input().split())
    diff = a-b
    D.append([diff,i])
    A.append(a)
    B.append(b)
else:
    D.sort()

for i in range(n//2):
    res += A[(D[i][1])]
    res -= B[(D[i+1][1])]
else:
    if n%2 ==1:
        res += A[D[n//2][1]]
    print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

N = int(input())
aList = []
bList = []
sa =[]
for i in range(N):
  a,b = map(int, stdin.readline().rstrip().split())
  aList.append(a)
  bList.append(b)
  sa.append(a-b)

sa=np.array(sa)
saSort = np.sort(sa)
saIndex=np.argsort(sa)[-1::-1]

score = 0
for i in range (N):
  if i % 2==0:
    score += aList[saIndex[i]]
  else:
    score -= bList[saIndex[i]]

print(score)

Submission status: Wrong Answer

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


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


def main():
    # 1文字に省略
    ip = IP()

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

    x = []
    y = []
    for i in range(n):
        x1, y1 = [int(i) for i in sys.stdin.readline().split()]
        x.append(x1)
        y.append(y1)
    x.sort()
    y.sort()
    y.pop(-1)
    y.append(0)
    y.sort()
    
    print(sum(x[i] - y[i] for i in range(n-1, -1, -2)))


main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n =int(input())
takahashi = 0
aoki = 0
a = [[int(i) for i in input().split()] for i in range(n)] 
a2 = sorted(a, key=lambda x: x[0])
a3 = sorted(a, key=lambda x: x[1])
d = deque(a2)
d2 = deque(a3)
start = 0
for i in range(n):
 if start%2 == 0:
  a,b =d.pop()
  d2.remove([a,b])
  takahashi += a
  #print(d)
 if start %2 == 1:
  a,b = d2.pop()
  d.remove([a,b])
  aoki += b
 start += 1
print(takahashi -aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [[] for i in range(n)]
A, B = 0, 0
for i in range(n):
    l[i] = list(map(int, input().split()))
    l[i].append(l[i][0]-l[i][1])
l.sort(key = lambda x: (x[2], -x[0]))
for i in range(n):
    if(i%2 == 0):
        A += l[i][0]
    else:
        B += l[i][1]
print(A - B)

Submission status: Wrong Answer

Solution code:
N = int(input())
ab = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append((i, a, b))

check = [False for _ in range(N)]

taka = []

for i in range(N):
    _, a, b = ab[i]
    if a >= b:
        taka.append((i, a, a, b))
    else:
        taka.append((i, b, a, b))
aoki = []
for i in range(N):
    _, a, b = ab[i]
    if b >= a:
        aoki.append((i, b, b, a))
    else:
        aoki.append((i, a, b, a))

taka = sorted(taka, key=lambda x:(-x[1], -x[2], x[3]))
aoki = sorted(aoki, key=lambda x:(-x[1], -x[2], x[3]))

ans = 0
i = 0
j = 0
for k in range(N):
    if k % 2 == 0:
        t = taka[i]
        while check[t[0]]:
            i += 1
            t = taka[i]
        ans += t[2]
        check[t[0]] = True
        i += 1
    else:
        a = aoki[j]
        while check[a[0]]:
            j += 1
            a = aoki[j]
        ans -= a[2]
        check[a[0]] = True
        j += 1
print(ans)

Submission status: Wrong Answer

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


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


def main():
    # 1文字に省略
    ip = IP()

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

    x = []
    y = []
    for i in range(n):
        x1, y1 = [int(i) for i in sys.stdin.readline().split()]
        x.append(x1)
        y.append(y1)
    x.sort()
    y.sort()
    y.pop(-1)
    y.append(0)
    y.sort()
    k = l = 0
    for i in range(n-1, -1, -2):
        k += x[i]
        l += y[i]
    print(k - l)


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * N
B = [0] * N
y = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

A_score=[]
B_score=[]
for n in range(0, N):
    if n > 0:
        tmp = A
        A = B
        B = tmp
    print(A, B)
    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)
print(sum(A_score)-sum(B_score))

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [[int(_) for _ in input().split()] for __ in range(n)]
s = [[sum(e), i] for i, e in enumerate(ab)]
s.sort()
t = 0

for j, x in enumerate(s):
    t += ab[x[1]][0] if j % 2 == 0 else -ab[x[1]][1]
    
print(t)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter

taka = 0
ao = 0

n=int(input())
string_list=[list(map(int,input().split())) for i in range(n)]

for i, temp in enumerate(string_list):
  string_list[i].append(string_list[i][0] - string_list[i][1])

temp = sorted(string_list, key=itemgetter(2), reverse=True)

for i, temp in enumerate(temp):
  if i % 2 == 0:
    taka += temp[0]
  else:
    ao += temp[1]

print(taka - ao)

Submission status: Wrong Answer

Solution code:
import numpy as np


def main():
    N = int(input())
    A = np.array([])
    B = np.array([])
    for i in range(0, N):
        a, b = map(int, input().split())
        A = np.append(A, [a])
        B = np.append(B, [b])
    
    # 自分に一番良い手と相手にとって一番良い手を考える
    # 自分にとって一番良い手が複数ある場合、その中で相手が一番良い手を選ぶ
    # 自分にとって一番良い手が１つの場合、相手にとって一番良い手との比較をして、差が大きい方を選ぶ
    # 自分にとって良いてと相手にとっていい手が同じ場合(相手にとっていい手が複数ある場合も)、それを選ぶ
    sub(N, A, B)


def sub(N, A, B):
    takahashi = 0
    aoki = 0
    # 足し算して一番大きいところからとる
    sum_AB = A + B
    print(A, B)
    for i in range(1, N + 1):
        max_idx = np.argmax(sum_AB)
        print(sum_AB, max_idx)
        if i % 2 == 1:
            takahashi += A[max_idx]
        else:
            aoki += B[max_idx]
        sum_AB[max_idx] = -1

    print(takahashi - aoki)



main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
i_N=int(input())
A_B=[]
for _ in range(i_N):
  t=[int(x) for x in input().split()]
  A_B+=[[t[0],t[1],t[0]-t[1]]]
A_B.sort(key=itemgetter(2))
A_B.sort(key=itemgetter(1))
A_B.sort(key=itemgetter(0))
print(sum([x[0] for i,x in enumerate(A_B) if i%2==0])-sum([x[1] for i,x in enumerate(A_B) if i%2==1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = sorted([list(map(int, input().split())) for _ in range(n)])

res = 0
for i in range(n):
    if i % 2 == 0:
        abi = ab.pop(len(ab)-1)
        res += abi[0]
    else:
        abi = ab.pop(len(ab)-1)
        res -= abi[1]

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []

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

A_orig = A[:]

diff = []

for i in range(N):
    diff.append(A[i]-B[i])
    
taka = 0
aoki = 0

for i in range(N):
    if i % 2==0:
        di = diff.index(max(diff))
        taka += A[di]
        diff.pop(di)
        A.pop(di)
        B.pop(di)
    else:
        di = diff.index(min(diff))
        aoki -= B[di]
        diff.pop(di)
        A.pop(di)
        B.pop(di)
        
print(taka+aoki)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
i_N=int(input())
A_B=[]
for _ in range(i_N):
  t=[int(x) for x in input().split()]
  A_B+=[[t[0],t[1],t[0]-t[1]]]
A_B.sort(key=itemgetter(2))
print(sum([x[0] for i,x in enumerate(A_B) if i%2==0])-sum([x[1] for i,x in enumerate(A_B) if i%2==1]))

Submission status: Wrong Answer

Solution code:
# input
n = int(input())
ab = sorted([list(map(int, input().split())) for _ in range(n)])

res = 0
for i in range(n):
    if i % 2 == 0:
        abi = ab.pop(len(ab)-1)
        res += abi[0]
    else:
        abi = ab.pop(len(ab)-1)
        res -= abi[1]
    print(abi)

print(res)

Submission status: Wrong Answer

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)
for i in range(n):
    if i%2 == 0:
        ans += li[i][1]
    if i%2 == 1:
        ans -= li[i][2]

print(ans)