Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def lun(s):
    ch = 1
    temp = int(s[0])
    for i in s[1: ]:
        i = int(i)
        if abs(i - temp) > 1:
            ch = 0
            break
        temp = i
    return ch
k = int(input())
d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
l = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
while 1:
    for i in l:
        for j in d:
            # print(i, j)
            s = i + str(j)
            if lun(s): l.append(s)
        if len(l) >= 10000: break
    if len(l) >= 10000: break
k = input()
print(l[k])

Fixed submission:
def lun(s):
    ch = 1
    temp = int(s[0])
    for i in s[1: ]:
        i = int(i)
        if abs(i - temp) > 1:
            ch = 0
            break
        temp = i
    return ch
k = int(input())
d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
l = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
while 1:
    for i in l:
        for j in d:
            # print(i, j)
            s = i + str(j)
            if lun(s): l.append(s)
        if len(l) >= 100002: break
    if len(l) >= 100002: break
print(l[k - 1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
freq = [0] * (10**5 + 5)
for i in l: freq[i] -= -1
count = 0
for i in range(10**5 + 5):
    if freq[i] >= 2:
        temp = (freq[i] * (freq[i] - 1)) // 2
        count += temp
for i in l:
    if freq[i] == 1: print(count)
    else:
        temp = freq[i] - 1
        if temp == 1: print(count - 1)
        else:
            yoyo = ((freq[i] * (freq[i] - 1)) // 2) - ((temp * (temp - 1)) // 2)
            print(count - yoyo)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
freq = [0] * (2 * (10**5) + 5)
for i in l: freq[i] -= -1
count = 0
for i in range(2 * (10**5) + 5):
    if freq[i] >= 2:
        temp = (freq[i] * (freq[i] - 1)) // 2
        count += temp
for i in l:
    if freq[i] == 1: print(count)
    else:
        temp = freq[i] - 1
        if temp == 1: print(count - 1)
        else:
            yoyo = ((freq[i] * (freq[i] - 1)) // 2) - ((temp * (temp - 1)) // 2)
            print(count - yoyo)
Buggy python submission (verdict: Runtime Error):
import math
a, b, x = [int(x) for x in input().split()]
y = 2 * (b - (x / (a * a)))
if y <= b:
    value = a / y
    print(90 - math.degrees(math.atan(value)))
else:
    y = (2 * x) / (a * b)
    v = b / y
    print(math.degrees(math.atan(v)))

Fixed submission:
import math
a, b, x = [int(x) for x in input().split()]
y = 2 * (b - (x / (a * a)))
if x == a * a * b: print(0)
elif y <= b:
    value = a / y
    print(90 - math.degrees(math.atan(value)))
else:
    y = (2 * x) / (a * b)
    v = b / y
    print(math.degrees(math.atan(v)))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
if(a >= 13):
	print(b)
else if(a >= 6):
	print(b // 2)
else:
	print(0)

Fixed submission:
a,b = map(int,input().split())
if(a >= 13):
	print(b)
elif(a >= 6):
	print(b // 2)
else:
	print(0)
Buggy python submission (verdict: Runtime Error):
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)
 
dp=[[0 for i in range(K+1)] for j in range(N)]
 
for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:j+1])
 
for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:K])
 
print(dp[N-1][K])

Fixed submission:
N = int(input())
h = list(map(int,input().split()))

dp=[]
dp.append(0)
dp.append(abs(h[0]-h[1]))

for i in range (2,N):
    dp.append(min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)
 
dp=[[0 for i in range(K+1)] for j in range(N)]
 
for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:j+1])
 
for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:K])
 
print(dp[N-1][K])

Fixed submission:
N, K = map(int,input().split())
h = list(map(int,input().split()))

INF = 10e9
dp=[INF]*N
dp[0]=0

for i in range (0,N):
    for j in range(i+1, min(N,i+K+1)):
        dp[j] = min(abs(h[i]-h[j])+dp[i],dp[j])

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)
 
dp=[[0 for i in range(K+1)] for j in range(N)]
 
for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:j+1])
 
for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:K])
 
print(dp[N-1][K])

Fixed submission:
N, K = map(int,input().split())
h = list(map(int,input().split()))

INF = 10e9
dp=[INF]*N
dp[0]=0

for i in range (0,N):
    for j in range(i+1, min(N,i+K+1)):
        dp[j] = min(abs(h[i]-h[j])+dp[i],dp[j])

print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        m =  (4*a*b) - N*(a+b)
        if m> 0 & N*a*b % m == 0:
            c = (N*a*b)//m
            break
    else:
        continue
    break
print(a,b,c)


Fixed submission:
N = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        m =  (4*a*b) - N*(a+b)
        if m> 0 and N*a*b % m == 0:
            c = (N*a*b)//m
            break
    else:
        continue
    break
print(a,b,c)

Buggy python submission (verdict: Runtime Error):
N = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        m =  (4*a*b) - N*(a+b)
        if m>= 0 & N*a*b % m == 0:
            c = (N*a*b)//m
            break
    else:
        continue
    break
print(a,b,c)


Fixed submission:
N = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        m =  (4*a*b) - N*(a+b)
        if m> 0 and N*a*b % m == 0:
            c = (N*a*b)//m
            break
    else:
        continue
    break
print(a,b,c)
Buggy python submission (verdict: Runtime Error):
MOD = 998244353


class DP:

    def __init__(self, X, Y, Z):
        self._X = X
        self._Y = Y
        self._Z = Z
        self._list = [0] * (X * Y * Z)
    
    def get(self, x, y, z):
        return self._list[x*(self._Y*self._Z) + y*self._Z + z]
    
    def set(self, x, y, z, v):
        self._list[x*(self._Y*self._Z) + y*self._Z + z] = v


def solve():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    # dp = [[[0 for _ in range(3)] for _ in range(S+1)] for _ in range(N+1)]
    dp = DP(N+1, S+1, 3)

    # dp[0][0][0] = 1
    dp.set(0, 0, 0, 1)

    for i in range(0, N):
        for s in range(0, S+1):
            # dp[i+1][s][0] = dp[i][s][0]
            dp.set(i+1, s, 0, dp.get(i, s, 0))
            if s - A[i] >= 0:
                # dp[i+1][s][1] = (dp[i][s][1] + dp[i][s][0] + dp[i][s-A[i]][1] + dp[i][s-A[i]][0]) % MOD
                dp.set(i+1, s, 1, (dp.get(i, s, 1) + dp.get(i, s, 0) + dp.get(i, s-A[i], 1) + dp.get(i, s-A[i], 0)) % MOD)
                # dp[i+1][s][2] = (dp[i][s][2] + dp[i][s][1] + dp[i][s][0] + dp[i][s-A[i]][1] + dp[i][s-A[i]][0]) % MOD
                dp.set(i+1, s, 2, (dp.get(i, s, 2) + dp.get(i, s, 1) + dp.get(i, s, 0) + dp.get(i, s-A[i], 1) + dp.get(i, s-A[i], 0)) % MOD)
            else:
                # dp[i+1][s][1] = (dp[i][s][1] + dp[i][s][0]) % MOD
                dp.set(i+1, s, 1, (dp.get(i, s, 1) + dp.get(i, s, 0)) % MOD)
                # dp[i+1][s][2] = (dp[i][s][2] + dp[i][s][1] + dp[i][s][0]) % MOD
                dp.set(i+1, s, 2, (dp.get(i, s, 2) + dp.get(i, s, 1) + dp.get(i, s, 0)) % MOD)

    # print(dp[N][S][2])
    print(dp.get(N, S, 2))


solve()


Fixed submission:
N, M = map(int, input().split())

print((N * (N-1) // 2) + (M * (M-1) // 2))
Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())
S = input()

if P == 2 or P == 5:
    res = 0

    for i in range(N):
        if int(S[i]) % P == 0:
            res += i + 1
    
    print(res)

else:
    res = 0
    count = [0] * P

    for i in range(N-1, -1, -1):
        n = int(S[i:N])
        r = n % P
        if r == 0: res += 1
        res += count[r]
        count[r] += 1
    
    print(res)


Fixed submission:
def solve():
    N, P = map(int, input().split())
    S = input()

    if P == 2 or P == 5:
        res = 0

        for i in range(N):
            if int(S[i]) % P == 0:
                res += i + 1
        
        print(res)

    else:
        res = 0
        count = [0] * P
        r = 0

        for i in range(N-1, -1, -1):
            r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P
            if r == 0: res += 1
            res += count[r]
            count[r] += 1
        
        print(res)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(S == U) score[0]--;
		else score[1]--;
		Console.WriteLine(String.Join(" ",score));
	}
	String S,T;
	int[] score;
	String U;
	public Sol(){
		var ss = rsa();
		S = ss[0]; T = ss[1];
		score = ria();
		U = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Fixed submission:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    s, t = rsa()
    a, b = ria()
    u = rs()
    if s == u: a -= 1
    if t == u: b -= 1
    print("{0} {1}".format(a,b))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

def inv(v, mod):
    return pow(v, mod-2, mod)
def main():
    r1, c1, r2, c2 = rip()

    MM = int(2e6+10)
    fact = [0] * MM
    finv = [0] * MM
    fact[0] = 1
    finv[0] = 1
    mod = int(1e9) + 7
    for i in range(1,MM): fact[i] = (fact[i-1] * i % mod)
    finv[MM-1] = inv(fact[MM-1], mod)
    for i in reversed(range(1,MM-1)):
        finv[i] = finv[i + 1] * (i + 1) % mod
    def sum(r, c):
        #[0, r) * [0, c)
        ret = 0
        for i in range(r):
            ret += fact[i + 1 + c - 1] * finv[i + 1] * finv[c - 1] % mod
        return ret
    ans = 0
    ans += sum(r2 + 1, c2 + 1)
    ans -= sum(r2 + 1, c1)
    ans -= sum(r1, c2 + 1)
    ans += sum(r1, c1)
    ans %= mod
    print(ans)



if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

def inv(v, mod):
    return pow(v, mod-2, mod)
def main():
    r1, c1, r2, c2 = rip()

    MM = int(2e6+10)
    fact = [0] * MM
    finv = [0] * MM
    fact[0] = 1
    finv[0] = 1
    mod = int(1e9) + 7
    for i in range(1,MM): fact[i] = (fact[i-1] * i % mod)
    finv[MM-1] = inv(fact[MM-1], mod)
    for i in reversed(range(1,MM-1)):
        finv[i] = finv[i + 1] * (i + 1) % mod
    def sum_naive(r, c):
        #[0, r) * [0, c)
        ret = 0
        for i in range(r):
            ret += fact[i + 1 + c - 1] * finv[i + 1] * finv[c - 1] % mod
        return ret
    def sum(r, c):
        #[0, r) * [0, c)
        ret = fact[r + c] * finv[r] * finv[c] % mod
        ret += -1 + mod
        ret %= mod
        return ret

    ans = 0
    ans += sum(r2 + 1, c2 + 1)
    ans -= sum(r2 + 1, c1)
    ans -= sum(r1, c2 + 1)
    ans += sum(r1, c1)
    ans %= mod
    print(ans)



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = []
    T = []
    for i in range(N):
        S[i], T[i] = rip()
    X = ri()

    ans = 0
    sleep = False
    for i in range(N):
        if S[i] == X:
            sleep = True
            continue
        if sleep:
            ans += T[i]
    
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = ["a"] * N
    T = [0] * N
    for i in range(N):
        ss = rsa()
        S[i] , T[i] = ss[0], int(ss[1])
    X = rs()

    ans = 0
    sleep = False
    for i in range(N):
        if S[i] == X:
            sleep = True
            continue
        if sleep:
            ans += T[i]
    
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
import math
def main():
    A, B = rip()
    g = math.gcd(A, B)
    print(A // g * B)
    

if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin
import sys
import math
import numpy as np
##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    A, B = rip()
    def gcd(a, b):
        return b if a == 0 else gcd(b % a, a)
    g = gcd(A, B)
    print(A // g * B)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = [""] * N
    for i in range(N): S[i] = rs()

    bw = [-1] * N
    q = collections.deque()
    bw[0] = 0
    q.append(0)
    while(len(q) > 0):
        now = q.popleft()
        for nxt in range(N):
            if S[now][nxt] == '0': continue
            if bw[nxt] == -1:
                bw[nxt] = bw[now] ^ 1
                q.append(nxt)
            elif bw[nxt] == bw[now]:
                print(-1)
                sys.exit(0)
    
    inf = int(1e9)
    wf = [[inf] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            wf[i][j] = 1 if S[i][j] == '1' else inf
    for k in range(N):
        for i in range(N):
            for j in range(N):
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
    
    ma = 0
    for i in range(N):
        for j in range(N):
            ma = max(ma, wf[i][j])

    print(ma + 1)

if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin
import sys
#import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = [""] * N
    for i in range(N): S[i] = rs()

    bw = [-1] * N
    q = collections.deque()
    bw[0] = 0
    q.append(0)
    while(len(q) > 0):
        now = q.popleft()
        for nxt in range(N):
            if S[now][nxt] == '0': continue
            if bw[nxt] == -1:
                bw[nxt] = bw[now] ^ 1
                q.append(nxt)
            elif bw[nxt] == bw[now]:
                print(-1)
                sys.exit(0)
    
    inf = int(1e9)
    wf = [[inf] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            wf[i][j] = 1 if S[i][j] == '1' else inf
            if i == j: wf[i][j] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
    
    ma = 0
    for i in range(N):
        for j in range(N):
            ma = max(ma, wf[i][j])

    print(ma + 1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
A = int(input())
S = input()

if A >= 3200:
    print(S)
else:
    print("red")


Fixed submission:
import numpy

A = int(input())
S = input()

if A >= 3200:
    print(S)
else:
    print("red")

Buggy python submission (verdict: Runtime Error):
import numpy

A = int(input())
S = input()

if A >= 3200:
    print(S)
else:
    print("red")

Fixed submission:
import numpy

A = int(input())
S = input()

if A >= 3200:
    print(S)
else:
    print("red")
Buggy python submission (verdict: Runtime Error):
i = list(map(int, input().split()))
print(max([i[0]+i[1], i[0]-i[1], i[0] * i[1]]))

Fixed submission:
i = list(map(int, input().split()))
print(max([i[0]+i[1], i[0]-i[1], i[0] * i[1]]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
m = 1000000007
d = [[-1 for i in range(100000)] for j in range(2)]
v = [[] for j in range(100000)]

def f(x, c, p):
    if d[c][x] != -1: return d[c][x]
    d[c][x] = 1
    for i in v[x]:
        if i != p:
            t = f(i, 0, x)
            if c == 0: t += f(i, 1, x)
            t %= m
            d[c][x] = (d[c][x]*t)%m
    return d[c][x]

for i in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    v[x].append(y)
    v[y].append(x)
ans = (f(0, 0, -1) + f(0, 1, -1))%m
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10000000)
n = int(input())
m = 1000000007
d = [[-1 for i in range(100000)] for j in range(2)]
v = [[] for j in range(100000)]

def f(x, c, p):
    if d[c][x] != -1: return d[c][x]
    d[c][x] = 1
    for i in v[x]:
        if i != p:
            t = f(i, 0, x)
            if c == 0: t += f(i, 1, x)
            t %= m
            d[c][x] = (d[c][x]*t)%m
    return d[c][x]

for i in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    v[x].append(y)
    v[y].append(x)
ans = (f(0, 0, -1) + f(0, 1, -1))%m
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]

t = [[] for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(len(t)-1, -1, -1):
        idx = bisect_left(t[j], A[i])
        if idx != len(t[j]):
            if abs(t[j][idx] - A[i]) <= K:
                t[j+1].append(A[i])
                ans = max(ans, j+2)
                break
        elif idx > 0:
            if abs(t[j][idx-1] -A[i]) <= K:
                t[j+1].append(A[i])
                ans = max(ans, j+2)
                break
    else:
        t[0].append(A[i])
        ans = max(ans, 1)

print(ans)

Fixed submission:
from bisect import bisect_left

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]

t = [[] for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(ans-1, -1, -1):
        idx = bisect_left(t[j], A[i])
        if idx != len(t[j]):
            if abs(t[j][idx] - A[i]) <= K:
                t[j + 1].insert(bisect_left(t[j + 1], A[i]), A[i])
                ans = max(ans, j+2)
                break
        if idx > 0:
            if abs(t[j][idx-1] - A[i]) <= K:
                t[j + 1].insert(bisect_left(t[j + 1], A[i]), A[i])
                ans = max(ans, j+2)
                break
    else:
        t[0].insert(bisect_left(t[0], A[i]), A[i])
        ans = max(ans, 1)

print(ans)