Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a = list(input())
b = list(input())
c = len(a)
d = len(b)

flag = False
for i in range(c-d+1):
    li = [0]*c
    for k in range(c):
        li[k] = a[k]
    for j in range(d):
        if b[j] == a[i+j] or a[i+j] == "?":
            flag = True
            li[i+j] = b[j]
        elif b[j] != a[i+j]:
            flag = False
            break
    else:
        continue
for i in range(c):
    if li[i] == "?":
        li[i] = "a"

if flag:
    print("".join(li))
else:
    print("UNRESTORABLE")

Fixed submission:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()
ans = []
   
for i in range(c-d+1):
    #print(a[i:i+d])
    flag = False
    for j in range(d):
        if a[i:i+d][j] == b[j] or a[i:i+d][j] == "?":
            flag = True
        else:
            flag = False
            break
    li = [] 
    if flag:
        #print(a[i:i+d])
        li = a[:i] + b + a[i+d:]
        for k in range(len(li)):
            if li[k] == "?":
                li[k] = "a"
        ans.append("".join(li))
if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from copy import deepcopy
n,m = map(int,input().split())
inf = float("inf")
L = [[inf for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    L[a-1][b-1] = 1
    L[b-1][a-1] = 1
#print(L)
cnt = 0
for i in range(n):
    for j in range(n):
        LL = deepcopy(L)
        LL[i][j] = 0
        LL[j][i] = 0
        LL = floyd_warshall(LL)
        #print(LL)
        for k in LL:
            if inf in k:
                cnt +=1
                break
print(cnt//2) 

Fixed submission:
n,m = map(int,input().split())
d = []
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    d.append((a,b))
#print(d)
pa = None

def root(a):
    if pa[a] == a:
        return a
    else:
        pa[a] = root(pa[a])
        return pa[a]
def is_same(a,b):
    return root(a) == root(b)
def unite(a,b):
    aa = root(a)
    bb = root(b)
    if aa == bb:
        return
    pa[aa] = bb

ans = 0
for i in range(m):
    pa = [x for x in range(n)]
    for j,v in enumerate(d):
        #(i,j,v)
        if i == j:continue
        a,b = v
        unite(a,b)
    a,b = d[i]
    if not is_same(a,b):
        ans +=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from copy import deepcopy
n,m = map(int,input().split())
inf = float("inf")
L = [[inf for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    L[a-1][b-1] = 1
    L[b-1][a-1] = 1
#print(L)
cnt = 0
for i in range(n):
    for j in range(n):
        LL = deepcopy(L)
        LL[i][j] = 0
        LL[j][i] = 0
        LL = floyd_warshall(LL)
        #print(LL)
        for k in LL:
            if inf in k:
                cnt +=1
                break
print(cnt//2) 

Fixed submission:
n,m = map(int,input().split())
d = []
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    d.append((a,b))
#print(d)
pa = None

def root(a):
    if pa[a] == a:
        return a
    else:
        pa[a] = root(pa[a])
        return pa[a]
def is_same(a,b):
    return root(a) == root(b)
def unite(a,b):
    aa = root(a)
    bb = root(b)
    if aa == bb:
        return
    pa[aa] = bb

ans = 0
for i in range(m):
    pa = [x for x in range(n)]
    for j,v in enumerate(d):
        #(i,j,v)
        if i == j:continue
        a,b = v
        unite(a,b)
    a,b = d[i]
    if not is_same(a,b):
        ans +=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L1 = list(map(int,input().split()))
m = int(input())
L2 = list(map(int,input().split()))
flag = False
cnt = 0
for i in range(m):
    if L2.count(L2[i]) <= L1.count(L2[i]):
        flag = True
        cnt +=1
    else:
        flag = False
if flag and cnt == len(L2):
    print("YES")
else:
    print("NO")

Fixed submission:
from collections import Counter
n = int(input())
L1 = list(map(int,input().split()))
m = int(input())
L2 = list(map(int,input().split()))
li1 = Counter(L1)
li2 = Counter(L2)

flag = False
for i in range(m):
    if li1[L2[i]] >= li2[L2[i]]:
        flag = True
    else:
        flag = False
        break
if flag:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L1 = list(map(int,input().split()))
m = int(input())
L2 = list(map(int,input().split()))
for i in range(m):
    if L2[i] in L1:
        L1.remove(L2[i])
    elif L2[i] not in L1:
        print("NO")
        exit()
if len(L1) >= 0:
    print("YES")

Fixed submission:
from collections import Counter
n = int(input())
L1 = list(map(int,input().split()))
m = int(input())
L2 = list(map(int,input().split()))
li1 = Counter(L1)
li2 = Counter(L2)

flag = False
for i in range(m):
    if li1[L2[i]] >= li2[L2[i]]:
        flag = True
    else:
        flag = False
        break
if flag:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

for i in range(1,3501):
    for j in range(1,3501):
        if (4*i*j-n*i-n*j) != 0:
            w = i*j*n/(4*i*j-n*i-n*j)
            if w%1 == 0 and w > 0:
                print(i,j,int(w))
                exit()

Fixed submission:
n = int(input())

for i in range(1,3501):
    for j in range(1,3501):
        if (4*i*j-n*i-n*j) != 0:
            w = i*j*n/(4*i*j-n*i-n*j)
            if w%1 == 0 and w > 0:
                print(i,j,int(w))
                exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
li=[]
for i in range(n):
  a=int(input())
  if a not in li:
    li.append(a)
  elif a in li:
    li.remove(a)
print(len(li))
    
    
  

Fixed submission:
n = int(input())
li = []
for i in range(n):
    li.append(int(input()))
import collections
a = collections.Counter(li)
a = a.most_common()
num = 0
for i in range(len(a)):
    if a[i][1]%2==1:
        num += 1
print(num)
Buggy python submission (verdict: Runtime Error):
s = list(input())
al = "abcdefghijklmnopqrstuvwxyz"
al = list(al)
li = []
for i in range(len(al)):
    if (al[i] not in s):
        li.append(al[i])
        
li.sort()
print(li[0])

Fixed submission:
s = list(set(list(input())))
a = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
li = []
for i in range(len(a)):
  if a[i] not in s:
    li.append(a[i])
if len(li) == 0:
    print("None")
else:
    print(min(li))

Buggy python submission (verdict: Runtime Error):
s = list(set(list(input())))
a = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
li = []
for i in range(len(s)):
  if s[i] not in a:
    li.append(s[i])
print(min(li))


Fixed submission:
s = list(set(list(input())))
a = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
li = []
for i in range(len(a)):
  if a[i] not in s:
    li.append(a[i])
if len(li) == 0:
    print("None")
else:
    print(min(li))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int,input().split()))
li1 = []
for i in range(len(li)):
    if li.count(li[i])>=2:
        li1.append(li[i])
li1 = sorted(list(set(li1)))[::-1]
if len(li1)>=2:
    print(li1[0]*li1[1])
else:
    print(0)

Fixed submission:
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse = True)

a,b = 0,0
i = 0
while i<=len(li)-2:
    if li[i] == li[i+1] and a == 0:
        a = li[i]
        i += 2
    elif li[i] == li[i+1]  and a != 0:
        b = li[i]
        break
    elif li[i] != li[i+1]:
        i += 1
print(a*b)
Buggy python submission (verdict: Runtime Error):
n = int(input())

li = []
for i in range(n):
  li.append(int(input()))

def gcd1(a,b):
  while b:
    a,b = b,a%b
  return a

def lcm1(a,b):
  return a*b//gcd1(a,b)
num = li[0]
num = lcm1(li[0],li[1])
for i in range(2,len(li)):
    num = lcm1(num,li[i])
print(num)
    

Fixed submission:
n = int(input())

def gcd1(a,b):
  while b:
    a,b = b,a%b
  return a

def lcm1(a,b):
  return a*b//gcd1(a,b)
num = 1
for i in range(n):
    num = lcm1(num,int(input()))
print(num)

Buggy python submission (verdict: Runtime Error):
n = int(input())

li = []
for i in range(n):
  li.append(int(input()))

def gcd1(a,b):
  while b:
    a,b = b,a%b
  return a

def lcm1(a,b):
  return a*b//gcd1(a,b)
num = 0
num = lcm1(li[0],li[1])
for i in range(2,len(li)):
    num = lcm1(num,li[i])
print(num)

Fixed submission:
n = int(input())

def gcd1(a,b):
  while b:
    a,b = b,a%b
  return a

def lcm1(a,b):
  return a*b//gcd1(a,b)
num = 1
for i in range(n):
    num = lcm1(num,int(input()))
print(num)
Buggy python submission (verdict: Runtime Error):
n = (int(input()))
li = []
for i in range(1,n+1):
    if i%2 == 0:
        li.append(i)

li = [bin(x) for x in li]
li = li[::-1]
for i in range(len(li)):
    if li[i].count(str(1)) == 1:
        a=((li[i].count(str(0)) -1))
        break
print(2**a)

Fixed submission:
n = (int(input()))
if n ==1:
    print(1)
li = []
for i in range(1,n+1):
    if i%2 == 0:
        li.append(i)

li = [bin(x) for x in li]
li = li[::-1]
for i in range(len(li)):
    
    if li[i].count(str(1)) == 1:
        a=((li[i].count(str(0)) -1))
        print(2**a)
        break
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import floyd_warshall as wf
n, m = map(int, input().split())
L = [[0]*n for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    L[a-1][b-1] = 1
    L[b-1][a-1] = 1

L = wf(L)

if L[0][n-1] == 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())
L = []
for i in range(m):
    a,b = map(int, input().split())
    L.append((a,b))

st,go = [],[]
for i in range(m):
    if 1 in L[i]:
        st.append(L[i][1])
    if n in L[i]:
        go.append(L[i][0])

if set(st)&set(go):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
li = list(map(int,input().split()))
li.sort(reverse = True)
print(sum(li[:k])

Fixed submission:
n,k = map(int,input().split())
li = list(map(int,input().split()))
li.sort(reverse = True)
print(sum(li[:k]))
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
L = list(map(int,input().split()))
Le = [x for x in L if x%2 == 0]
Lo = [x for x in L if x%2 == 1]
#print(Le,Lo)
def nCr(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
    
if b == 0:
    ev = 0
    od = 1
    while ev <= len(Le)//2:
        ev += nCr(len(Le),ev)
        ev += 2
    while od <= len(Lo)+1:
        od += nCr(len(Lo),od)
        od += 2
elif b == 1:
    ev = 0
    od = 0
    while ev <= len(Le)//2:
        ev += nCr(len(Le),ev)
        ev += 2
    while od <= len(Lo)+1:
        od += nCr(len(Lo),od)
        od += 2
print(ev*od)

Fixed submission:
n,p = map(int,input().split())
L = list(map(int,input().split()))
Le = [x for x in L if x%2 == 0]
Lo = [x for x in L if x%2 == 1]

if p == 0:
    if len(Lo) == 0:
        print(2**n)
    else:
        print(2**(n-1))
if p == 1:
    if len(Lo) == 0:
        print(0)
    else:
        print(2**(n-1))
Buggy python submission (verdict: Runtime Error):
sl = list(input())
s2 = set(s1)
if len(s1) == len(s2):
  print("yes")
elif len(s1) != len(s2):
  print("no")


Fixed submission:
s1 = list(input())
s2 = set(s1)
if len(s1) == len(s2):
  print("yes")
elif len(s1) != len(s2):
  print("no")
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

if any((a%2==1,b%2!==1,c%2==1)):
    print(0)
    exit()
    
cnt = 0
while cnt <= 100:
    a,b,c = (b+c)/2, (a+c)/2,(a+b)/2
    cnt += 1
    if any((a%1!=0,b%1!=0,c%1!=0)):
        print(cnt-1)
        exit()
print(-1)

Fixed submission:
a,b,c = map(int,input().split())

if any((a%2==1,b%2==1,c%2==1)):
    print(0)
    exit()
    
cnt = 0
while cnt <= 100:
    a,b,c = (b+c)/2, (a+c)/2,(a+b)/2
    cnt += 1
    if any((a%1!=0,b%1!=0,c%1!=0)):
        print(cnt-1)
        exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s1 = list(input())
s2 = list(input())
s3 = list(input())

ans = ""
a = set(s1)&set(s2)&set(s3)
s1 = [x for x in s1 if x in a]
s2 = [x for x in s2 if x in a]
s3 =[x for x in s2 if x in a]
s1.sort()
s2.sort()
s3.sort()

for i in range(min(len(s1),len(s2),len(s3))):
    if s1[:i+1] == s2[:i+1] == s3[:i+1]:
        ans = "".join(s1[:i+1])
    else:
        break
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
L = []
for i in range(n):
    L.append(sorted(list(input())))
set1 = set(L[0])
for i in range(2,n):
    set1 = set1&set(L[i])
li = []
al = "abcdefghijklmnopqrstuvwxyz"
for s in al:
    if s in set1:
        min1 = 10 **10
        for i in range(n):
            a = Counter(L[i])
            min1 = min(min1,a[s])
        li.append((s,min1))
ans = ""
for i in range(len(li)):
    ans += li[i][0]*li[i][1]
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s1 = list(input())
s2 = list(input())
s3 = list(input())

ans = ""
a = set(s1)&set(s2)&set(s3)
s1 = [x for x in s1 if x in a]
s2 = [x for x in s2 if x in a]
s3 =[x for x in s2 if x in a]
s1.sort()
s2.sort()
s3.sort()
print(s1,s2,s3)
for i in range(min(len(s1),len(s2),len(s3))):
    if s1[:i+1] == s2[:i+1] == s3[:i+1]:
        ans = "".join(s1[:i+1])
    else:
        break
print(ans)


Fixed submission:
from collections import Counter
n = int(input())
L = []
for i in range(n):
    L.append(sorted(list(input())))
set1 = set(L[0])
for i in range(2,n):
    set1 = set1&set(L[i])
li = []
al = "abcdefghijklmnopqrstuvwxyz"
for s in al:
    if s in set1:
        min1 = 10 **10
        for i in range(n):
            a = Counter(L[i])
            min1 = min(min1,a[s])
        li.append((s,min1))
ans = ""
for i in range(len(li)):
    ans += li[i][0]*li[i][1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
d = int(input())
t = 0 
while True:
  if t*(t+1)//2 >=d:
    print(t)
    exit()

Fixed submission:
x = int(input())
i = 0
n = 1
while n <=x:
    n +=i
    i +=1
    
print(i-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
L1,L2 = [],[]
for i in range(n):
    a,b = map(int,input().split())
    L1.append(b)
    L2.append(a)
L1 = L1[::-1]
L2 = L2[::-1]
#print(L1)
#print(L2)
cnt = 0
for i in range(n):
    
    L1[i] += cnt
    #print(L1[i])
    
    if L1[i] >= L2[i]:
        cnt += L1[i]%L2[i]
        
    elif L1[i] < L2[i]:
        c = 2
        while True:
            if L1[i] >= L2[i]:
                cnt += L1[i]%L2[i]
                #print(cnt,i,L1[i])
                break
            else:
                L1[i] *= c
                c +=1
        #cnt += L1[i]%L2[i]
print(cnt)

Fixed submission:
n = int(input())
A,B = [],[]
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
A,B = A[::-1],B[::-1]

num = 0
for i in range(n):
    A[i] +=num
    if A[i]%B[i] !=0:
        num = num + B[i] - A[i]%B[i]
        #print(num,B[i], B[i] - A[i]%B[i])
print(num)
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())

if y<x<0 or 0<y<x:
    print(abs(x-y)+2)
elif (y<x and x=0) or (y=0 and y<x):
    print(abs(x-y)+1)
elif x<=y<=0 or 0<=x<=y:
    print(abs(x-y))
elif x<0<y or y<0<x:
    print(abs(abs(x)-abs(y))+1)

Fixed submission:
x,y = map(int,input().split())

if y<x<0 or 0<y<x:
    print(abs(x-y)+2)
elif (y<x and x==0) or (y==0 and y<x):
    print(abs(x-y)+1)
elif x<=y<=0 or 0<=x<=y:
    print(abs(x-y))
elif x<0<y or y<0<x:
    print(abs(abs(x)-abs(y))+1)

Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())

if y<x<0 or 0<y<x:
    print(abs(x-y)+2)
elif y<x=0 or 0=y<x:
    print(abs(x-y)+1)
elif x<=y<=0 or 0<=x<=y:
    print(abs(x-y))
elif x<0<y or y<0<x:
    print(abs(abs(x)-abs(y))+1)

Fixed submission:
x,y = map(int,input().split())

if y<x<0 or 0<y<x:
    print(abs(x-y)+2)
elif (y<x and x==0) or (y==0 and y<x):
    print(abs(x-y)+1)
elif x<=y<=0 or 0<=x<=y:
    print(abs(x-y))
elif x<0<y or y<0<x:
    print(abs(abs(x)-abs(y))+1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
if n <= 2:
    print(n)
if n == 3:
    print(1)
    print(2)
    exit()

num = 0
for i in range(1,n):
    if i*(i+1)//2 >= n:
        num = i
        break
#print(num)
if num*(num+1)//2== n:
    for i in range(1,num+1):
        print(i)
    exit()
s = []
sum1 = 0
while sum1 <=n:
    sum1 +=num
    s.append(num)
    num -=1

if sum1 > n:
    s[-1] -=sum1-n
if s[-1] == 0:
    s.pop()
    
for i in range(len(s)):
    print(s[i])

Fixed submission:
n = int(input())
num = 0
for k in range(1,n+1):
    #print(k)
    if k*(k+1) >=2*n:
        break
if k*(k+1) == 2*n:
    for i in range(k):
        print(i+1)
else:
    num = k*(k+1)//2-n
    #print(num,k*(k+1)//2)
    for i in range(k):
        if i+1 == num:
            continue
        else:
            print(i+1)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

L = []
for i in range(len(s)):
    L.append((ord("z")-ord(s[i])+1))

ans = ""
i = 0
while i < len(s):
    if k-L[i] >= 0:
        ans +="a"
        k -=L[i]
        i +=1
    else:
        ans +=s[i]
        i +=1

ans = ans[:-1] + chr(ord(ans[-1]) + k)
print(ans)

Fixed submission:
s = input()
k = int(input())

L = []
for i in range(len(s)):
    L.append((ord("z")-ord(s[i])+1))

ans = ""
i = 0
while i < len(s):
    if s[i] == "a":
        ans +="a"
        i +=1
    elif k-L[i] >= 0:
        ans +="a"
        k -=L[i]
        i +=1
    else:
        ans +=s[i]
        i +=1
k = k%26
ans = ans[:-1] + chr(ord(ans[-1]) + k)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = list(map(int,input().split()))
if any([i%2==0 for i in (a,b,c)]):
    print(0)
else:
    ans = min(a*b , c*b , a*c)
print(ans)

Fixed submission:
a,b,c = map(int,input().split())

p = any((a%2 == 0,b%2 == 0,c%2 == 0))
if p:
    print(0)
else:
    print(min(a*b,b*c,c*a))

Buggy python submission (verdict: Runtime Error):
a,b,c = list(map(int,input().split()))
if any([i%2==0 for i in (a,b,c)]):
    print(0)
else:
    ans = min(a*b*(c//2+1) - a*b*(c//2) , c*b*(a//2+1) - c*b*(a//2) , a*c*(b//2+1) - a*c*(b//2))
print(ans)

Fixed submission:
a,b,c = map(int,input().split())

p = any((a%2 == 0,b%2 == 0,c%2 == 0))
if p:
    print(0)
else:
    print(min(a*b,b*c,c*a))

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

p = any((a%2 == 0,b%2 == 0,c%2 == 0))
if p:
    print(0)
else:
    L = []
    for i in range(a//2,a//2+2):
        L.append(i*b*c)
    aa = abs(L[0]-L[1])
    L = []
    for j in range(b//2,b//2+2):
        L.append(j*a*c)
    bb = abs(L[0]-L[1])
    L = []
    for k in range(c//2,c//2+2):
        L.append(k*a*b)
    cc = abs(L[0]-L[1])

print(min(aa,bb,cc))

Fixed submission:
a,b,c = map(int,input().split())

p = any((a%2 == 0,b%2 == 0,c%2 == 0))
if p:
    print(0)
else:
    print(min(a*b,b*c,c*a))
Buggy python submission (verdict: Runtime Error):
n.l = map(int,input().split())
L = [input() for_ in range(n)]
L.sort()
print("".join(L))

Fixed submission:
n,m= map(int,input().split())
li = []
for i in range(n):
    li.append(input())
li.sort()
print("".join(li))
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a=[int(input()) for i in range(n)]

ide_ele = 0

def segfunc(x, y):
    return max(x,y)

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r): #[l, r) 0-index
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

al = [0]*(n+1)
seg = SegTree(al, segfunc, ide_ele)

for num in a:
    l=max(0,num-k)
    r=min(n,num+k+1)
    mx = seg.query(l,r)
    seg.update(num,mx+1)

print(seg.query(0,n))

Fixed submission:
n,k = map(int, input().split())
a=[int(input()) for i in range(n)]

ide_ele = 0

def segfunc(x, y):
    return max(x,y)

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r): #[l, r) 0-index
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

maxa=max(a)
al = [0]*(maxa+1)
seg = SegTree(al, segfunc, ide_ele)

for num in a:
    l=max(0,num-k)
    r=min(maxa,num+k)
    mx = seg.query(l,r+1)
    seg.update(num,mx+1)

print(seg.query(0,maxa+1))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

import collections
ac = collections.Counter(a)
bc = collections.Counter(b)

for i in range(1,n+1):
    if ac[i] + bc[i] > n:
        print("No")
        exit()

dup_lis = []
for i in range(n):
    if a[i] == b[i]:
        dup_lis.append(a[i])

dup_lis = set(dup_lis)

from collections import defaultdict
a_right  = defaultdict(int)
b_left = defaultdict(int)

for i in range(n):
    a_right[a[i]] = i

for i in reversed(range(n)):
    b_left[b[i]] = i

sft=[]
for dup in dup_lis:
    sft.append(a_right[dup] - b_left[dup]+1)

from collections import deque
b=deque(b)
b.rotate(max(sft))
print("Yes")
print(*b)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

import collections
ac = collections.Counter(a)
bc = collections.Counter(b)

for i in range(1,n+1):
    if ac[i] + bc[i] > n:
        print("No")
        exit()

from collections import defaultdict
a_right  = defaultdict(int)
b_left = defaultdict(int)

for i in range(n):
    a_right[a[i]] = i

for i in reversed(range(n)):
    b_left[b[i]] = i

sft=[0]
for dup in set(a) & set(b):
    sft.append(a_right[dup] - b_left[dup]+1)

from collections import deque
b=deque(b)
b.rotate(max(sft))
print("Yes")
print(*b)
Buggy python submission (verdict: Runtime Error):
k=int(input())

now=7
for i in range(k+10):
	if now==0:
		print(i+1)
		exit()
	now*=10
	now+=7
    now%=k
print(-1)
    

Fixed submission:
k=int(input())

now=7%k
for i in range(k+10):
	if now==0:
		print(i+1)
		exit()
	now*=10
	now+=7
	now%=k
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())

now=7
for i in range(k+10):
	if now%k==0:
		print(i+1)
		exit()
	now*=10
	now+=7
print(-1)
    

Fixed submission:
k=int(input())

now=7%k
for i in range(k+10):
	if now==0:
		print(i+1)
		exit()
	now*=10
	now+=7
	now%=k
print(-1)