qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginner_Contest117-B
#  TODO https://atcoder.jp/contests/abc117/tasks/abc117_b

def solveProblem(lengthList):
	sortedList = sorted(lengthList,reverse=True)
	allIntegerSum = sum(lengthList)
	maxInteger = sortedList.pop(0)
	anotherIntegerSum = allIntegerSum - maxInteger
	if maxInteger < anotherIntegerSum:
		answer="YES"
	else:
		answer="NO"
	return answer

if __name__ == '__main__':
	_ = input()
	lList = list(map(int,input().strip().split(' ')))
	solution = solveProblem(lList)
	print("{}".format(solution))


Fixed code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginner_Contest117-B
#  TODO https://atcoder.jp/contests/abc117/tasks/abc117_b

def solveProblem(lengthList):
	sortedList = sorted(lengthList,reverse=True)
	allIntegerSum = sum(lengthList)
	maxInteger = sortedList.pop(0)
	anotherIntegerSum = allIntegerSum - maxInteger
	if maxInteger < anotherIntegerSum:
		answer="Yes"
	else:
		answer="No"
	return answer

if __name__ == '__main__':
	_ = input()
	lList = list(map(int,input().strip().split(' ')))
	solution = solveProblem(lList)
	print("{}".format(solution))
Buggy code:
n = int(input())
l = [int(i) for i in input().split()]

l.sort()
l.reverse()
cnt = 0
for i in range(n-1):
	cnt += l[i]
if cnt > l[n]:
	print("Yes")
else:
	print("No")

Fixed code:
n = int(input())
l = [int(i) for i in input().split()]

l.sort()
cnt = 0
for i in range(n-1):
	cnt += l[i]
if cnt > l[n-1]:
	print("Yes")
else:
	print("No")
Buggy code:
numN = int(input())
args = input()
 
lines = list()
 
 
for i in range(numN):
    if i == numN - 1 :
        lines.append(int(args))
        break

    lines.append(int(args[0:args.find(" ")]))
    args = args[args.find(" ") + 1 :]
 
list_sorted = sorted(lines, reverse = True)
max_line = list_sorted[0]
 
for m in range(numN - 1):
    max_line = max_line - list_sorted[m+1]

print(max_line) 
if max_line < 0 :
    print('yes')
else:
    print('no')

Fixed code:
numN = int(input())
args = input()
 
lines = list()
 
 
for i in range(numN):
    if i == numN - 1 :
        lines.append(int(args))
        break

    lines.append(int(args[0:args.find(" ")]))
    args = args[args.find(" ") + 1 :]
 
list_sorted = sorted(lines, reverse = True)
max_line = list_sorted[0]
 
for m in range(numN - 1):
    max_line = max_line - list_sorted[m+1]

if max_line < 0 :
    print('Yes')
else:
    print('No')
Buggy code:
n = int(input())

L = [map(int,input().split())]

sum = int(0)
a = max(L)

for i in range(n):
  sum += L[i]
  
if 2*a > sum:
  print("Yes")
else:
  print("No")

Fixed code:
n = int(input())

L = list(map(int,input().split()))

sum = int(0)
a = max(L)

for i in range(n):
  sum += L[i]
  
if 2*a < sum:
  print("Yes")
else:
  print("No")
Buggy code:
N=int(input())
l=list(map(int,input().split()))
l=sorted(l)

if l[-1] < sum([:-1]):
  print("Yes")
else:
  print("No")


Fixed code:
N=int(input())
l=list(map(int,input().split()))
l=sorted(l)

if l[-1] < sum(l[:-1]):
  print("Yes")
else:
  print("No")
Buggy code:
a=input()
b=list(map(int,input().split()))
b.sort()
if sum(b)-max(b)-max(b)<0:
  print("Yes")
else:
  print("No")

Fixed code:
a=input()
b=list(map(int,input().split()))
b.sort()
if sum(b)-max(b)-max(b)>0:
  print("Yes")
else:
  print("No")
Buggy code:
n = int(input())
t = list(map(int, input().split()))
if max(t) * 2 > sum(t):
	print("Yes")
else:
	print("No")

Fixed code:
n = int(input())
t = list(map(int, input().split()))
if max(t) * 2 < sum(t):
    print("Yes")
else:
    print("No")
Buggy code:
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        val = lis.popleft()
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        val = lis.popleft()
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)


Fixed code:
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        val = lis.popleft()
        takacnt += A[val[1]]
    else:
        val = lis.popleft()
        aocnt += B[val[1]]
print(takacnt-aocnt)
Buggy code:
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(taka)

takacnt = 0
aocnt = 0
st = set()

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)


Fixed code:
from collections import deque
N = int(input())
taka = []
ao = []
A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    taka.append((Bin+Ain,i))
    ao.append((Ain+Bin,i))
taka.sort()
taka.reverse()
ao.sort()
ao.reverse()
taka = deque(taka)
ao = deque(ao)
takacnt = 0
aocnt = 0
st = set()

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        while True:
            val = taka.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = ao.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)
Buggy code:
from collections import deque
N=int(input())

C=[]
D=0
for _ in range(N):
    a,b=map(int,input().split())
    C.append((a,b))
    D+=b
    
C.sort(key=lambda x:x[0]+x[1])
C=deque(C)
print(C)

i=0
A=0
while C:
    (a,b)=C.pop()
    if i==0:
        A+=a+b
    i^=1
print(A-D)


Fixed code:
from collections import deque
N=int(input())

C=[]
D=0
for _ in range(N):
    a,b=map(int,input().split())
    C.append((a,b))
    D+=b
    
C.sort(key=lambda x:x[0]+x[1])
C=deque(C)

i=0
A=0
while C:
    (a,b)=C.pop()
    if i==0:
        A+=a+b
    i^=1
print(A-D)
Buggy code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
b = [None]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())
    
ab = [(a[i]+b[i], i) for i in range(n)]
ab.sort()
takahashi = 0
aoki = 0
for i in range(n):
    if i%2==0:
        takahashi += a[ab[-i][1]]
    else:
        aoki += b[ab[-i][1]]
print(takahashi-aoki)

Fixed code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
b = [None]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())
    
ab = [(a[i]+b[i], i) for i in range(n)]
ab.sort()
takahashi = 0
aoki = 0
for i in range(n):
    if i%2==0:
        takahashi += a[ab[n-1-i][1]]
    else:
        aoki += b[ab[n-1-i][1]]
print(takahashi-aoki)
Buggy code:
from collections import deque
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key = lambda x:x[0]-x[1])
ans=0
for i in range(n):
  if i%2==0:
    ans+=l[i//2][0]
  else:
    ans-=l[n-1-(i//2)][1]
print(ans)

Fixed code:
from collections import deque
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key = lambda x:x[0]+x[1],reverse=True)
ans=0
for i in range(n):
  if i%2==0:
    ans+=l[i][0]
  else:
    ans-=l[i][1]
print(ans)
Buggy code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    T, A = [None] * N, [None] * N
    used = [False] * N
    for i in range(N):
        a, b = map(int, input().split())
        T[i] = (b - a, a, b, i)
        A[i] = (a - b, b, a, i)
    T.sort(reverse = True)
    A.sort(reverse = True)
    hapiness = 0
    ti, ai = 0, 0
    for i in range(N):
        if i % 2 == 0:
            while used[T[ti][3]]: ti += 1
            hapiness += T[ti][1]
            used[T[ti][3]] = True
            ti += 1           
        else:
            while used[A[ai][3]]: ai += 1
            hapiness -= A[ai][1]
            used[A[ai][3]] = True
            ai += 1
    print(hapiness)
   
    return 0

if __name__ == "__main__":
    solve()

Fixed code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    T, A = [None] * N, [None] * N
    used = [False] * N
    for i in range(N):
        a, b = map(int, input().split())
        T[i] = (a + b, a, i)
        A[i] = (a + b, b, i)
    T.sort(reverse = True)
    A.sort(reverse = True)
    hapiness = 0
    ti, ai = 0, 0
    for i in range(N):
        if i % 2 == 0:
            while used[T[ti][2]]: ti += 1
            hapiness += T[ti][1]
            used[T[ti][2]] = True
            ti += 1           
        else:
            while used[A[ai][2]]: ai += 1
            hapiness -= A[ai][1]
            used[A[ai][2]] = True
            ai += 1
    print(hapiness)
   
    return 0

if __name__ == "__main__":
    solve()
Buggy code:
n = int(input())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(key=lambda x: (max(x), min(x)), reverse=True)
print(AB)
A, B = [], []
for i in range(n):
    a, b = AB[i]
    if i % 2 == 0:
        A.append(a)
    else:
        B.append(b)
print(sum(A)-sum(B))


Fixed code:
n = int(input())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(key=lambda x: x[0]+x[1], reverse=True)
A, B = [], []
for i in range(n):
    a, b = AB[i]
    if i % 2 == 0:
        A.append(a)
    else:
        B.append(b)
print(sum(A)-sum(B))
Buggy code:
n=int(input())
x=[]
for _ in range(n):
    a,b=map(int,input().split())
    x.append([abs(a-b),a,b])
x.sort(reverse=True)
ans=0
for i in range(n):
    if i%2==0: ans+=x[i][1]
    else: ans-=x[i][2]
print(ans)

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

AB = sorted(AB, key=lambda x:x[2]*(-1))
print(AB)
A = 0
B = 0
for i in range(N):
    if i%2==0:
        A += AB[i][2]
    B += AB[i][1]
        
print(A-B)

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

AB = sorted(AB, key=lambda x:x[2]*(-1))

A = 0
B = 0
for i in range(N):
    if i%2==0:
        A += AB[i][2]
    B += AB[i][1]
        
print(A-B)
Buggy code:
n=int(input())
s=[0]*n
t=0
for i in range(n):
  a,b=map(int,input().split())
  s[i]=a+b
  t+=b
s.sort()
s=s[::-1]
print(sum(s[:n//2+(n%2==1)])-t)

Fixed code:
n=int(input())
s=[0]*n
t=0
for i in range(n):
  a,b=map(int,input().split())
  s[i]=a+b
  t+=b
s.sort()
s=s[::-1]
print(sum(s[::2])-t)
Buggy code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
sys.setrecursionlimit(10 ** 7)

N = ri()
A = []
B = []

for i in range(N):
    a, b = rl()
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)
diff = A - B
D = []
for i, x in enumerate(diff):
    D.append((x, i))

D.sort()
A = list(A)
B = list(B)
ta = 0
ao = 0
for x, i in D[::2]:
    ta += A[i]
for x, i in D[1::2]:
    ao -= B[i]

print(ta-ao)


Fixed code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
sys.setrecursionlimit(10 ** 7)

N = ri()
A = []
B = []

for i in range(N):
    a, b = rl()
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)
diff = A + B
D = []
for i, x in enumerate(diff):
    D.append((x, i))

D.sort(reverse=True)
A = list(A)
B = list(B)
ta = 0
ao = 0
for x, i in D[::2]:
    ta += A[i]
for x, i in D[1::2]:
    ao += B[i]

print(ta-ao)
Buggy code:
# -*- coding: utf-8 -*-
#"""
#Created on Wed Nov 20 17:37:14 2019
#
#@author: manakamura
#"""

#https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_c

n= int(input())
#s= input()
tup = []
for i in range(0,n):
    tmp = input().split()
    tmpa,tmpb = list(map(lambda a: int(a), tmp))
    tup.append([abs(tmpa-tmpb),tmpa,tmpb])

#print(tup)
tup=sorted(tup, reverse=True, key=lambda x:x[0])
#print(tup)

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

Fixed code:
# -*- coding: utf-8 -*-
#"""
#Created on Wed Nov 20 17:37:14 2019
#
#@author: manakamura
#"""

#https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_c

n= int(input())
#s= input()
tup = []
for i in range(0,n):
    tmp = input().split()
    tmpa,tmpb = list(map(lambda a: int(a), tmp))
    tup.append([tmpa+tmpb,tmpa,tmpb])

#print(tup)
tup=sorted(tup, reverse=True, key=lambda x:x[0])
#print(tup)

total=0
for i in range(0,n):
    if (i%2==0):
       total+=tup[i][1]
    else:
       total-=tup[i][2]
          
print(total)
Buggy code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
ab = [0] * n
for i in range(n):
    a,b = inpl()
    ab[i] = (abs(a-b),a,b)
ab.sort(reverse=True)
# print(ab)
x = 0
y = 0
for i,j in enumerate(ab):
    if i%2:
        y += j[2]
    else:
        x += j[1]
print(x-y)


Fixed code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
ab = [0] * n
for i in range(n):
    a,b = inpl()
    ab[i] = (a+b,a,b)
ab.sort(reverse=True)
# print(ab)
x = 0
y = 0
for i,j in enumerate(ab):
    if i%2:
        y += j[2]
    else:
        x += j[1]
print(x-y)
Buggy code:
N=int(input().split())
C=[list(map(int,input().split())) for i in range(N)]
C.sort(key=lambda x:sum(x), reverse=True)
ans=0
for i in range(N):
  if i%2==0:
    ans+=C[i][0]
  else:
    ans-=C[i][1]
print(ans)

Fixed code:
N=int(input())
C=[list(map(int,input().split())) for i in range(N)]
C.sort(key=lambda x:sum(x), reverse=True)
ans=0
for i in range(N):
  if i%2==0:
    ans+=C[i][0]
  else:
    ans-=C[i][1]
print(ans)
Buggy code:
#c
n=int( input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split() )
    
d=[[a[i],b[i],a[i]+b[i]] for i in range(n)]
d.sort(reverse=True,key=lambda x:x[2])
tsum = sum( d[i][0] for i in range((n+1)//2)  ) 
asum = sum( d[i][1] for i in range((n+1)//2,n))
print(tsum-asum)

Fixed code:
n=int( input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split() )
c=[[a[i],b[i],a[i]+b[i]] for i in range(n)]
c.sort(reverse=True,key=lambda x:x[2])
tsum=sum(c[i*2][0] for i in range((n+1)//2))
asum=sum(c[i*2+1][1] for i in range(n//2))
print( tsum- asum )
Buggy code:
n=int(input())
lists=[]
lists1=[]
for i in range(n):
    a,b=map(int,input().split())
    lists.append((a+b,a,b))
listed=sorted(lists,key=lambda x:x[0],reverse=True)

ans=0
for n in range(n):
if n%2==0:
    ans+=listed[n][1]
    
elif n%2!=0:
    ans-=listed[n][2]
print(ans)
    

Fixed code:
n=int(input())
lists=[]
lists1=[]
for i in range(n):
    a,b=map(int,input().split())
    lists.append((a+b,a,b))
listed=sorted(lists,key=lambda x:x[0],reverse=True)

ans=0
for n in range(n):
    if n%2==0:
        ans+=listed[n][1]
    
    elif n%2!=0:
        ans-=listed[n][2]
print(ans)
Buggy 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(and)


Fixed code:
N = int(input())
F = []
for i in range(N):
  a,b = map(int,input().split())
  F.append([a+b,a,b])
F.sort(key=lambda x:x[0],reverse=True)
ans = 0
for i in range(N):
  if i%2==0:
    ans += F[i][1]
  else:
    ans -= F[i][2]
print(ans)
Buggy code:
n = int(input())
ab = []
for _ in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])
ab.sort(key = lambda x:x[0]+x[1] ,reverse = True)
ans = sum([x[0]+x[1] for x in ab[0:(n+1)//2]])-sum([x[1] for x in ab])
print(ans)




Fixed code:
n = int(input())
ab = []
for _ in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])
ab.sort(key = lambda x:x[0]+x[1] ,reverse = True)
ans = sum([x[0]+x[1] for x in ab[0:n:2]])-sum([x[1] for x in ab])
print(ans)
Buggy code:
n,*t=map(int,open(0).read().split())
t=sorted(zip(t[::2],t[1::2]),key=lambda v:v[0]+v[1])
print(sum(a for a,_ in t[::-2])-sum(b for _,b in t[-1::-2]))

Fixed code:
n,*t=map(int,open(0).read().split());t=sorted(zip(t[::2],t[1::2]),key=lambda v:v[0]+v[1]);print(sum(a for a,_ in t[::-2])-sum(b for _,b in t[-2::-2]))
Buggy code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
ABs = []
for _ in range(N):
    A,B = inpl()
    ABs.append([A+B,A,B])

ABs.sort(reversed=True)
t = a = 0

for i,[AB,A,B] in enumerate(ABs):
    if i%2 == 0:
        t += A
    else:
        a += B

print(t-a)


Fixed code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
ABs = []
for _ in range(N):
    A,B = inpl()
    ABs.append([A+B,A,B])

ABs.sort(reverse=True)
t = a = 0

for i,[AB,A,B] in enumerate(ABs):
    if i%2 == 0:
        t += A
    else:
        a += B

print(t-a)
Buggy code:
N = int(input())
ABs = [list(map(int,input.split())) for i in rane(N)]
li = []
for A,B in ABs:
  li.append([A+B,A,B])
  
li.sort(reverse=True)
flag = True
ans1 = ans2 = 0
for S,A,B in li:
  if flag:
    ans1 += A
  else:
    ans2 += B
  flag = not flag
  
print(ans1-ans2)

Fixed code:
N = int(input())
ABs = [list(map(int,input().split())) for i in range(N)]
li = []
for A,B in ABs:
  li.append([A+B,A,B])
  
li.sort(reverse=True)
flag = True
ans1 = ans2 = 0
for S,A,B in li:
  if flag:
    ans1 += A
  else:
    ans2 += B
  flag = not flag
  
print(ans1-ans2)
Buggy code:
input()
s=[list(map(int,input().split()))for i in range(n)]
print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))

Fixed code:
n=int(input())
s=[list(map(int,input().split()))for i in range(n)]
print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))
Buggy code:
N = int(input())
L = []
K = []
S = 0
for i in range(N):
  L.append(list(map(int,input().split())))
for i in range(N):
  S += -L[i][1]
for i in range(N):
  K.append(L[i][0]+L[i][1])
K.sort()
K.reverse()
if N%2 == 0:
  for i in range(N//2):
    S += K[i]
else:
  for i in range(N//2+1):
    S += K[i]
print(S)

Fixed code:
N = int(input())
L = []
K = []
S = 0
for i in range(N):
  L.append(list(map(int,input().split())))
for i in range(N):
  S += -L[i][1]
for i in range(N):
  K.append(L[i][0]+L[i][1])
K.sort()
K.reverse()
if N%2 == 0:
  for i in range(N//2):
    S += K[i*2]
else:
  for i in range(N//2+1):
    S += K[i*2]
print(S)
Buggy code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=sum, reverse=True)

sol = 0
import sys
print(sys.maxsize)

for i, x in enumerate(ab):
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

print(sol)


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

ab.sort(key=sum, reverse=True)

sol = 0

for i, x in enumerate(ab):
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

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

Fixed code:
n=int(input())
AB=[]
for i in range(n):
    a,b=map(int,input().split())
    AB.append([a+b,a,b])
AB.sort(reverse=True,key=lambda x:x[0])
ans=0
for i in range(n):
    if i%2==0:
        ans+=AB[i][1]
    else:
        ans-=AB[i][2]
print(ans)
Buggy code:
n = int(input())
a = []
for i in range(n):
  ai, bi = list(map(int, input()))
  a.append((ai, bi, ai+bi))
a.sort(key = lambda x: x[2], reverse=True)
tak = 0
aok = 0
for i in range(n):
  if i%2 == 0:
    tak += a[i][0]
  else:
    aok += a[i][1]
print(tak - aok)
  

Fixed code:
n = int(input())
a = []
for i in range(n):
  ai, bi = list(map(int, input().split()))
  a.append((ai, bi, ai+bi))
a.sort(key = lambda x: x[2], reverse=True)
tak = 0
aok = 0
for i in range(n):
  if i%2 == 0:
    tak += a[i][0]
  else:
    aok += a[i][1]
print(tak - aok)
Buggy code:
N = int(input())
l = []
sumB = 0
for i in range(N):
    tmp = map(int, input().split())
    l.append(tmp[0] + tmp[1])
    sumB += tmp[1]
l.sort(reverse=True)
A = 0
for i in range(0, N, 2):
        A += l[i]
print(A - sumB)

Fixed code:
N = int(input())
l = []
sumB = 0
for i in range(N):
    tmp = list(map(int, input().split()))
    l.append(tmp[0] + tmp[1])
    sumB += tmp[1]
l.sort(reverse=True)
A = 0
for i in range(N):
    if i % 2 ==0:
        A += l[i]
print(A - sumB)
Buggy code:
n = int(input())
c = []
bs = 0
for i in range(n):
  a,b = map(int,input().split())
  bs += b
  c.append(a+b)

c.sort()

ans = -bs
for i in range(n,0,-1):
  if i%2==0: ans += c[i]
    
print(ans)


Fixed code:
n = int(input())
c = []
bs = 0
for i in range(n):
  a,b = map(int,input().split())
  bs += b
  c.append(a+b)

c.sort()

ans = -bs
for i in reversed(range(n)):
  cnt = n-1-i
  if cnt%2==0: ans += c[i]
    
print(ans)
Buggy code:
n = int(input())
a = []
for i in range(n):
  a1,a2 = map(int, input().split())
  a.append([a1+a2,a1,a2])
a.sort()
a.reverse()
ans = 0
print(a)
for i in range(n):
  if i % 2 == 0:
    ans += a[i//2][1]
  else:
    ans -= a[i//2 + 1][2]
print(ans)

Fixed code:
n = int(input())
a = []
for i in range(n):
  a1,a2 = map(int, input().split())
  a.append([a1+a2,a1,a2])
a.sort()
a.reverse()
ans = 0
for i in range(n):
  if i % 2 == 0:
    ans += a[i][1]
  else:
    ans -= a[i][2]
print(ans)