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:
import numpy as np

N = int(input())
Alist = []
Blist = []
sumlist = []

for i in range(N):
    a,b = map(int,input().split())
    Alist.append(a)
    Blist.append(b)
    sumlist.append(a+b)

sumlist = np.sort(sumlist)
sumlist = sumlist[-1::-1]
index = np.argsort(sumlist)
counter = 0
takahasi = 0
aoki = 0

for i in range(N):
    if counter == 0:
        takahasi += Alist[index[i]]
        sumlist[i] = 0
        counter = 1
        continue
    if counter == 1:
        aoki += Blist[index[i]]
        sumlist[i] = 0
        counter = 0
        continue

print(takahasi-aoki)

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))
    else:
        taka.append((i, ab[i][1]))
aoki = []
for i in range(N):
    _, a, b = ab[i]
    if b >= a:
        aoki.append((i, b))
    else:
        aoki.append((i, ab[i][2]))

taka.sort(reverse=True)
aoki.sort(reverse=True)

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[1]
        check[t[0]] = True
        i += 1
    else:
        a = aoki[j]
        while check[a[0]]:
            j += 1
            a = aoki[j]
        ans -= a[1]
        check[a[0]] = True
        j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

A=[]
B=[]
f = [0 for i in range(N)]
for i in range(N):
    a,b = map(int,input().split())
    A.append([a,b,i])
    B.append([b,a,i])
A.sort(key=lambda x:x[1],reverse=True)
A.sort(key=lambda x:x[0],reverse=True)
B.sort(key=lambda x:x[1],reverse=True)
B.sort(key=lambda x:x[0],reverse=True)

ai=0
bi=0
ans=0
for i in range(N):
    while f[A[ai][2]]==1:
        ai+=1
    while f[B[bi][2]]==1:
        bi+=1
    amax,bm,aind = A[ai]
    bmax,am,bind = B[bi]
    if i%2==0:
        if amax-bm > am-bmax:
            ans+=amax
            f[aind]=1
        else:
            ans+=am
            f[bind]=1
    else:
        if bm-amax > bmax-am:
            ans-=bm
            f[aind]=1
        else:
            ans-=bmax
            f[bind]=1
print(ans)

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,0,0]  for i in range(n+2)]

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

counta=0
for i in range(nu):
    counta+=x[i*2][1]
 #   print(x[i*2+1][1])
    counta-=x[i*2+1][2]
 #   print(x[i*2+1][2])

if mod==1:
    counta+=x[2*nu][1]
   # print(x[2*nu][1])
    

    

print(counta)

Submission status: Wrong Answer

Solution code:
n = int(input())
res = [0 for i in range(n)]
for j in range(n):
    a, b = (int(i) for i in input().split())
    res[j] = a-b
tak = 0
she = 0
res = sorted(res)
for i in range(n):
    if i & 1 == 1:
        she += abs(res[i])
    else:
        tak += abs(res[i])
print(abs(she-tak))

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 input().split()]
        x.append(x1)
        y.append(y1)
    x.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 = []
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, a - b, a, b) )
su.sort()

cc = 0
for i in range(N):
    if i < N-1 and su[i][0] == su[i+1][0]:
        cc += 1
    else:
        if cc:
            temp = []
            for j in range(i-cc, i+1):
                temp.append(su[j])
            temp2 = []
            for j in range(i-cc, i+1):
                if j % 2 == 0:
                    temp2.append(temp.pop())
                else:
                    temp2.append(temp.pop(0))
            for j in range(i-cc, i+1):
                su[j] = temp2[j-(i-cc)]
            cc = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

###### input ######
n = int(input())
taka = []
aoki = []
for i in range(n):
  t,a= map(int,input().split())
  taka.append(t)
  aoki.append(a)

###### main ######
res = 0
for i in range(n):
  if i % 2 == 0: # turn TAKAHASHI
    if max(taka) < max(aoki):
      tmp = aoki.index(max(aoki))#[0]
    else:
      tmp = taka.index(max(taka))#[0]
    print(tmp)
    res+= taka[tmp]
    taka[tmp] = 0
    aoki[tmp] = 0

  else:
    if max(taka) > max(aoki):
      tmp = taka.index(max(taka))#[0]
    else:
      tmp = aoki.index(max(aoki))#[0]  
    print(tmp)
    res -= aoki[tmp]
    taka[tmp] = 0
    aoki[tmp] = 0

print(res)

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()))
    #print(l)
    l[i].append(l[i][0]-l[i][1])
l.sort(key = lambda x: (x[2], -x[0], -x[1]))
for i in range(n):
    if(i%2 == 0):
        #print(l)
        A += l[i][0]
    else:
        #print(l)
        B += l[i][1]
print(A - B)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def select(list_, selected_set):
    while True:
        s = list_.pop()
        if not s[0] in selected_set:
            return s


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

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

flag = True
list_a = sorted(ab, key=lambda x: (x[1], x[2]))
list_b = sorted(ab, key=lambda x: (x[2], x[1]))
a = 0
b = 0
selected = set()
for _ in range(n):
    s = None
    if flag:
        s = select(list_a, selected)
        a += s[1]
    else:
        s = select(list_b, selected)
        b += s[2]
    selected.add(s[0])

    flag = not(flag)

print(a - b)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_items = sorted(
  ab,
  key = lambda x: (x[0], x[1]),
  reverse=True
)
t=0
a=0
for i,v in enumerate(sorted_items):
    if i%2==0:
        t+=v[0]
    else:
        a+=v[1]
print(t-a)

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([c,-a,-b])
A.sort()
ao=0
t=0
for j in range(N):
    if j%2==0:
        ao+=-1*A[j][1]
    else:
        t+=-1*A[j][2]
print(ao-t)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
B = []
dif = []
for i in range(N):
    a, b = [int(i) for i in input().split()]
    dif.append(a-b)
    A.append(a)
    B.append(b)

count1 = 0
count2 = 0

def fa():
    if max(dif) > 0 or min(dif) < 0:
        if max(dif) > -min(dif):
            index = dif.index(max(dif))
        else:
            index = dif.index(min(dif))
    else:
        index = A.index(max(A))

    dif.pop(index)
    B.pop(index)
    return A.pop(index)

def fb():
    if max(dif) > 0 or min(dif) < 0:
        if max(dif) < -min(dif):
            index = dif.index(max(dif))
        else:
            index = dif.index(min(dif))
    else:
        index = A.index(max(A))

    dif.pop(index)
    A.pop(index)
    return B.pop(index)

for i in range(N//2):
    count1 += fa()
    count2 += fb()

if len(A) > 0:
    count1 += fb()

print(count1 - count2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a,b = [],[]
A = 0
B = 0
c = []
for i in range(n):
  c.append(i)
for i in range(n):
  s,t = map(int, input().split())
  a.append(s)
  b.append(t)
for i in range(n):
  if i % 2 == 0:
    d = max(a)
    c.pop(a.index(d))
    b.pop(a.index(d))
    a.pop(a.index(d))
    A += d
  else:
    d = max(b)
    c.pop(b.index(d))
    a.pop(b.index(d))
    b.pop(b.index(d))
    B += d
print(A-B)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A, B = zip(*AB)
ABC = [[A[i], B[i], A[i]+B[i]] for i in range(N)]
ABC.sort(key=itemgetter(2, 0, 1), reverse=True)
ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += A[i]
    else:
        ans -= B[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
AB=np.empty((N,2))
sum=np.zeros(N)

for i in range(N):
    AB[i]=list(map(int,input().split()))
    sum[i]=AB[i][0]+AB[i][1]
lis = np.argsort(sum)
taka=0
aoki=0
for i in lis:
    if i%2==0:
        taka+=AB[lis[i]][0]
    else:
        aoki+=AB[lis[i]][1]

print(int(taka-aoki))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[[i]+list(map(int,input().split())) for i in range(n)]

a=sorted(l,key=lambda x:(-x[2],-x[1]))
b=sorted(l,key=lambda x:(-x[1],-x[2]))
pa,pb=0,0
used=set()

v=0
while pa<n and pb<n:
  while pa<n and a[pa][0] in used:
    pa+=1
  if pa<n:
    used.add(a[pa][0])
    v+=a[pa][1]
  while pb<n and b[pb][0] in used:
    pb+=1
  if pb<n:
    used.add(b[pb][0])
    v-=b[pb][2]

print(v)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    H = [(0, 0, 0)] * N
    for i in range(N):
        a, b = tuple(map(int, input().split()))
        key = a-b
        H[i] = (key, a, b)
    H.sort(reverse=True)
    t = sum(map(lambda x: x[1], H[::2]))
    a = sum(map(lambda x: x[2], H[1::2]))

    print(t - a)


if __name__ == "__main__":
    main()

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)

Submission status: Wrong Answer

Solution code:
N=int(raw_input())
S=[[0,0]for i in range(N)]
notused=[1 for i in range(N)]
for i in range(N):
    A,B=[int(x) for x in raw_input().split()]
    S[i]=[A,B,i]
SA=sorted( sorted(S,key=lambda x:x[1], reverse=True), key=lambda x:x[0], reverse=True)
SB=sorted( sorted(S,key=lambda x:x[0],reverse=True), key=lambda x:x[1],reverse=True)
ans=0
tturn=1
aind=0
bind=0
for i in range(N):
    if SA[aind]>=SB[bind]:
        chosen=SA[aind][2]
        notused[chosen]=0
    else:
        chosen=SB[bind][2]
        notused[chosen]=0
    while( notused[ SA[aind][2] ]==0):
        aind+=1
        if aind==N:
            break
    while( notused[ SB[bind][2] ]==0):
        bind+=1
        if bind==N:
            break
    if tturn:
        ans+=S[chosen][0]
    else:
        ans-=S[chosen][1]
    tturn=not(tturn)
print ans

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
Alist = []
Blist = []
sumlist = []

for i in range(N):
    a,b = map(int,input().split())
    Alist.append(a)
    Blist.append(b)
    sumlist.append(a+b)

sumlist = np.sort(sumlist)
index = np.argsort(sumlist)
counter = 0
takahasi = 0
aoki = 0

for i in range(N):
    if counter == 0:
        takahasi += Alist[index[i]]
        sumlist[i] = 0
        counter = 1
        continue
    if counter == 1:
        aoki += Blist[index[i]]
        sumlist[i] = 0
        counter = 0
        continue

print(takahasi-aoki)

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, a - b, a, b) )
su.sort()

cc = 0
for i in range(N-1):
    if su[i][0] == su[i+1][0]:
        cc += 1
    else:
        if cc:
            temp = []
            for j in range(i-cc, i+1):
                temp.append(su[j])
            temp2 = []
            for j in range(i-cc, i+1):
                if j % 2 == 0:
                    temp2.append(temp.pop(0))
                else:
                    temp2.append(temp.pop())
            for j in range(i-cc, i+1):
                su[j] = temp2[j-(i-cc)]
            cc = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
score = 0
info = []
d = []
for i in range(N):
    A,B = map(int,input().split())
    tmp = A - B
    info.append([A,B])
    d.append((tmp,i))
d.sort()
for i in range(N):
    if i % 2 == 0:
        score += info[d[i][1]][0]
    else:
        score -= info[d[i][1]][1]
print(score)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
n = int(input())

a = np.array([list(map(int,input().split())) for _ in range(n)])

t = np.argsort(a[:,0]-a[:,1])

ans = 0
for i,j in zip(t,range(len(t))):
    if j%2 == 0:
        ans+=a[i][0]
    else:
        ans-=a[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(raw_input())
S=[[0,0]for i in range(N)]
notused=[1 for i in range(N)]
for i in range(N):
    A,B=[int(x) for x in raw_input().split()]
    S[i]=[A,B,i]
SA=sorted( sorted(S,key=lambda x:x[1], reverse=True), key=lambda x:x[0], reverse=True)
SB=sorted( sorted(S,key=lambda x:x[0],reverse=True), key=lambda x:x[1],reverse=True)
ans=0
tturn=1
aind=0
bind=0
for i in range(N):
    if SA[aind]>=SB[bind]:
        chosen=SA[aind][2]
        notused[chosen]=0
    else:
        chosen=SB[bind][2]
        notused[chosen]=0
    while( notused[ SA[aind][2] ]==0):
        aind+=1
        if aind==N:
            break
    while( notused[ SB[bind][2] ]==0):
        bind+=1
        if bind==N:
            break
    if tturn:
        ans+=S[chosen][0]
    else:
        ans-=S[chosen][0]
    tturn=not(tturn)
print ans

Submission status: Wrong Answer

Solution code:
# Different Strokes
n = int(input())
a, b = list(), list()
for _ in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
s = list()
ans = 0
for i in range(n):
    s.append((a[i], b[i], i))
s.sort(key=(lambda z: z[0]+z[1]))
for i in s:
    ans += i[0] if i[2] % 2 == 0 else -i[1]
exit(print(ans))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N = int(input())

A = []
B = []
seen = [False] * N

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

A.sort()
B.sort()

sumA = 0
sumB = 0
while len(A) != 0 and len(B) != 0:
	while len(A) != 0 and seen[A[-1][1]]:
		try: A.pop()
		except: break
			
	try:
		sumA += A[-1][0]
		seen[A[-1][1]] = True
	except:
		pass
	
	while len(B) != 0 and seen[B[-1][1]]:
		try: B.pop()
		except: break
			
	try:
		sumB += B[-1][0]
		seen[B[-1][1]] = True
	except:
		pass
	

print(sumA - sumB)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_b = list()
tkh = list()
for i in range(n):
    a,b = input().split()
    a = int(a)
    b= int(b)
    a_b.append((a,b))
    tkh.append([a_b[i][0]-a_b[i][1],i])

#a_b = [(int(i[0]), int(i[1])) for i in input().split()]
#tkh = [(int(i[0])-int(i[1]),ind) for ind,i in enumerate(a_b)]
tkh = sorted(tkh,key = lambda x : x[0])
takahashi, aoki =0,0

for ind,i in enumerate(tkh):
    if ind%2 == 0:
        takahashi += a_b[i[1]][0]
    else:
        aoki += a_b[i[1]][1]

print(takahashi-aoki)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
happy = list([])
for i in range(n):
    x,y = [int(i) for i in input().split() ]
    happy.append([x,y,max(x,y), x+y])
sort_h=sorted(happy, key=lambda x: (x[2],x[3]), reverse = True)
tk= list(map(lambda x: x[0], sort_h[0::2]))
ao= list(map(lambda x: x[1], sort_h[1::2]))
print(sum(tk)- sum(ao))

Submission status: Wrong Answer

Solution code:
N=int(input())

A=[]
B=[]
f = [0 for i in range(N)]
for i in range(N):
    a,b = map(int,input().split())
    A.append([a,i])
    B.append([b,i])
A.sort(key=lambda x:x[0])
B.sort(key=lambda x:x[0])

ai=0
bi=0
ans=0
for i in range(N):
    while f[A[ai][1]]==1:
        ai+=1
    while f[B[bi][1]]==1:
        bi+=1
    amax,aind = A[ai]
    bm = B[ai][0]
    bmax,bind = B[bi]
    am = A[bi][0]
    if i%2==0:
        if amax-bm > am - bmax:
            ans+=amax
            f[aind]=1
        else:
            ans+=am
            f[bind]=1
    else:
        if bm-amax > bmax-am:
            ans-=bm
            f[aind]=1
        else:
            ans-=bmax
            f[bind]=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter

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

C = [(A[i], B[i], A[i] - B[i]) for i in range(N)]
C = sorted(C, key=itemgetter(0), reverse=True)
C = sorted(C, key=itemgetter(2))

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

print(ans)

Submission status: Wrong Answer

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


a.sort(key = itemgetter(1))
a.sort(key = itemgetter(0), reverse = True)
b.sort(key = itemgetter(1))
b.sort(key = itemgetter(0), reverse = True)
# sorted(b,key=functools.cmp_to_key(sortedby))
# print(a)
# print(b)
count = 0
check = []
for i in range(n):
    check.append(0)

i = 0
j = 0
sum1 = 0
sum2 = 0
while(count < n):
    if count & 1:
        indi = b[j][2]
        while(check[indi] != 0):
            j+=1
            indi = b[j][2]
        count += 1
        check[indi] = 1
        sum2 += real[indi][1]
    else:
        indi = a[i][2]
        while(check[indi] != 0):
            i+=1
            indi = a[i][2]
        check[indi] = 1
        sum1 += real[indi][0]
        count += 1
    # print(sum1,sum2)
print(sum1 - sum2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
n = int(input())

a = np.array([list(map(int,input().split())) for _ in range(n)])

t = np.argsort(a[:,0]*2-a[:,1])

ans = 0
for i,j in zip(t,range(len(t))):
    if j%2 == 0:
        ans+=a[i][0]
    else:
        ans-=a[i][1]
        
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
lst = [list(map(int,input().split())) for i in range(N)]
lst.sort(key=lambda x:(x[0],x[1]), reverse=True)
#print(lst)

count = 1
Takahashi = 0
Aoki = 0
for i in lst:
    if count % 2 == 1:
        Takahashi += i[0]
    else:
        Aoki += i[1]
    count+=1
print(Takahashi-Aoki)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

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

diff = []
for _ in range(N):
    diff.append(B[_] - A[_])

diff = np.array(diff)
A = np.array(A)
B = np.array(B)

sort_index = diff.argsort()

A = (A[sort_index])
B = (B[sort_index])

taka = (A[0::2])
aoki = (B[1::2])

print(sum(taka) - sum(aoki))

Submission status: Wrong Answer

Solution code:
N = int(input())
Nlist=[]
Takalist=[]
Aokilist=[]
for n in range(N):
    Nlist.append(n)
    a,b = map(int,input().split())
    Takalist.append(a)
    Aokilist.append(b)

Taka = 0
Aoki = 0


flg = 0
for n in range(N):
    if flg == 0:
        big = max(Takalist)
        Taka += big
        num = Takalist.index(big)
        Aokilist[num]=0
        Takalist[num]=0
        flg=1

    elif flg == 1:
        big = max(Aokilist)
        Aoki += big
        num = Aokilist.index(big)
        Aokilist[num]=0
        Takalist[num]=0
        flg=0

print(Taka-Aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())

dishes = list()
for i in range(0, n):
    a, b = input().split()
    a = int(a)
    b = int(b)
    diff = b - a
    dishes.append([a, b, diff])

takahashi = 0
aoki = 0
for i in range(0, n):
    if i % 2 == 0:
        dishes.sort(key=lambda x: x[2], reverse=True)
        dishes.sort(key=lambda x: x[0], reverse=True)
        j = dishes[0]
        print(j)
        dishes.pop(0)
        takahashi = takahashi + j[0]
    else:
        dishes.sort(key=lambda x: x[1], reverse=True)
        j = dishes[0]
        print(j)
        dishes.pop(0)
        aoki = aoki + j[1]

print(takahashi - aoki)

Submission status: Wrong Answer

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

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

dif.sort()
dif.reverse()
tak = 0
aok = 0
for i in range(N):
    if i % 2 == 0:
        tak += A[dif[i][1]]
    else:
        aok += B[dif[i][1]]

print(tak - aok)

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):
    if i%2 == 0:
        res += A[(D[i][1])]
    else:
        res -= B[(D[i][1])]
else:
    print(res)

Submission status: Wrong Answer

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

takahashi = 0
aoki = 0
for i in range(n):
    lis[i].append(lis[i][0]-lis[i][1])
    takahashi += lis[i][0]
    aoki += lis[i][1]
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:
        aoki -= lis[i][1]
    else:
        takahashi -= lis[i][0]
ans = takahashi - aoki
print(ans)

Submission status: Wrong Answer

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

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

dif.sort()
dif.reverse()
tak = 0
aok = 0
for i in range(N):
    if i % 2 == 0:
        tak += A[dif[i][1]]
    else:
        aok += B[dif[i][1]]

print(tak - aok)
print(dif)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

sumA = 0
pair_sum = [0] * N
for i in range(N):
  A, B = map(int, input().split())
  pair_sum[i] = A + B
  sumA += A

pair_sum = sorted(pair_sum)
pair_sum_first = 0

for i in range(1, N, 2):
  pair_sum_first += pair_sum[i]
print("%d" % (sumA - pair_sum_first))

Submission status: Wrong Answer

Solution code:
N=input()

L=[]
for i in range(N):
	a,b=map(int,raw_input().split())
	L.append( (a-b,a,b) ) 


L.sort(key=lambda x: x[0])


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

print ans

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter

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

C = [(A[i], B[i], A[i] - B[i]) for i in range(N)]
C = sorted(C, key=itemgetter(0))
C = sorted(C, key=itemgetter(2))

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

print(ans)

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(max(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(arrA[ordC][::2])
# print(arrB[ordC][1::2])
print(sum(arrA[ordC][::2]) - sum(arrB[ordC][1::2]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

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

diff = []
for _ in range(N):
    diff.append(B[_] - A[_])

diff = np.array(diff)
A = np.array(A)
B = np.array(B)
sort_index = diff.argsort()

taka = (A[0::2])
aoki = (B[1::2])

print(sum(taka) - sum(aoki))

Submission status: Wrong Answer

Solution code:
n = int(input())

a = []
b = []

a_point = 0
b_point = 0

for i in range(n):
    p_ = input().split()
    p = [int(s) for s in p_]
    a.append(p[0])
    b.append(p[1])

for i in range(n):
    if i % 2 == 0: # さいしょのたかはし
        m_ = max(a)
        a_point += m_
        ind_m = a.index(m_)
        a.pop(ind_m)
        b.pop(ind_m)
    else: # こうはつのだれか
        m_ = max(b)
        b_point += m_
        ind_m = b.index(m_)
        a.pop(ind_m)
        b.pop(ind_m)

print(a_point - b_point)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[[i]+list(map(int,input().split())) for i in range(n)]

a=sorted(l,key=lambda x:(-x[1]+x[2],-x[1],-x[2]))
b=sorted(l,key=lambda x:(x[1]-x[2],-x[2],-x[1]))
pa,pb=0,0
used=set()

v=0
while pa<n and pb<n:
  while pa<n and a[pa][0] in used:
    pa+=1
  if pa<n:
    used.add(a[pa][0])
    v+=a[pa][1]
  while pb<n and b[pb][0] in used:
    pb+=1
  if pb<n:
    used.add(b[pb][0])
    v-=b[pb][2]

print(v)

Submission status: Wrong Answer

Solution code:
n = int(input())

aa = []
for i in range(n):
	k,l = map(int,input().split())
	aa.append([k,l])
aa.sort(key = lambda x:x[1])
co = 0
ma = 0
kkk = 0
for i in range(n):
	if i % 2 == 0:
		ma = max(aa,key = lambda x:x[0])[0]
		for j in range(len(aa)):
			if ma == aa[j][0]:
				co += aa.pop(j)[0]
				break
	else:
		co -= aa.pop(0)[1]

print(co)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq
from collections import defaultdict

D = defaultdict(int)
p = 0
asum = 0
bsum = 0

N = int(input())
aq = []
bq = []
for i in range(N):
	A, B = list(map(int, input().split()))
	asum += A
	bsum += B
	heapq.heappush(aq, [-B, -A, i])
	heapq.heappush(bq, [-A, -B, i])



turn = "a"
while p < N:
	if turn == "a":
		while True:
			x, z, n = heapq.heappop(aq)
			if D[n] == 0:
				bsum += x
				D[n] += 1
				turn = "b"
				break
	else:
		while True:
			x, z, n = heapq.heappop(bq)
			if D[n] == 0:
				asum += x
				D[n] += 1
				turn = "a"
				break
	p += 1

print(asum - bsum)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    A_list=[]
    B_list=[]
    All_list = []
    t_eated_set = set([])
    a_eated_set = set([])
    eated_set = set([])
    for i in range(N):
        input_raw = read_func().strip().split()
        [A, B] = [long(input_raw[0]), long(input_raw[1])]
        A_list.append(A)
        B_list.append(B)
        All_list.append((A, i, True))
        All_list.append((B, i, False))

    All_list.sort(reverse = True)

    is_t_turn = True
    t_sum = 0L
    a_sum = 0L
    for i in range(len(All_list)):
        #if i in t_eated_set or i in a_eated_set:
        if All_list[i][1] in eated_set:
            continue
        if is_t_turn == True:
            t_sum += A_list[All_list[i][1]]

        else:
            a_sum += B_list[All_list[i][1]]

        eated_set.add(All_list[i][1])
        if is_t_turn == True:
            is_t_turn = False
        else:
            is_t_turn = True
    print t_sum - a_sum





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

sumA = 0
pair_sum = [0] * N
for i in range(N):
  A, B = map(int, input().split())
  pair_sum[i] = A + B
  sumA += A

pair_sum = sorted(pair_sum)
pair_sum_first = 0

for i in range(1, N, 2):
  pair_sum_first += pair_sum[i]
print(sumA - pair_sum_first)