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:
n = int(input())
a = []
b = []
ab = []
for i in range(n):
    ai,bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    ab.append(ai-bi)

il = sorted(range(n), key=lambda k: ab[k])

at = 0
bt = 0
for i in range(n):
    if i % 2 == 0:
        at += a[il[i]]
    else:
        bt += b[il[i]]

print(at - bt)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import heapq
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
A = []
B = []
for i in range(n):
    a, b = LI()
    A.append((a, b, i))
    B.append((b, a, i))
A.sort()
B.sort()

# print(*A, sep='\n')
# print(*B, sep='\n')

used = set()
score_a, score_b = 0, 0
for i in range(n):
    if i % 2:
        while B:
            b, a, j = B.pop()
            if j not in used:
                break
        # print('b', b, j)
        score_b += b
        used.add(j)

    else:
        while A:
            a, b, j = A.pop()
            if j not in used:
                break
        # print('a', a, j)
        score_a += a
        used.add(j)

print(score_a - score_b)

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])
for i in range(n):
    c=array1[i][0]-array1[i][1]
    array1[i].insert(0,c) 
array1.sort()
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 sys import stderr, setrecursionlimit
from collections import deque
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getInt()
dif0 = []
difisnot0 = []
for i in range(n):
    a, b = getInts()
    if a == b:
        dif0.append(a)
    else:
        difisnot0.append((a,b,a-b))

dif0.sort()
dif_not0 = deque(sorted(difisnot0, key=lambda x:x[2]))

takahashi = 0
aoki = 0

while len(dif0) >= 2:
    dish = dif0.pop()
    takahashi += dish
    dish = dif0.pop()
    aoki += dish
if len(dif0) == 1:
    takahashi += dif0[0]

while len(dif_not0) >= 2:
    dish = dif_not0.pop()
    takahashi += dish[0]
    dish = dif_not0.popleft()
    aoki += dish[1]
if len(dif_not0) == 1:
    dish = dif_not0.pop()
    takahashi += dish[0]

print(takahashi - aoki)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [0 for i in range(N)]
B = [0 for i in range(N)]

for i in range(N):
  A[i], B[i] = [int(j) for j in input().split()]

takahashi = 0
aoki = 0

while len(A) > 0:
  index = A.index(max(A))
  takahashi += A[index]
  A.pop(index)
  B.pop(index)

  if len(A) == 0:
    break

  index = B.index(max(B))
  aoki += B[index]
  A.pop(index)
  B.pop(index)

print(takahashi - aoki)

Submission status: Wrong Answer

Solution code:
def solve(N, fortune):
  fortune.sort(key=lambda f: f[0] - f[1])
  value = 0
  for n in range(N):
    value = value + (1 if n % 2 == 0 else -1) * fortune[n][n % 2]
  return value

N = int(input())
fortune = [tuple(map(int, input().split())) for _ in range(N)]
print(solve(N, fortune))

Submission status: Wrong Answer

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


diff = [[ryouri[i][1] - ryouri[i][0], i] for i in range(n)]
diff = sorted(diff, key=lambda x: x[1])

score_t = 0
score_k = 0

for i, x in enumerate(diff):
    if i % 2 == 0:
        score_t += ryouri[x[1]][0]
    else:
        score_k += ryouri[x[1]][1]
        
print(score_t - score_k)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
for i in range(n):lis[i].append(lis[i][0]-lis[i][1])

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

for i in range(n):
    if i % 2 == 0:
        takahashi += lis[i][0]
    else:
        aoki += lis[i][1]
ans = takahashi-aoki

takahashi = 0
aoki = 0

lis.sort(key=lambda  x:x[0],reverse=True)
for i in range(n):
    if i % 2 == 0:
        takahashi += lis[i][0]
    else:
        aoki += lis[i][0]
ans = min(ans,takahashi-aoki)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
cuisine = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x: (-x[0],-x[1]))
taka = 0
aoki = 0
ind = 0
for c in cuisine:
  if(ind%2 == 0):
    taka += c[0]
  else:
    aoki += c[1]
  ind += 1
print(taka - aoki)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, AB):
    
    t = []
    for a, b in AB:
        t.append((a-b, a, b))
    
    t.sort()
    # error_print(t)
    A = 0
    B = 0
    for i, (_, a, b) in enumerate(t):
        if i % 2 == 0:
            A += a
        else:
            B += b
    return A- B


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()

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)

takahashi = list(sorted(range(n), key=lambda dish: (b[dish], a[dish]), reverse=True))
aoki = list(sorted(range(n), key=lambda dish: (a[dish], b[dish]), reverse=True))

who = True
history = set()
i = j = x = y = 0
for _ in range(n):
    if who:
        while i in history: i += 1
        x += a[i]
        history.add(i)
    else:
        while j in history: j += 1
        y += b[j]
        history.add(j)
    who = not who

print(x - y)

Submission status: Wrong Answer

Solution code:
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]
src.sort(key=lambda x:x[1])

a = b = 0
for i,(x,y) in enumerate(reversed(src)):
    if i%2:
        b += y
    else:
        a += x
print(a-b)

Submission status: Wrong Answer

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

C = []
D = []
i = 0

for a, b in A:
    C.append((a, b, i))
    D.append((b, a, i))
    i += 1

C.sort()
D.sort()

used = [False] * n
ans = 0

for i in range(n):
    if i % 2 == 0:
        while used[D[-1][2]]:
            D.pop()
        ans += D[-1][1]
        used[D[-1][2]] = True
        D.pop()
    else:
        while used[C[-1][2]]:
            C.pop()
        ans -= C[-1][1]
        used[C[-1][2]] = True
        C.pop()

print(ans)

Submission status: Wrong Answer

Solution code:
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy as np
import scipy

from collections import defaultdict
from pprint import pprint

N = int(input())
A = []
B = []
diff = []
points = [] # points[i] = [A,B,diff]
for i in range(N):
    a,b = [int(x) for x in input().split(" ")]
    points.append([a,b,a-b])

sorted_points = sorted(points, key=lambda x: x[2], reverse=False)
point_a, point_b = 0,0

turn_A = True
for p in sorted_points:
    if turn_A:
        point_a += p[0]
        turn_A = False
    else:
        point_b += p[1]
        turn_A = True

print(point_a - point_b)

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 = []
for i in range(2 * n):
    if i < n:
        e.append([c[i][0], i])
    else:
        e.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
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:
N=int(input())

Takahashi=[]
Aoki=[]

for i in range(N):
  A,B=map(int,input().split())
  if A>B:
    symbol='p'
  else:
    symbol='m'
  Takahashi.append((abs(A-B),B,symbol,A))

Takahashi=sorted(Takahashi,key=lambda x: (x[0],x[1]),reverse=True)

#print(Takahashi)

answer=0
Asum=0
Bsum=0
for i,name in enumerate(Takahashi):
  if i%2==0:
    Asum+=name[3]
  else:
    Bsum+=name[1]

  
      
print(Asum-Bsum)

Submission status: Wrong Answer

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

div = [[abs(ab[i][1] - ab[i][0]), ab[i][0], ab[i][1]] for i in range(n)]
div = sorted(div, key=lambda x: x[0], reverse=True)

counta = 0
countb = 0
for i in range(n):
    if i % 2 == 0:
        counta += div[i][1]
    else:
        countb += div[i][2]

print(counta - countb)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [-1] * N
for i in range(N):
    ai, bi = [int(_) for _ in input().split()]
    C[i] = (ai - bi, ai, bi)

C.sort()

result = 0
for i, ci in enumerate(C):
    if i % 2 == 0:
        result += ci[1]
    else:
        result -= ci[2]

print(result)

Submission status: Wrong Answer

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

l = sorted(dish)

t=a = 0
for i, (_, (a_i, b_i)) in enumerate(l):
    if i % 2 == 0:
        #takahashi
        t += a_i
    else:
        a += b_i

print(t-a)

Submission status: Wrong Answer

Solution code:
N = int(input())

An = []
Bn = []

results = dict()
for i in range(N):
    a, b = map(int, input().split())
    hyoka = (a, b)
    wa = a + b
    if wa in results:
        results[wa].append(hyoka)
    else:
        results[wa] = [hyoka]

sa = 0
turn = 1
for _, v in sorted(results.items()):
    for hyoka in v:
        if turn % 2 == 1:
            sa += hyoka[0]
        else:
            sa -= hyoka[1]
        turn += 1
print(sa)

Submission status: Wrong Answer

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

div = [[abs(ab[i][1] - ab[i][0]), ab[i][0], ab[i][1]] for i in range(n)]
div = sorted(div, key=lambda x: x[0], reverse=True)

print(div)
counta = 0
countb = 0
for i in range(n):
    if i % 2 == 0:
        counta += div[i][1]
    else:
        countb += div[i][2]

print(counta - countb)

Submission status: Wrong Answer

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

T = []
A = []
eaten = [False]*N

happiness1 = sorted(happiness, key=lambda x:(x[0], x[1]))
happiness2 = sorted(happiness, key=lambda x:(x[1], x[0]))

for i in range(N):
    if i % 2 == 0: # Takahashi
        while True:
            a, _, idx = happiness1.pop()
            if not eaten[idx]:
                eaten[idx] = True
                T.append(a)
                break
    else: # Aoki
        while True:
            _, b, idx = happiness2.pop()
            if not eaten[idx]:
                eaten[idx] = True
                A.append(b)
                break

print(sum(T) - sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve(n, xs, ys):
    dp = [0] * (n + 1)
    dp[n] = 0
    for i in range(n + 1)[::-1]:
        if i == n:
            continue
        elif i % 2 == 0:
            dp[i] = xs[i] + dp[i + 1]
        else:
            dp[i] = -ys[i] + dp[i + 1]
    return dp[0]


def main():
    n = int(input())
    xs = [0] * n
    ys = [0] * n
    for i in range(n):
        xs[i], ys[i] = (int(z) for z in input().split())
    res = solve(n, xs, ys)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

n =int(input())

# n行の複数列ある数値を二次元配列へ。x[n][2]
ab = [[int(i) for i in input().split()] for i in range(n)] 

#print(ab)

ab.sort(key = lambda x: x[1]-x[0])

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    AB = iml(N)
    sAB = sorted(AB, reverse=True)
    takahashi = sum([s[0] for s in sAB[::2]])
    aoki = sum([s[1] for s in sAB[1::2]])
    return takahashi - aoki


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([0 for i in range(N)], np.int64)
B = np.array([0 for i in range(N)], np.int64)
TA = 0
AO = 0
for i in range(N):
    A[i], B[i] = map(int, input().split())
AmB = np.array([A[i] - B[i] for i in range(N)])
sort_index = A.argsort()[::-1]
A = A[sort_index]
B = B[sort_index]
AmB = AmB[sort_index]
index = np.argsort(AmB)
print(np.sum(A[index[::2]]) - np.sum(B[index[1::2]]))

Submission status: Wrong Answer

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

T = []
A = []
eaten = [False]*N

happiness1 = sorted(happiness, key=lambda x:(x[0], x[1]))
happiness2 = sorted(happiness, key=lambda x:(x[1], x[0]))

print(happiness1)
print(happiness2)

for i in range(N):
    if i % 2 == 0: # Takahashi
        while True:
            a, _, idx = happiness1.pop()
            if not eaten[idx]:
                eaten[idx] = True
                T.append(a)
                break
    else: # Aoki
        while True:
            _, b, idx = happiness2.pop()
            if not eaten[idx]:
                eaten[idx] = True
                A.append(b)
                break

print(sum(T) - sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(n):
    a[i],b[i]=map(int,input().split())
    x[i]=a[i]-b[i]
    
s=sorted(x,reverse=True)
nu=n//2
mod=n%2

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

    

print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n=int(input())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))
data=sorted(data,key=lambda x:(-max(x[0],x[1]),-(x[0]+x[1])))
a=0
b=0
for i in range(n):
    if i%2==0:
        a+=data[i][0]
    else:
        b+=data[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, max(a, b)))

item = sorted(ab, key=lambda x: (-x[3], -x[2]))
check = [False for _ in range(N)]

ans = 0
for i in range(N):
    if i % 2 == 0:

        ans += item[i][1]

    else:
        ans -= item[i][2]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]

P0 = sorted(P, key=lambda p: - p[0] - p[1])

ret = 0

for i, p in enumerate(P):
    if i % 2 == 0:
        ret += p[0]
    else:
        ret -= p[1]

print(ret)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
C = []
A,B = [],[]
for i in range(N):
    a,b = list(map(int,input().split()))
    A.append(a)
    B.append(b)
    # print("A,B:",A,B)
    C.append(a-b)
# print(C)

arrA,arrB,arrC = np.array(A).astype(np.int64),np.array(B).astype(np.int64),np.array(C)
ordC = np.argsort(arrC)[::-1]
# print(ordC)
print(sum(arrA[ordC][::2]) - sum(arrB[ordC][1::2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
for i in range(n):lis[i].append(lis[i][0]-lis[i][1])

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

for i in range(n):
    if i % 2 == 0:
        takahashi += lis[i][0]
    else:
        aoki += lis[i][1]
print(takahashi-aoki)

Submission status: Wrong Answer

Solution code:
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy as np
import scipy

from collections import defaultdict
from pprint import pprint

N = int(input())
A = []
B = []
diff = []
points = [] # points[i] = [A,B,diff]
for i in range(N):
    a,b = [int(x) for x in input().split(" ")]
    points.append([a,b,a-b])

sorted_points = sorted(points, key=lambda x: x[2], reverse=False)
print(sorted_points)
point_a, point_b = 0,0

turn_A = True
for p in sorted_points:
    if turn_A:
        point_a += p[0]
        turn_A = False
    else:
        point_b += p[1]
        turn_A = True

print(point_a - point_b)

Submission status: Wrong Answer

Solution code:
N=int(input())
CAB=[]
for i in range(N):
	x,y=list(map(int,input().split()))
	CAB.append([x+y,x,y])

CAB.sort()

point=0
for i in range(N):
	if i%2==0: point+=CAB[i][1]
	else: point-=CAB[i][2]

print(point)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import heapq
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
A = []
B = []
for i in range(n):
    a, b = LI()
    A.append((a, i))
    B.append((b, i))
A.sort()
B.sort()

used = set()
score_a, score_b = 0, 0
for i in range(n):
    if i % 2:
        while B:
            b, j = B.pop()
            if j not in used:
                break
        score_b += b
        used.add(j)

    else:
        while A:
            a, j = A.pop()
            if j not in used:
                break
        score_a += a
        used.add(j)

print(score_a - score_b)

Submission status: Wrong Answer

Solution code:
# C
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()
d = zeros(N)
for i in range(N):
    a,b = getIntList()
    d[i] = [a-b,a,b]
db(d)
d.sort()
db(d)
p = 0
for i in range(N):
    if i%2==0: p += d[i][1]
    else: p -= d[i][2]
print(p)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
aa = []
bb = []
for i in range(n):
  ai,bi = list(map(int, input().split()))
  a.append(ai)
  b.append(bi)
  if ai == bi:
    aa.append(ai+bi)
    bb.append(ai+bi)
  elif ai > bi:
    aa.append(0)
    bb.append(ai+bi)
  else:
    aa.append(bi+ai)
    bb.append(0)
alice = 0
bob = 0
for i in range(n):
  if i % 2 == 0:
    w = aa.index(max(aa))
    alice += a[w]
    aa[w] = 0
    bb[w] = 0
  else:
    w = bb.index(max(bb))
    aa[w] = 0
    bb[w] = 0
print(alice-bob)

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)

takahashi = list(sorted(range(n), key=lambda dish: (b[dish], a[dish])))
aoki = list(sorted(range(n), key=lambda dish: (a[dish], b[dish])))

who = True
history = set()
i = j = x = y = 0
for _ in range(n):
    if who:
        while i in history: i += 1
        x += a[i]
        history.add(i)
    else:
        while j in history: j += 1
        y += b[j]
        history.add(j)
    who = not who

print(x - y)

Submission status: Wrong Answer

Solution code:
N = int( input())
SA = [(0,0,0)]*N
SB = [(0,0,0)]*N
A = [0]*N
B = [0]*N
C = [0]*N
for i in range(N):
    a, b = map( int, input().split())
    A[i] = a
    B[i] = b
    SA[i] = (-a+b,-a,i)
    SB[i] = (b-a,-b,i)
SA.sort()
SB.sort()
ansa = 0
ansb = 0
a = 0
b = 0
for i in range(N):
    if i%2 == 0:
        while 1:
            _,_,j = SA[a]
            if C[j] == 0:
                ansa += A[j]
                C[j] = 1
                a += 1
                break
            else:
                a += 1
    else:
        while 1:
            _,_,j = SB[b]
            if C[j] == 0:
                ansb += B[j]
                C[j] = 1
                b += 1
                break
            else:
                b += 1
print( ansa - ansb)

Submission status: Wrong Answer

Solution code:
N = int(input())

num_dict = {}
A_list = []
B_list = []
sum_list = []
ans = 0

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

sum_list.sort()

for i in range(N):
	point = sum_list.pop()
	num = num_dict[point]
	if i%2 == 0:
		ans += A_list[num]
	else:
		ans -= B_list[num]

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

T = []
A = []
eaten = [False]*N

happiness1 = sorted(happiness, key=lambda x:(x[0], x[1]))
happiness2 = sorted(happiness, key=lambda x:(x[1], x[0]))

for i in range(N):
    if i % 2 == 0: # Takahashi
        while True:
            a, _, idx = happiness1.pop()
            if not eaten[idx]:
                eaten[idx] = True
                T.append(a)
                break
    else: # Aoki
        while True:
            _, b, idx = happiness1.pop()
            if not eaten[idx]:
                eaten[idx] = True
                A.append(b)
                break

print(sum(T) - sum(A))

Submission status: Wrong Answer

Solution code:
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy as np
import scipy

from collections import defaultdict
from pprint import pprint

N = int(input())
A = []
B = []
diff = []
points = [] # points[i] = [A,B,diff]
for i in range(N):
    a,b = [int(x) for x in input().split(" ")]
    points.append([a,b,a-b])

sorted_points = sorted(points, key=lambda x: x[2], reverse=True)

point_a, point_b = 0,0

turn_A = True
for p in sorted_points:
    if turn_A:
        point_a += p[0]
        turn_A = False
    else:
        point_b += p[1]
        turn_A = True

print(point_a - point_b)

Submission status: Wrong Answer

Solution code:
N = int( input())
SA = [(0,0,0)]*N
SB = [(0,0,0)]*N
A = [0]*N
B = [0]*N
C = [0]*N
for i in range(N):
    a, b = map( int, input().split())
    A[i] = a
    B[i] = b
    SA[i] = (-a+b,-a,i)
    SB[i] = (b-a,-b,i)
SA.sort()
SB.sort()
ansa = 0
ansb = 0
a = 0
b = 0
for i in range(N):
    if i%2 == 0:
        while 1:
            _,_,j = SA[a]
            if C[j] == 0:
                ansa += A[j]
                C[j] = 1
                a += 1
                break
            else:
                a += 1
    else:
        while 1:
            _,_,j = SB[i]
            if C[j] == 0:
                ansb += B[j]
                C[j] = 1
                b += 1
                break
            else:
                b += 1
print( ansa - ansb)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


def main():
    n = get_int()
    A = []
    B = []
    for _ in range(n):
        a, b = get_int_list()
        A.append(a)
        B.append(b)

    takahashi = OrderedDict()
    aoki = OrderedDict()
    for i, v in enumerate(sorted(A)):
        takahashi[i] = v
    for i, v in enumerate(sorted(B)):
        aoki[i] = v
    ret = 0
    for i in range(n):
        if i % 2 == 0:
            j, v = takahashi.popitem(last=True)
            ret += v
            aoki.move_to_end(j, last=False)
        else:
            j, v = aoki.popitem(last=True)
            ret -= v
            takahashi.move_to_end(j, last=False)
    print(ret)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
su = []
for i in range(N):
    a, b = (int(i) for i in input().split())
    A.append(a)
    B.append(b)
    su.append( (a + b, i) )
su.sort()

ans = 0
for i in range(N):
    ind = su[i][1]
    if i%2 == 0:
        ans += A[ind]
    else:
        ans -= B[ind]

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
ab = []

for i in range(n):
    ab.append(list(map(int, input().split())))

ab = sorted(ab, key=itemgetter(0,1), reverse=True)

a = b = 0

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split(" "))) for i in range(N)]

ABC = [[a,b,a+b]for a,b in AB]
ABC = sorted(ABC, key=itemgetter(2))
ans = 0
flag = True
for a,b,c in ABC:
    if flag:
        ans += a
    else:
        ans -= b
    flag = not flag
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
d = [t[0] - t[1] for t in ab]

o = list(range(n))
o.sort(key=lambda x: d[x])

sol = 0
for i in o:
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

print(sol)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
L = []
for i in range(N):
  L.append(raw_input())
A = []
B = []
for i in range(N):
    # print(L[i])
    L[i] = L[i].split()
for i in range(N):
    A.append(L[i][0])
    B.append(L[i][1])
time = 0
countA = 0
countB = 0
# print(max(A))
for i in range(N):
    if time %2 ==0:
        countA += int(max(A))
        point = A.index(max(A))
        A.pop(point)
        B.pop(point)
    else:
        countB += int(max(B))
        point = B.index(max(B))
        A.pop(point)
        B.pop(point)
    time += 1
result = countA - countB
print(result)

Submission status: Wrong Answer

Solution code:
#A
"""
n, a, b = map(int, input().split())
ab = n / 2
ansa = min(a, b)
ansb = max((a+b)-n, 0)
print(ansa,ansb)
"""

#B
"""
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    bf = [a[i], b[i], c[i]]
    bf = set(bf)
    ans += len(bf) - 1
print(ans)
"""

#C 
n = int(input())
ab = []
aba = []
abb = []
for i in range(n):
    a,b = map(int, input().split())
    ab.append([a + b, i])
    aba.append(a)
    abb.append(b)
ab.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += aba[ab[i][1]]
    else:
        ans -= abb[ab[i][1]]
print(ans)