qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a
 
 
 
def lcm(a, b):
    return a * b // (gcd(a, b))
 
 
 
def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)
 
    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm
 
#    print(Bc,Bd,Blcm)
 
    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm
 
#    print(Ac,Ad,Alcm)
 
    print(Bdec - Adec)
 

Fixed code:
import sys

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a



def lcm(a, b):
    return a * b // (gcd(a, b))



def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)

    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()
Buggy code:
A,B,C,D=map(int,input().split())
if C>D:
  c=D
  d=C
else:
  c=C
  d=D
  
f=B//d
g=(A-1)//d
h=B//c
i=(A-1)//c
  
while c:
  c,d=d%c,c
j=C*D/d
k=B//j
l=(A-1)//j
print(int(B-A+1-(f-g+h-i-k+l)))


Fixed code:
A,B,C,D=map(int,input().split())
if C>D:
  c=D
  d=C
else:
  c=C
  d=D
  
f=B//d
g=(A-1)//d
h=B//c
i=(A-1)//c
  
while c:
  c,d=d%c,c
j=C*D//d
k=B//j
l=(A-1)//j
print(B-A+1-(f-g+h-i-k+l))
Buggy code:
def euclid(a,b):
	c=0
	if (a-b)<0:
		c=a
		a=b
		b=c
	r=-1
	while r!=0:
		r=a%b
		a=b
		b=r
	return a

A,B,C,D=map(int,input().split())
c1=A//C
d1=A//D
c2=B//C
d2=B//D
k=euclid(C,D)
CD=C*D//k
cd1=A//CD
cd2=B//CD
c3=c2-c1
d3=d2-d1
cd3=cd2-cd1
print(B-A+1-c3-d3+cd3)

Fixed code:
def euclid(a,b):
	c=0
	if (a-b)<0:
		c=a
		a=b
		b=c
	r=-1
	while r!=0:
		r=a%b
		a=b
		b=r
	return a

A,B,C,D=map(int,input().split())
c1=(A-1)//C
d1=(A-1)//D
c2=B//C
d2=B//D
k=euclid(C,D)
CD=C*D//k
cd1=(A-1)//CD
cd2=B//CD
c3=c2-c1
d3=d2-d1
cd3=cd2-cd1
print(B-A+1-c3-d3+cd3)
Buggy code:
import math
A,B,C,D = map(int,input().split())

E = C*D / math.gcd(C,D)

i = B//C
j = B//D
k = A//C
n = A//D
m = B//E
l = A//E

res = B-(A-1)-(i-k)-(j-n)+(m-l)
print(math.floor(res))

Fixed code:
import math
A,B,C,D = map(int,input().split())

E = C*D // math.gcd(C,D)

i = B//C
j = B//D
k = (A-1)//C
l = (A-1)//E
n = (A-1)//D
m = B//E

res = B-(A-1)-(i-k)-(j-n)+(m-l)
print(res)
Buggy code:
import math

A,B,C,D = map(int, input().split())
a = B//C - A//C
b = B//D - A//D
lcm = C*D//math.gcd(C,D)
c = B//lcm - A//lcm
print(B-A-(a+b-c))

Fixed code:
import math
 
A,B,C,D = map(int, input().split())
a = B//C - (A-1)//C
b = B//D - (A-1)//D
lcm = C*D//math.gcd(C,D)
c = B//lcm - (A-1)//lcm
print(B-(A-1)-(a+b-c))
Buggy code:
A,B,C,D=list(map(int, input().split()))

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

E=lcm(C,D)

Cmin=A-A%C
Cmax=B-B%C
Dmin=A-A%D
Dmax=B-B%D
Emin=A-A%E
Emax=B-B%E

num = ((Cmax-Cmin)/C)+((Dmax-Dmin)/D)-((Emax-Emin)/E)

print(int(B-A+1-num))


Fixed code:
A,B,C,D=list(map(int, input().split()))

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

E=lcm(C,D)

A-=1

Cmin=A-A%C
Cmax=B-B%C
Dmin=A-A%D
Dmax=B-B%D
Emin=A-A%E
Emax=B-B%E

num = ((Cmax-Cmin)//C)+((Dmax-Dmin)//D)-((Emax-Emin)//E)



print(int(B-A-num))
Buggy code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
 
 
def lcd(a, b):
    return a*b // gcd(a, b)
  
a, b, c, d = map(int, input().split())
sum1 = (a - 1) // c + (a - 1) // d + (a - 1) // lcd(c, d)
sum2 = b // c + b // d + b // lcd(c, d)
print(sum2 - sum1)

Fixed code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
 
 
def lcd(a, b):
    return a*b // gcd(a, b)
  
a, b, c, d = map(int, input().split())
sum1 = (a - 1) // c + (a - 1) // d - (a - 1) // lcd(c, d)
sum2 = b // c + b // d - b // lcd(c, d)
print(b - a  + 1 - (sum2 - sum1))
Buggy code:
import math

def getDivCount( a, b, x ):
    count=0
    if a==0 :
        count+=1
    count+=b//x-a//x
    return count

a,b,c,d = map(int, input().split())

count = b-a+1
count -= getDivCount(a,b,c)
count -= getDivCount(a,b,d)
count += getDivCount(a,b,c*d//math.gcd(c,d))
print(count)


Fixed code:
import math

def getDivCount( a, b, x ):
    count=0
    if a!=0 :
        count+=b//x-(a-1)//x
    else:
        count+=b//x+1
    return count

a,b,c,d = map(int, input().split())

count = b-a+1
count -= getDivCount(a,b,c)
count -= getDivCount(a,b,d)
count += getDivCount(a,b,c*d//math.gcd(c,d))
print(count)
Buggy code:
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def lcm(a,b):
    return int(a*b//gcd(a,b))

def div(x,c,d):
    return x - x//c - x//d + x//lcm(c,d)


a,b,c,d = map(int,input().split())

a = div(a,c,d)
b = div(b,c,d)
num = b-a

print(num)


Fixed code:
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def lcm(a,b):
    return int(a*b//gcd(a,b))

def div(x,c,d):
    return x - x//c - x//d + x//lcm(c,d)


a,b,c,d = map(int,input().split())

a = div(a-1,c,d)
b = div(b,c,d)
num = b-a

print(num)
Buggy code:
# AtCoder Beginner Contest 131
# C - Anti-Division
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D=map(int,input().split())
bc=B//C
ac=A//C
cnum=bc-ac

bd=B//D
ad=A//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=A//lcmcd
lcmcdnum=blcmcd-alcmcd

print(B-A-cnum-dnum+lcmcdnum)

Fixed code:
# AtCoder Beginner Contest 131
# C - Anti-Division
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D=map(int,input().split())
bc=B//C
ac=(A-1)//C
cnum=bc-ac

bd=B//D
ad=(A-1)//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=(A-1)//lcmcd
lcmcdnum=blcmcd-alcmcd


print(B-A-cnum-dnum+lcmcdnum+1)
Buggy code:
def GCD(a,b):
  if a<b:
    tmp = a
    a = b
    b = tmp
 
  r = a % b
  while (r!=0): 
    a = b
    b = r
    r = a % b
  return b


A,B,C,D = map(int,input().split())

upperC = int(B / C)
upperD = int(B / D)
lowerC = int(A / C)
lowerD = int(A / D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D / gcd
upperL = int(B / lcm)
lowerL = int(A / lcm)
numL = upperL - lowerL

print(str(B - A + 1 - (numC + numD - numL)))




Fixed code:
def GCD(a,b):
  if a<b:
    tmp = a
    a = b
    b = tmp
 
  r = a % b
  while (r!=0): 
    a = b
    b = r
    r = a % b
  return b


A,B,C,D = map(int,input().split())
A = A - 1
upperC = int(B // C)
upperD = int(B // D)
lowerC = int(A // C)
lowerD = int(A // D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D // gcd
upperL = int(B // lcm)
lowerL = int(A // lcm)
numL = upperL - lowerL

print(str(B - A - (numC + numD - numL)))
Buggy code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

aa = - ((a-1) // x) + ((a-1) // c) + ((a-1) // d)
bb = - b // x + b // c + b // d
ans = (b-a+1)-(bb-aa)

print(ans)


Fixed code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
        sys.exit()
    else:
        print(0)
        sys.exit()

aa = a-1+(a-1)//x - (a-1)//c - (a-1)//d
bb = b+b//x - b//c - b//d
ans = bb-aa

print(ans)
Buggy code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = c * d / g
    print(gcm)


    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)
    
    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()


Fixed code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

import math

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = int(c * d // g)

    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)

    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()
Buggy code:
import math
from decimal import Decimal

def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)

A, B, C, D = map(int, input().split())
count = 0
BCcount = B // C
BDcount = B // D
ACcount = (A - 1) // C
ADcount = (A - 1) // D
l = C * D // gcd(C, D)
BCDcount = B // l
print(BCDcount)
ACDcount = (A - 1) // l
print(ACDcount)
Bcount = Decimal(B - (BCcount + BDcount - BCDcount))
Acount = Decimal((A - 1) - (ACcount + ADcount - ACDcount))
print(Decimal(Bcount - Acount))

Fixed code:
from decimal import Decimal
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)

A, B, C, D = map(int, input().split())
count = 0
BCcount = B // C
BDcount = B // D
ACcount = (A - 1) // C
ADcount = (A - 1) // D
l = C * D // gcd(C, D)
BCDcount = B // l
ACDcount = (A - 1) // l
Bcount = Decimal(B - (BCcount + BDcount - BCDcount))
Acount = Decimal((A - 1) - (ACcount + ADcount - ACDcount))
print(Decimal(Bcount - Acount))
Buggy code:
a, b, c, d = [int(v) for v in input().split()]

def gcd(p, q):
    if q > p:
        p, q = q, p
    m = -1
    while m != 0:
        m = p % q
        p, q = q, m
    return p

a = a - 1
lcm = c * d / gcd(d, c)
dc = b//c - a//c
dd = b//d - a//d
dcd = b//lcm - a//lcm
divable = dc + dd - dcd
print(b - a - divable)

Fixed code:
a, b, c, d = [int(v) for v in input().split()]

def gcd(p, q):
    if q > p:
        p, q = q, p
    m = -1
    while m != 0:
        m = p % q
        p, q = q, m
    return p

a = a - 1
lcm = c * d // gcd(d, c)
dc = b//c - a//c
dd = b//d - a//d
dcd = b//lcm - a//lcm
divable = dc + dd - dcd
print(b - a - divable)
Buggy code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)


a, b, c, d = map(int, input().split())
cd = lcm(a,b)
ans = 0
ans += (b // c) - (a // c)
ans += (b // d) - (a // d)
ans -= (b // cd) - (a // cd)
ans = (b - a + 1) - ans

print(ans)

Fixed code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)


a, b, c, d = map(int, input().split())
cd = lcm(c,d)
ans = 0
ans += ((b // c) - ((a-1) // c))
ans += ((b // d) - ((a-1) // d))
ans -= ((b // cd) - ((a-1) // cd))
ans = (b - a + 1) - ans

print(ans)
Buggy code:
import fractions

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

A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


firstC = int((A-1)/C)
firstD = int((A-1)/D)
firstCD = int((A-1)/lcm(C,D))

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 1

endC = int(B/C)
endD = int(B/D)
endCD = int(B/lcm(C,D))

End = B-endC-firstD + endCD
First = (A-1) - firstC - firstD + firstCD



thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD

print(thereC)
print(thereD)
print(thereCD)
print(NoP)
print((B-A+1)-NoP)
# print(End-First)









Fixed code:
import fractions

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

A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]


# def lcm(x, y):
#     return (x * y) // fractions.gcd(x, y)


def floor(a, b):
  # return int((a - a%b)/b)
  return a//b
def gcd(a, b):
  while b != 0:
      a, b = b, a % b
  return a
def lcm(a, b):
  return floor((a * b), gcd(a, b))

firstC = floor((A-1),C)
firstD = floor((A-1),D)
firstCD = floor((A-1),lcm(C,D))

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 1

endC = floor(B,C)
endD = floor(B,D)
endCD = floor(B,lcm(C,D))

End = B-endC-firstD + endCD
First = (A-1) - firstC - firstD + firstCD



thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD

# print(thereC)
# print(thereD)
# print(thereCD)
# print(NoP)
print((B-A+1)-NoP)
# print(End-First)
Buggy code:
#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = b/c - (a-1)/c
canD = b/d - (a-1)/d
dbCD = b/lcm(c,d) - (a-1)/lcm(c,d)
print(int((b-a+1) -canC - canD + dbCD))


Fixed code:
#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b // gcd(a,b)
a,b,c,d = map(int,input().split())
canC = int(b//c) -int((a-1)//c)
canD = int(b//d) - int((a-1)//d)
dbCD = int(b//lcm(c,d)) -int((a-1)//lcm(c,d))
print((b-a+1) -canC - canD + dbCD)
Buggy code:
n = int(input())
sche = []
for i in range(n):
    a,b = map(int,input().split())
    sche.append((b,a))
sche.sort(reverse = True)
now = 1e18
for dead,ti in :
    if(dead > now):
        dead = now
    now -= ti

if now < 0:
    print("No")
else:
    print("Yes")


Fixed code:
n = int(input())
sche = []
for i in range(n):
    a,b = map(int,input().split())
    sche.append((b,a))
sche.sort(reverse = True)
now = 1e18
for dead,ti in sche:
    if(dead < now):
        now = dead
    now -= ti

if now < 0:
    print("No")
else:
    print("Yes")
Buggy code:
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    N = input()
    AB = [inputs() for _ in range(int(N))]
    AB.sort(key=lambda x: x[1])
    print(AB)
    time = 0
    for a, b in AB:
        time += a
        print(time, b)
        if time > b:
            return 'No'
    return 'Yes'


if __name__ == '__main__':
    print(main())


Fixed code:
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    N = input()
    AB = [inputs() for _ in range(int(N))]
    AB.sort(key=lambda x: x[1])
    time = 0
    for a, b in AB:
        time += a
        if time > b:
            return 'No'
    return 'Yes'


if __name__ == '__main__':
    print(main())
Buggy code:
N = int(input())
job = [list(map(int, input().split())) for i in range(N)]

job.sort(key = lambda x: x[1]

time = 0
flag = 0
for i in range(N):
    time += job[i][0]
    if time > job[i][1]:
        flag = 1 
    
if flag == 0:
    print('Yes')
else:
    print('No')

Fixed code:
N = int(input())
job = [list(map(int, input().split())) for i in range(N)]

job.sort(key = lambda x: x[1])

time = 0
flag = 0
for i in range(N):
    time += job[i][0]
    if time > job[i][1]:
        flag = 1 
    
if flag == 0:
    print('Yes')
else:
    print('No')
Buggy code:
from operatpr import itemgetter

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

job.sort(key = itemgetter(1))

time = 0
flag = 0
for i in range(N):
    time += job[i][0]
    if time > job[i][1]:
        flag = 1
    print(flag)    
    
if flag == 0:
    print('Yes')
else:
    print('No')

Fixed code:
from operator import itemgetter

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

job.sort(key = itemgetter(1))

time = 0
flag = 0
for i in range(N):
    time += job[i][0]
    if time > job[i][1]:
        flag = 1    
    
if flag == 0:
    print('Yes')
else:
    print('No')
Buggy code:
n = int(input())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([a,b])
li = sorted(li,key = lambda x:x[1])
ok = True
s = 0
for i in range(n):
    #print(li[i])
    f,s = li[i]
    s += f
    if s > s:
        ok = False
print('Yes' if ok else 'No')


Fixed code:
n = int(input())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([a,b])
li = sorted(li,key = lambda x:x[1])
ok = True
sa = 0
for i in range(n):
    #print(li[i])
    f,s = li[i]
    sa += f
    if sa > s:
        ok = False
print('Yes' if ok else 'No')
Buggy code:
n = int(input())
a = list(list(map(int, input().split())) for _ in range(n))
a.sort(key=lambda x: x[1])
ans = 0
for i in range(0, n - 1):
    ans += a[i][0]
    if ans > a[i][1]:
        print("No")
        exit()
print("Yes")

Fixed code:
n = int(input())
a = list(list(map(int, input().split())) for _ in range(n))
a.sort(key=lambda x: x[1])
ans = 0
for i in a:
    ans += i[0]
    if ans > i[1]:
        print("No")
        exit()
print("Yes")
Buggy code:
from operator import itemgetter
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
ab.sort(key=itemgetter(1))
sum=0
for i in range(n):
    sum+=ab[i][0]
    if sum>ab[i][1]:
        print('No')
else:
    print('Yes')

Fixed code:
from operator import itemgetter
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
ab.sort(key=itemgetter(1))
sum=0
for i in range(n):
    sum+=ab[i][0]
    if sum>ab[i][1]:
        print('No')
        break
else:
    print('Yes')
Buggy code:
N = int(input())

X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[1])

cnt = 0
for i in range(N):
    temp = X[i][1]
    if temp >= cnt:
        cnt += X[i][0]
    else:
        print("No")
        break
else:
    print("Yes")


Fixed code:
N = int(input())

X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[1])

cnt = 0
for i in range(N):
    temp = X[i][1]
    cnt += X[i][0]
    if temp < cnt:
        print("No")
        break
else:
    print("Yes")
Buggy code:
def solve():
    n = int(input())
    task = [0]*n
    for i in range(n):
        a,b = map(int,input().split())
        task[i] = [a,b]
    
    task = sorted(task, key= lambda x : x[1])
    print(task)

    time = 0
    due = 0

    for i in range(n):
        time += task[i][0]
        due = max(due,task[i][1])
        if time > due:
            print('No')
            exit()
    
    print('Yes')
    return 0

solve()

Fixed code:
def solve():
    n = int(input())
    task = [0]*n
    for i in range(n):
        a,b = map(int,input().split())
        task[i] = [a,b]
    
    task = sorted(task, key= lambda x : x[1])
    time = 0
    due = 0

    for i in range(n):
        time += task[i][0]
        due = max(due,task[i][1])
        if time > due:
            print('No')
            exit()
    
    print('Yes')
    return 0

solve()
Buggy code:
import sys, fractions

readline = sys.stdin.readline

N = int(readline())
AB = [list(map(int, readline().split())) for i in range(N)]

AB.sort(key=lambda x:x[1])

t = 0
for a, b in AB:
    t += a
    if t > b:
        print('NO')
        exit(0)

print('YES')

Fixed code:
import sys, fractions

readline = sys.stdin.readline

N = int(readline())
AB = [list(map(int, readline().split())) for i in range(N)]

AB.sort(key=lambda x:x[1])

t = 0
for a, b in AB:
    t += a
    if t > b:
        print('No')
        exit(0)

print('Yes')
Buggy code:
N = int(input())
lis = []
for i in range(N):
    lis.append(map(int,input().split()))
lis.sort(key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')

Fixed code:
N = int(input())
lis = []
for i in range(N):
    lis.append(list(map(int,input().split())))
lis = sorted(lis, key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')
Buggy code:
N = int(input())
AB = [[int(c) for c in input().split()] for _ in range(N)]

s=0
possible=True
for a, b in sorted(AB, key=lambda x:x[1]):
    s+=a
    if s>b:
	possible = False
        break

print('Yes' if possible else 'No')

Fixed code:
N = int(input())
AB = [[int(c) for c in input().split()] for _ in range(N)]

s=0
possible=True
for a, b in sorted(AB, key=lambda x:x[1]):
    s+=a
    if s>b:
        possible = False
        break

print('Yes' if possible else 'No')
Buggy code:
N=int(input())
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB,key = lambda x:x[1])
S=0
flag=0
for i in range(N):
    S+=AB[i][0]
    if S>= AB[i][1]:
        print("No")
        flag=1
        break
if flag == 0:
    print("Yes")


Fixed code:
N=int(input())
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB,key = lambda x:x[1])
S=0
flag=0
for i in range(N):
    S+=AB[i][0]
    if S> AB[i][1]:
        print("No")
        flag=1
        break
if flag == 0:
    print("Yes")
Buggy code:
N = int(input())
p = [[0,0]]*N
for i in range(N):
  p[i] = input().split()
  p[i] = list(map(int,p[i]))
p = sorted(p,key = lambda x:x=p[1])
s = [0]*N
s[0] = p[0][0]
for i in range(N-1):
  s[i+1] = s[i] + p[i+1][0]
k = 0
for i in range(N):
  if s[i] <= p[i][1]:
    k = k + 1
  else:
    print('No')
    break
if k == N:
  print('Yes')

Fixed code:
N = int(input())
p = [[0,0]]*N
for i in range(N):
  p[i] = input().split()
  p[i] = list(map(int,p[i]))
p = sorted(p,key = lambda p:p[1])
s = [0]*N
s[0] = p[0][0]
for i in range(N-1):
  s[i+1] = s[i] + p[i+1][0]
k = 0
for i in range(N):
  if s[i] <= p[i][1]:
    k = k + 1
  else:
    print('No')
    break
if k == N:
  print('Yes')
Buggy code:
a = [int(input()) for i in range(1)]
n = a[0]
works = [list(map(int, input().split())) for i in range(n)]
#print(works)  
works = sorted(works, key=lambda x: x[1])
print(works)
work_time = 0
for w in works:
  work_time += w[0]
  if work_time > w[1]:
    print("No")
    print(w)
    break
else:
  print("Yes")


Fixed code:
a = [int(input()) for i in range(1)]
n = a[0]
works = [list(map(int, input().split())) for i in range(n)]
#print(works)  
works = sorted(works, key=lambda x: x[1])
work_time = 0
for w in works:
  work_time += w[0]
  if work_time > w[1]:
    print("No")
    break
else:
  print("Yes")
Buggy code:
import math

N = int(input())
task = {}
for i in range(N):
    tmp = input().split()
    A = int(tmp[0])
    B = int(tmp[1])
    task[B] = A
    # if B in task:
    #     task[B].append(A)
    # else:
    #     task[B] = [A]

s = 0
for b in sorted(task.keys()):    
    s = task[b]
    if b<s:
        print('No')
        exit()

print('Yes')

Fixed code:
import math

N = int(input())
task = {}
tasks = []
for i in range(N):
    tmp = input().split()
    A = int(tmp[0])
    B = int(tmp[1])
    tasks.append((B,A))
    task[B] = A
    # if B in task:
    #     task[B].append(A)
    # else:
    #     task[B] = [A]

s = 0
# for b in sorted(task.keys()):    
#     s += task[b]
#     if b<s:
#         print('No')
#         exit()

for (b,a) in sorted(tasks):
    s += a
    if b<s:
        print('No')
        exit()

print('Yes')
Buggy code:
from collections import defaultdict
a=defaultdict(list)
n = int(input())
for i in range(n):
    h,m=list(map(int,input().split()))
    a[m].append(h)
t=0
r=0

for i in a:
    for j in a[i]:
        t+=j
    if t>i:
        r=1
        break
if r==1:
    print('No')
else:
    print('Yes')

Fixed code:

from collections import defaultdict
d=set()
a=defaultdict(list)
n = int(input())
for i in range(n):
    h,m=list(map(int,input().split()))
    a[m].append(h)
    d.add(m)
t=0
r=0

for i in sorted(d):
    for j in a[i]:
        t+=j
    if t>i:
        r=1
        break
if r==1:
    print('No')
else:
    print('Yes')