qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
l = []

for i in range(N):
    a, b = map(int, input().split())
    l.append((a+b,a-b))

l = sorted(l,key=lambda x:x[1])

start = l[0][1]
ans = 1
for i in range(1,N):
    if start <= l[i][0]:
        start = l[i][0]
        ans += 1
        
print(ans)

Fixed code:
N = int(input())
l = []

for i in range(N):
    a, b = map(int, input().split())
    l.append((a-b,a+b))

l = sorted(l,key=lambda x:x[1])

start = l[0][1]
ans = 1
for i in range(1,N):
    if start <= l[i][0]:
        start = l[i][1]
        ans += 1

print(ans)
Buggy code:
n=int(input())
d=sorted([list(map(int,input().split()))for i in range(n)],key=lambdax:x[0]+x[1])
c=-float("INF")
an=0
for i,j in d:
    if i-j>=c:
        an+=1
        c=i+j
print(an)

Fixed code:
n=int(input())
d=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0]+x[1])
c=-float("INF")
an=0
for i,j in d:
    if i-j>=c:
        an+=1
        c=i+j
print(an)
Buggy code:
import numpy as np

n = int(input())

left = np.zeros(n)
right = np.zeros(n)
for i in range(n):
    x, l = map(int, input().split())
    left[i] = x-l
    right[i] = x+l

sort_ind = np.argsort(right)
left = left[sort_ind]
right = right[sort_ind]

ans = 0
right_now = -1
for i in range(n):
    if(left[i] >= right_now):
        ans += 1
        tright_now = right[i]

print(ans)

Fixed code:
import numpy as np

n = int(input())

left = np.zeros(n)
right = np.zeros(n)
for i in range(n):
    x, l = map(int, input().split())
    left[i] = int(x-l)
    right[i] = int(x+l)

sort_ind = np.argsort(right)
left = left[sort_ind]
right = right[sort_ind]

ans = 0
right_now = -1 * 10**10
for i in range(n):
    if(left[i] >= right_now):
        ans += 1
        right_now = right[i]

print(ans)
Buggy code:
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
a = [[a[i][0]-a[i][1],a[i][0]+a[i][1]] for i in range(n)]
a.sort(key = lambda x:x[1])
ans = 1
g = a[0][1]
for i in range(1,n):
  x = a[i][0]
  if g>=x:
    ans += 1
    g = a[i][1]
print(ans)

Fixed code:
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
a = [[a[i][0]-a[i][1],a[i][0]+a[i][1]] for i in range(n)]
a.sort(key = lambda x:x[1])
ans = 1
g = a[0][1]
for i in range(1,n):
  x = a[i][0]
  if g<=x:
    ans += 1
    g = a[i][1]
print(ans)
Buggy code:
from collections import defaultdict

def main():
    N = int(input())
    robots = {}
    for _ in range(N):
        x,l = [int(x) for x in input().split()]
        robots.update({x-l:x+l})

    print(sorted(robots.items(), key=lambda x:x[1]))
    cnt = 0
    t = -float('inf')
    for start,end in sorted(robots.items(), key=lambda x:x[1]):
        print(t,start)
        if t <= start:
            print('append')
            cnt += 1
            t = end
    print(cnt)
        

if __name__ == '__main__':
    main()

Fixed code:
from collections import defaultdict

def main():
    N = int(input())
    robots = []
    for _ in range(N):
        x,l = [int(x) for x in input().split()]
        robots.append((x-l, x+l))

    # print(sorted(robots.items(), key=lambda x:x[1]))
    cnt = 0
    t = -float('inf')
    for start,end in sorted(robots, key=lambda x:x[1]):
        # print(t,start)
        if t <= start:
            # print('append')
            cnt += 1
            t = end
    print(cnt)
        

if __name__ == '__main__':
    main()
Buggy code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    lis = []
    for _ in range(n):
        x, l = LI()
        lis.append((x + l, x - l))
    lis.sort()
    ans = 0
    now = 0
    for r, l in lis:
        if now <= l:
            now = r
            ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Fixed code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    lis = []
    for _ in range(n):
        x, l = LI()
        lis.append((x + l, x - l))
    lis.sort()
    ans = 0
    now = -inf
    for r, l in lis:
        if now <= l:
            now = r
            ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()
Buggy code:
n = int(input())

arms = []
for i in range(n):
  x, l = [int(i) for i in input().split(' ')]
  arms.append({"st": x-l, "ed": x+l})

arms.sort(key=lambda x: x["ed"])
print(arms)

n_arm = 1
tot_end = arms[0]["ed"]

for i in range(1, n):
  if tot_end <= arms[i]["st"]:
    n_arm += 1
    tot_end = arms[i]["ed"]

print(n_arm)


Fixed code:
n = int(input())

arms = []
for i in range(n):
  x, l = [int(i) for i in input().split(' ')]
  arms.append({"st": x-l, "ed": x+l})

arms.sort(key=lambda x: x["ed"])

n_arm = 1
tot_end = arms[0]["ed"]

for i in range(1, n):
  if tot_end <= arms[i]["st"]:
    n_arm += 1
    tot_end = arms[i]["ed"]

print(n_arm)
Buggy code:
n = int(input())
robots = []
for _ in range(n):
    xi, li = map(int, input().split())
    robots.append((xi - li, xi + li))
robots.sort(key=lambda x: x[1])
ans = n
pre_r = -float('inf')
for l, r in robots:
    if pre_r <= l:
        ans += 1
        pre_right = r
print(ans)

Fixed code:
n = int(input())
robots = []
for _ in range(n):
    xi, li = map(int, input().split())
    robots.append((xi - li, xi + li))
robots.sort(key=lambda x: x[1])
ans = 0
pre_r = -float('inf')
for l, r in robots:
    if pre_r <= l:
        ans += 1
        pre_r = r
print(ans)
Buggy code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x+l+1, x-l-1))
    X.sort()
    ans = 1
    now = X[0][0]
    for i in range(1,N):
        b, a = X[i]
        if now +1< a:
            now = b
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()


Fixed code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x+l, x-l))
    X.sort()
    ans = 1
    now = X[0][0]
    for i in range(1,N):
        b, a = X[i]
        if now <= a:
            now = b
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
l = []
for _ in range(n):
  x,y = map(int, input().split())
  l.append([x+y,x-y])
l.sort()

temp = l[0][1]
count = n
i = 1
while(i<n):
  if temp <= l[i][1]:
    i = i + 1
  else:
    temp = min(temp,l[i][1])
    count -= 1
    i = i + 1
print(count)

Fixed code:
n = int(input())
l = []
for _ in range(n):
  x,y = map(int, input().split())
  l.append([x+y,x-y])
l.sort()

temp = l[0][0]
count = n
i = 1
for i in range(1,n):
  if temp <= l[i][1]:
    temp = l[i][0]
  else:
    temp = min(temp,l[i][0])
    count -= 1
print(count)
Buggy code:
N = int(input())
XL = sorted([list(map(int, input().split())) for _ in range(N)])

remove = 0
reach = 0

for i in range(N):
    r = XL[i]
    right = r[0] + r[1]
    left = r[0] - r[1]

    if i == 0:
        reach = right
        continue

    if reach > left:
        reach = max(reach, right)
        remove += 1
    else:
        reach = right

print(N - remove)


Fixed code:
N = int(input())
XL = sorted([list(map(int, input().split())) for _ in range(N)])

remove = 0
reach = 0

for i in range(N):
    r = XL[i]
    right = r[0] + r[1]
    left = r[0] - r[1]

    if i == 0:
        reach = right
        continue

    if reach > left:
        reach = min(reach, right)
        remove += 1
    else:
        reach = right

print(N - remove)
Buggy code:
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
    s,t = x-l, x+l
    if s > right:
        right = t
        ans += 1
print(ans)


Fixed code:
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
    s,t = x-l, x+l
    if s >= right:
        right = t
        ans += 1
print(ans)
Buggy code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n = int(input())
    x, l = [0]*n, [0]*n
    for i in range(n):
        x[i], l[i] = map(int, input().split())
    hoge = []
    for i in range(n):
        hoge.append(x+l)
    t = 0
    for i in range(n):
        if t < hoge[i]:
            ans += 1
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Fixed code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n = int(input())
    x, l = [0]*n, [0]*n
    for i in range(n):
        x[i], l[i] = map(int, input().split())
    hoge = []
    for i in range(n):
        hoge.append([x[i]+l[i], x[i]-l[i]])
    hoge.sort()
    t = -1000000000000000000000
    ans = 0
    for i in range(n):
        if t <= hoge[i][1]:
            ans += 1
            t = hoge[i][0]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()
Buggy code:
n = int(input())
r = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
  r[i] = [r[i][0] - r[i][1], r[i][0] + r[i][1]]
r.sort(key = lambda x:x[1])
print(r)
cur = -1001001001
ans = 0
for i in range(n):
  if cur <= r[i][0]:
    ans += 1
    cur = r[i][1]
print(ans)

Fixed code:
n = int(input())
r = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
  r[i] = [r[i][0] - r[i][1], r[i][0] + r[i][1]]
r.sort(key = lambda x:x[1])
#print(r)
cur = -1001001001
ans = 0
for i in range(n):
  if cur <= r[i][0]:
    ans += 1
    cur = r[i][1]
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 07:49:36 2020

@author: naoki
"""


N = int(input())
xl = [list(map(int, input())) for _ in range(N)]

left_right = [[row[0]-row[1], row[0]+row[1]] for row in xl]
left_right = sorted(left_right, key = lambda x:int(x[1]))
count = 0
now = -10000
for row in (left_right):
    if row[0] < now:
        continue
    else:
        count += 1
        now = row[1]


Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 07:49:36 2020

@author: naoki
"""
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]

left_right = [[row[0]-row[1], row[0]+row[1]] for row in xl]
left_right = sorted(left_right, key = lambda x:int(x[1]))
count = 0
now = -100000000000
for row in (left_right):
    if row[0] < now:
        continue
    else:
        count += 1
        now = row[1]
print(count)
Buggy code:
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)
print(ll)

ans = n
r = ll.pop(0)[1]

while ll:
  while ll and ll[0][0] < r:
    ans -= 1
    ll.pop(0)
  if ll:
    r = ll.pop(0)[1]

print(ans)

Fixed code:
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

print(ans)
Buggy code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
rl = []
for i in range(N):
    rl.append((xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]))
rl.sort(key=lambda x: x[1])
cnt = 0
tmp = -10 ** 18
print(rl)
for i, j in rl:
    if tmp <= i:
        cnt += 1
        tmp = j
print(cnt)

Fixed code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
rl = []
for i in range(N):
    rl.append((xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]))
rl.sort(key=lambda x: x[1])
cnt = 0
tmp = -10 ** 18

for i, j in rl:
    if tmp <= i:
        cnt += 1
        tmp = j
print(cnt)
Buggy code:
from operator import itemgetter

N = int(input())

X = []
L = []

for i in range(N):
    a,b = map(int,input().split())
    X.append(a-b)
    L.append(a+b)

xl = sorted([(X[i],L[i]) for i in range(N)], key = itemgetter(1))

ans = 0
last = 0

for i in range(N):
    if last <= xl[i][0]:
        ans += 1
        last = xl[i][1]

print(ans)


Fixed code:
from operator import itemgetter

N = int(input())

X = []
L = []

for i in range(N):
    a,b = map(int,input().split())
    X.append(a-b)
    L.append(a+b)

xl = sorted([(X[i],L[i]) for i in range(N)], key = itemgetter(1))

ans = 0
last = -float("inf")

for i in range(N):
    if last <= xl[i][0]:
        ans += 1
        last = xl[i][1]

print(ans)
Buggy code:
N = int(input())
R = []
for _ in range(N):
    x, l = map(int, input().split())
    R.append([x-l, x+l])

R = sorted(R, key=lambda x: x[1])

ans = 0
tmp = -float('inf')
for l, r in R:
    if tmp <= r:
        ans += 1
        tmp = l
print(ans)


Fixed code:
N = int(input())
R = []
for _ in range(N):
    x, l = map(int, input().split())
    R.append([x-l, x+l])

R = sorted(R, key=lambda x: x[1])

ans = 0
tmp = -float('inf')
for l, r in R:
    if tmp <= l:
        ans += 1
        tmp = r
print(ans)
Buggy code:
n = int(input())
xl = sorted([tuple(map(int, input().split())) for _ in range(n)])

tmp = sum(xl[0])

res = 0
for i in range(1, n):
    x, l = xl[i]
    if tmp >= x-l:
        res += 1
    else:
        tmp = x+l

print(n-res)

Fixed code:
n = int(input())
xl = sorted([tuple(map(int, input().split())) for _ in range(n)])

tmp = sum(xl[0])

res = 0
for i in range(1, n):
    x, l = xl[i]
    if tmp > x-l:
        res += 1
        tmp = min(tmp, x+l)
    else:
        tmp = x+l

print(n-res)
Buggy code:
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: 10000000000 * student[0] + student[1])


now = -100000000000
ans = 0
for i in fanwei:
    down = i[0] - i[1]
    if down >= now:
        ans += 1
        now = i[0] + i[1]

print(ans)

Fixed code:
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: student[0] + 100000000000000000000 * student[1])

now = -100000000000000000000
ans = 0
for i in fanwei[:]:
    down = i[0]
    if down >= now:
        ans += 1
        now = i[1]


print(ans)
Buggy code:
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
a = []
for i in r:
    a.append((i[0]-i[1],i[0]+i[1]))
a.sort(key=lambda x:x[1])
ans = 0
cur = -float('inf')
for i in a:
    if i[0] < cur:
        continue
    ans += 1
    cur = i[1]
print(a)
print(ans)

Fixed code:
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
a = []
for i in r:
    a.append((i[0]-i[1],i[0]+i[1]))
a.sort(key=lambda x:x[1])
ans = 0
cur = -float('inf')
for i in a:
    if i[0] < cur:
        continue
    ans += 1
    cur = i[1]
print(ans)
Buggy code:
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
a = []
for i in r:
    a.append((i[0]+i[1],i[0]-i[1]))
a.sort()
ans = 0
cur = a[0][0]
for i in a:
    if i[1] < cur:
        continue
    ans += 1
    cur = i[0]
print(ans)

Fixed code:
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
a = []
for i in r:
    a.append((i[0]+i[1],i[0]-i[1]))
a.sort()
ans = 0
cur = a[0][1]
for i in a:
    if i[1] < cur:
        continue
    ans += 1
    cur = i[0]
print(ans)
Buggy code:
n = int(input())

machines = []
for i in range(n):
  x, l = map(int, input().split())
  machines.append([x+l, x-l])
machines.sort()

ans = 1
first = machines.pop(0)
stock_r = first[1]
for r,l in machines:
  if stock_r > l:
    break
  else:
    ans += 1
    stock_r = r

print(ans)

Fixed code:
n = int(input())

machines = []
for i in range(n):
  x, l = map(int, input().split())
  machines.append([x+l, x-l])
machines.sort()

ans = 1
first = machines.pop(0)
stock_r = first[0]
for r,l in machines:
  if stock_r > l:
    continue
  else:
    ans += 1
    stock_r = r

print(ans)
Buggy code:
def solve(N, XL):
    XL_re = [[xl[0] - xl[1], xl[0] + xl[1]] for xl in XL]
    XL_re = sorted(XL_re, key=lambda x: x[1])

    cnt = 0
    for i, xl in enumerate(XL_re):
        if i == 0:
            tmp = xl[1]
            cnt += 1
        else:
            if tmp <= xl[0]:
                tmp = xl[1]
                cnt += 1
    return cnt

def test():
    assert solve(4, [[2, 4], [4, 3], [9, 3], [100, 5]]) == 3

def main():
    N = int(input())
    XL = [list(map(int, input().split())) for _ in range(N)]
    ans = main(N, XL)
    print(ans)

if __name__ == "__main__":
    # test()
    main()


Fixed code:
def solve(N, XL):
    XL_re = [[xl[0] - xl[1], xl[0] + xl[1]] for xl in XL]
    XL_re = sorted(XL_re, key=lambda x: x[1])

    cnt = 0
    for i, xl in enumerate(XL_re):
        if i == 0:
            tmp = xl[1]
            cnt += 1
        else:
            if tmp <= xl[0]:
                tmp = xl[1]
                cnt += 1
    return cnt

def test():
    assert solve(4, [[2, 4], [4, 3], [9, 3], [100, 5]]) == 3

def main():
    N = int(input())
    XL = [list(map(int, input().split())) for _ in range(N)]
    ans = solve(N, XL)
    print(ans)

if __name__ == "__main__":
    # test()
    main()
Buggy code:
from collections import deque

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

p = deque()

for i in list:
  p.append([i[0] - i[1],i[0] + i[1]])
  
p = sorted(p,key = lambda x: x[1])

ex = []
ex.append(p.pop(left))




for i in range(len(p)):
  if(ex[-1][1] <= p[0][0]):
    ex.append(p.pop(left))
  else:
    p.pop(left)

print(len(ex))

Fixed code:
from collections import deque

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

p = deque()

for i in list:
  p.append([i[0] - i[1],i[0] + i[1]])
  
p = sorted(p,key = lambda x: x[1])

ex = []
ex.append(p.pop(0))




for i in range(len(p)):
  if(ex[-1][1] <= p[0][0]):
    ex.append(p.pop(0))
  else:
    p.pop(0)

print(len(ex))
Buggy code:
N=int(input())
ES = []
for i in range(N):
    x,l = list(map(int,input().split()))
    ES.append((x+l,x-l))

ES = sorted(ES)

sel = []
cur = None
ans = 0
for E,S in ES:
    if cur is None or cur <= S:
        sel.append((S,E))
        cur = E
print(ans)



Fixed code:
N=int(input())
ES = []
for i in range(N):
    x,l = list(map(int,input().split()))
    ES.append((x+l,x-l))
 
ES = sorted(ES)

sel = []
cur = None
ans = 0
for E,S in ES:
    if cur is None or cur <= S:
        sel.append((S,E))
        cur = E
        ans += 1
print(ans)
Buggy code:
n=int(input())
A=[[] for i in range(n)]
for i in range(n):
    x,l=map(int,input().split())
    A[i]=[x-l,x+l]
A=sorted(A, key=lambda x :x[1])
print(A)

ans=0
last=-float("INF")
for i in range(n):
    if last<=A[i][0]:
        ans+=1
        last=A[i][1]

print(ans)

Fixed code:
n=int(input())
A=[[] for i in range(n)]
for i in range(n):
    x,l=map(int,input().split())
    A[i]=[x-l,x+l]
A=sorted(A, key=lambda x :x[1])
#print(A)

ans=0
last=-float("INF")
for i in range(n):
    if last<=A[i][0]:
        ans+=1
        last=A[i][1]

print(ans)
Buggy code:
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def f(A):
    min_num = A[0] + A[-1]


def main():
    N = int(input())
    R = []
    for _ in range(N):
        X, L = map(int, input().split())
        R.append((X - L, X + L))
    
    R.sort(key=lambda l: l[1])

    print(R)
    res = 0
    T = None    
    for r in R:
        if T is None or r[0] >= T:
            T = r[1]
            res += 1

    print(res)


if __name__ == "__main__":
    main()


Fixed code:
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def f(A):
    min_num = A[0] + A[-1]


def main():
    N = int(input())
    R = []
    for _ in range(N):
        X, L = map(int, input().split())
        R.append((X - L, X + L))
    
    R.sort(key=lambda l: l[1])

    res = 0
    T = None    
    for r in R:
        if T is None or r[0] >= T:
            T = r[1]
            res += 1

    print(res)


if __name__ == "__main__":
    main()
Buggy code:
N = int(input())
XLlist = [tuple(map(int, input().split())) for _ in range(N)]
XLlist.sort(key=lambda x: x[0])
ans = 1
tikan = -1
x, l = XLlist[0]
rl = x + (l - 1)
for x, l in XLlist:
    ll = x - l
    if ll < rl:
        tikan += 1
        rl = min(rl, x + l - 1)
    else:
        ans += 1
        rl = x + l - 1

print(ans + 1)


Fixed code:
N = int(input())
XLlist = [tuple(map(int, input().split())) for _ in range(N)]
XLlist.sort(key=lambda x: x[0])
ans = 1
x, l = XLlist[0]
rl = x + (l - 1)
for x, l in XLlist:
    ll = x - l
    if ll <= rl:
        rl = min(rl, x + l - 1)
    else:
        ans += 1
        rl = x + l - 1

print(ans)
Buggy code:
import sys
input = sys.stdin.readline

N = int(input())
XL = []
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    XL.append(tmp)
LR = []
for i in XL:
    LR.append([i[0] - i[1], i[0] + i[1]])
LR.sort()
ans = N
last = LR[0][1]
for i in range(1, N - 1):
    if last > LR[i][0]:
        if last > LR[i][1]:
            last = LR[i][1]
        ans -= 1
    else:
        last = LR[i][1]
print(ans)


Fixed code:
import sys
input = sys.stdin.readline

N = int(input())
XL = []
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    XL.append(tmp)
LR = []
for i in XL:
    LR.append([i[0] - i[1], i[0] + i[1]])
LR.sort()
ans = N
last = LR[0][1]
for i in range(1, N):
    if last > LR[i][0]:
        if last > LR[i][1]:
            last = LR[i][1]
        ans -= 1
    else:
        last = LR[i][1]
print(ans)
Buggy code:
n = int(input())
scope = []
for _ in range(n):
    x, l = map(int, input().split())
    scope.append([x+l, x-l])
    
scope.sort()
ans = 1
border = scope[0][0]
for i, r in enumerate(scope[1:]):
    if border <= r[0]:
        ans += 1
        border = r[1]
print(ans)


Fixed code:
n = int(input())
scope = []
for _ in range(n):
    x, l = map(int, input().split())
    scope.append([x+l, x-l])
    
scope.sort()
ans = 1
border = scope[0][0]
for i, r in enumerate(scope[1:]):
    if border <= r[1]:
        ans += 1
        border = r[0]
print(ans)