Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,mv=map(int,input().split())

for i in range(31):
    for j in range(31):
        if i+j==0:continue
        for k in range(31):
            for l in range(31):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= 100*sugar/(water+sugar)
                if e<= pp and ans<pp:
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)


Fixed submission:
a,b,c,d,e,mv=map(int,input().split())
e= e/(e+100)

ans=-1
for i in range(31):
    if 100*i*a> mv: continue
    for j in range(31):
        if i+j==0:continue
        if 100*(i*a+j*b)> mv:continue
        for k in range(2801):
            if 100*(i*a+j*b)+k*c> mv:continue
            for l in range(2801):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= sugar/(water+sugar)
                
                if e>= pp and ans<pp:
                    #print("water",water,"sugar",sugar,pp)
                    ans=pp
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)

Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,mv=map(int,input().split())
ans=0
for i in range(31):
    for j in range(31):
        for k in range(31):
            for l in range(31):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= 100*sugar/(water+sugar)
                if e<= pp and ans<pp:
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)

Fixed submission:
a,b,c,d,e,mv=map(int,input().split())
e= e/(e+100)

ans=-1
for i in range(31):
    if 100*i*a> mv: continue
    for j in range(31):
        if i+j==0:continue
        if 100*(i*a+j*b)> mv:continue
        for k in range(2801):
            if 100*(i*a+j*b)+k*c> mv:continue
            for l in range(2801):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= sugar/(water+sugar)
                
                if e>= pp and ans<pp:
                    #print("water",water,"sugar",sugar,pp)
                    ans=pp
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)
Buggy python submission (verdict: Runtime Error):
q,h,s,d=map(int,input().split())
n=int(input())
n*=4
if q*2<h:
    if h*2<s:
        if q*8<d:
            print(n*q);exit()
        else:
            print(q*(n%8)+d*(n//8));exit()
    elif 2*s<d:
      if q*4<s:
        print(n*q)
      else:
        print(s*(n//4));exit()
    else:
      if q*4<s:
        print(d*(n//8)+q*(n%8))
      else:
        print(d*(n//8)+s*((n%8)//4);exit()
else:
    if 2*h<s:
        if 2*s>d:
            print(d*(n//8)+h*((n%8)//2));exit()
        else:
            print(h*(n//2));exit()
    else:
        if 2*s<d:
            print(s*(n//4))
        else:
            print(d*(n//8)+s*((n%8)//4)) 
            


Fixed submission:
q,h,s,d=map(int,input().split())
n=int(input())
n*=4
j=4*(2*q<h)+2*(2*h<s)+(4*q<s)
if j%4==0:
  if 2*s<d:
    print(s*(n//4))
  else:
    print(d*(n//8)+s*((n%8)//4))
  
if j==2 or j==3:
  if 4*h<d:
    print(h*(n//2))
  else:
    print(d*(n//8)+h*((n%8)//2))

if j==5 or j==7:
  if q*8<d:
    print(q*n)
  else:
    print(d*(n//8)+q*(n%8))
Buggy python submission (verdict: Runtime Error):
A=input()
B=list(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)
for i in range(26):
  if not B[i]  in A:
    print(B[i])
    exit()
print("None")


Fixed submission:
A=input()
B=list("abcdefghijklmnopqrstuvwxyz")
for i in range(26):
  if not B[i]  in A:
    print(B[i])
    exit()
print("None")

Buggy python submission (verdict: Runtime Error):
A=input()
B=list(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)
for i in range(26):
  if B[i] not in A:
    print(B[i])
    exit()
print("None")

Fixed submission:
A=input()
B=list("abcdefghijklmnopqrstuvwxyz")
for i in range(26):
  if not B[i]  in A:
    print(B[i])
    exit()
print("None")
Buggy python submission (verdict: Time Limit Exceeded):
_=input()
A=list(map(int,input().split()))
B=list(set(A))
ans=-1
B=sorted(B)[::-1]
for i in B:
  if A.count(i) >=4:
    if ans==-1 : 
      print(i*i)
      exit()
    else:
      print(ans*i)
      exit()
  else:
    if A.count(i) >= 2:
      if ans==-1:
        ans=i
      else:
        print(ans*i)
        exit()
print(0)


Fixed submission:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A=Counter(A)

S=[]
for i,j in A.items():
  if j>=2:
    S.append(i)
S=list(set(S))
S.sort()
if len(S)>=2:
  ans=S[-1]*S[-2]
else:
  print(0)
  exit()

Q=[]

for i,j in A.items():
  if j>=4:
    Q.append(i)
if Q==[]:
  print(ans)
  exit()
print(max(ans, (max(Q))**2))

Buggy python submission (verdict: Runtime Error):
_=input()
A=list(map(int,input().split()))
B=list(set(A))
ans=-1
B=sorted(B)[::-1]
for i in B:
  if A.count(i) >=4:
    print(i**2)
  else:
    A.count(i) >= 2:
      if ans==-1:
        ans=i
      else:
        print(ans*i)
        exit()
print(0)

Fixed submission:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A=Counter(A)

S=[]
for i,j in A.items():
  if j>=2:
    S.append(i)
S=list(set(S))
S.sort()
if len(S)>=2:
  ans=S[-1]*S[-2]
else:
  print(0)
  exit()

Q=[]

for i,j in A.items():
  if j>=4:
    Q.append(i)
if Q==[]:
  print(ans)
  exit()
print(max(ans, (max(Q))**2))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A=Counter(A)
S=[]
for i,j in A.items():
  if j>=2:
    S.append(i)
S=list(set(S))
S.sort()
if len(S)>=2:
  ans=S[-1]*S[-2]
else:
  print(0)
  exit()

Q=[]
for i,j in A.items():
  if j>=4:
    Q.append(i)
print(max(ans, (max(Q))**2))


Fixed submission:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A=Counter(A)

S=[]
for i,j in A.items():
  if j>=2:
    S.append(i)
S=list(set(S))
S.sort()
if len(S)>=2:
  ans=S[-1]*S[-2]
else:
  print(0)
  exit()

Q=[]

for i,j in A.items():
  if j>=4:
    Q.append(i)
if Q==[]:
  print(ans)
  exit()
print(max(ans, (max(Q))**2))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
M=[]
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    M.append([a,b])
yes="POSSIBLE";no="IMPOSSIBLE"

for i in M[0]:
    if n-1 in M[i]:
        print(yes);exit()
print(no)



Fixed submission:
n,m=map(int,input().split())
M=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    M[a].append(b)
    M[b].append(a)
yes="POSSIBLE";no="IMPOSSIBLE"

for i in M[0]:
    if n-1 in M[i]:
        print(yes);exit()
print(no)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from collections import defaultdict
#すべてのkeyが用意されてる defaultdict(int)で初期化
from collections import OrderedDict
#順序を保ったdict
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import Decimal #floatの高精度ver, 渡すのはstr型で
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
k=int(input())
print(50)
if k==0:
    print(" ".join(["0"]*50));exit()
    
kijun=int((k-0.1)//50)+1
A=[50+kijun-1]*50
nokori=kijun*50-k
if nokori:
    print(" ".join([f"{i+1}"]*(50-nokori)+["0"]*nokori))
    exit()
print(*A)

Fixed submission:
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from collections import defaultdict
#すべてのkeyが用意されてる defaultdict(int)で初期化
from collections import OrderedDict
#順序を保ったdict
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import Decimal #floatの高精度ver, 渡すのはstr型で
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
k=int(input())
print(50);n=50
if k==0:
    print(" ".join(["0"]*50));exit()
    
a=k//n
b=k%n
A=[a+i for i in range(50)]
for  i in range(b):
    A=[A[j]-1 if i!=j else A[j]+n for j in range(50)]
print(*A)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
  
a=0
ans=1
for i in range(100100):
  if A[a]==1:
    print(ans)
    exit()
  ans+=1
  a=A[a]
print(-1)

Fixed submission:
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
A=[0]+A
a=1
ans=1
for i in range(100100):
  if A[a]==2:
    print(ans)
    exit()
  ans+=1
  
  a=A[a]
print(-1)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
def C(n, r ,mod=10**9+7):
    if n-r<r: r=n-r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) %mod

    return result % mod
print(C(a+1,b))

Fixed submission:
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

a,b=map(int,input().split())
if abs(a-b)>=2:
    print(0)
    exit()
mod=10**9+7
re=2 if a==b else 1
def kaijou(n):
    if n==1:return 1
    else:
        return (kaijou(n-1)*n)%mod


print(kaijou(a)*kaijou(b)*re%mod)
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(len(s)-1):
  for j in range(i+1,len(s)+1):
    if s[i]==s[j]:
      print("no")
      exit()
print("yes")


Fixed submission:
s=input()
for i in range(len(s)-1):
  for j in range(i+1,len(s)):
    if s[i]==s[j]:
      print("no")
      exit()
print("yes")

Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(len(s)-1):
  for j in range(i+1,len(s)+1):
    if A[i]==A[j]:
      print("no")
      exit()
print("yes")

Fixed submission:
s=input()
for i in range(len(s)-1):
  for j in range(i+1,len(s)):
    if s[i]==s[j]:
      print("no")
      exit()
print("yes")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c=map(int,input().split())
A=[a,b,c]
ans=0
if a%2==1 or b%2==1 or c%2==1:
  print(0)
  exit()
while a%2==0 and b%2==0 and c%2==0:
  a=(b+c)/2
  b=(sum(A)-A[1])/2
  c=(sum(A)-A[2])/2
  if [a,b,c]==A:
    print(-1)
    exit()
  ans+=1

print(ans)


Fixed submission:
a,b,c=map(int,input().split())
for i in range(500000):
    if a%2==1 or b%2==1 or c%2==1:
        print(i);exit()
    
    else:
      p=(b+c)//2 ;q=(a+c)//2 ; r=(a+b)//2
      a=p ; b=q;c=r
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()

d=""
for i in range(len(a)):
  d+=(a[i])
  d+=(b[i])
print(d)


Fixed submission:
a=input()
b=input()

d=""
for i in range(len(b)):
  d+=(a[i])
  d+=(b[i])

if len(a)!=len(b):
  d+=a[-1]
  
print(d)

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c=a+b
d=""
for i in len(c)//2:
  d+=(c[i])
  d+=(c[len(c)//2+i])
print(d)

Fixed submission:
a=input()
b=input()

d=""
for i in range(len(b)):
  d+=(a[i])
  d+=(b[i])

if len(a)!=len(b):
  d+=a[-1]
  
print(d)
Buggy python submission (verdict: Time Limit Exceeded):
n,ma,mb=map(int,input().split())
zen=[]
kou=[]
A=[ list(map(int,input().split())) for i in range(n//2)];a=len(A)
B=[ list(map(int,input().split())) for i in range(n-n//2)];b=len(B)
for bit in range(1<<a):
    now=[0,0,0]
    for i in range(a):
        if (bit>>i)&1:
            now[0]+=A[i][0]
            now[1]+=A[i][1]
            now[2]+=A[i][2]
    zen.append(now)
for bit in range(1<<b):
    now=[0,0,0]
    for i in range(b):
        if (bit>>i)&1:
            now[0]+=B[i][0]
            now[1]+=B[i][1]
            now[2]+=B[i][2]
    kou.append(now)

ans=10**10
for li in zen:
    for lj in kou:
        if li[0]+lj[0]==0 :continue
        if (li[0]+lj[0])*mb==ma*(li[1]+lj[1]):
            ans=min(ans,li[2]+lj[2])
print(ans if ans!=10**10 else -1)

Fixed submission:
n,ma,mb=map(int,input().split())
zen=[[10**10]*401 for i in range(401)]
kou=[[10**10]*401 for j in range(401)]
A=[ list(map(int,input().split())) for i in range(n//2)];a=len(A)
B=[ list(map(int,input().split())) for i in range(n-n//2)];b=len(B)
for bit in range(1<<a):
    now=[0,0,0]
    for i in range(a):
        if (bit>>i)&1:
            now[0]+=A[i][0]
            now[1]+=A[i][1]
            now[2]+=A[i][2]
    zen[now[0]][now[1]]=min(zen[now[0]][now[1]],now[2])
for bit in range(1<<b):
    now=[0,0,0]
    for i in range(b):
        if (bit>>i)&1:
            now[0]+=B[i][0]
            now[1]+=B[i][1]
            now[2]+=B[i][2]
    kou[now[0]][now[1]]=min(kou[now[0]][now[1]],now[2])


ans=10**10
for base in range(1,401):
    na=base*ma ; nb=base*mb 
    if max(na,nb)>400: break
    for i in range(na+1):
        for j in range(nb+1):
            ans=min(ans,zen[i][j]+ kou[na-i][nb-j])


print(ans if ans<10**6 else -1)
Buggy python submission (verdict: Runtime Error):
A=input()
n=A.index("a")
m=A[::-1].index("z")
print(len(A)-n-m)

Fixed submission:
A=input()
n=A.index("A")
m=A[::-1].index("Z")
print(len(A)-n-m)

Buggy python submission (verdict: Runtime Error):
A=input()
print(A.index("z")-A.index("a"))

Fixed submission:
A=input()
n=A.index("A")
m=A[::-1].index("Z")
print(len(A)-n-m)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%11>6:
  print(n//11*2+2)
elif n%11>0
  print(n//11*2+1)
else:
  print(n//11*2)

Fixed submission:
n=int(input())
if n%11>6:
  print(n//11*2+2)
elif n%11>0:
  print(n//11*2+1)
else:
  print(n//11*2)
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
ans=0
if s<=k:
  print((s+1)*(s+2)//2)
  exit()
for i in range(k+1):
  for j in range(i,k+1):
    for l in range(j,k+1):
      if i+j+l==s:
        if i==j and j==l:
          ans+=1
        elif i==j or j==l or l==i:
          ans+=3
        else:
          ans+=6
print(ans)


Fixed submission:
k,s=map(int,input().split())
ans=0
if s<=k:
  print((s+1)*(s+2)//2)
  exit()
for i in range(k+1):
  for j in range(k+1):
    if 0<=s-i-j<=k:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
ans=0
for i in range(k+1):
  for j in range(i,k+1):
    for l in range(j,k+1):
      if i+j+l==s:
        if i==j and j==l:
          ans+=1
        elif i==j or j==l or l==i:
          ans+=3
        else:
          ans+=6
print(ans)


Fixed submission:
k,s=map(int,input().split())
ans=0
if s<=k:
  print((s+1)*(s+2)//2)
  exit()
for i in range(k+1):
  for j in range(k+1):
    if 0<=s-i-j<=k:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
ans=0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i+j+l==s:
        ans+=1
print(ans)

Fixed submission:
k,s=map(int,input().split())
ans=0
if s<=k:
  print((s+1)*(s+2)//2)
  exit()
for i in range(k+1):
  for j in range(k+1):
    if 0<=s-i-j<=k:
      ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
a=input()
a=a.replace("erase","")
a=a.replace("dream","")
a=a.replace("dreamer","")
a=a.replace("eraser","")
if a="":
  print("YES")
else:
  print("NO")

Fixed submission:
s = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if s:
  print("NO")
else:
  print("YES")
Buggy python submission (verdict: Runtime Error):
w,h,n=map(int,input().split())
A=[[0 for i in range(w)] for j in range(h)]
for i in range(n):
  a,b,c=map(int,input().split())
  if c==1:
    for i in range(h):
      for j in range(a):
        A[i][j]=1
  elif c==2:
    for i in range(h):
      for j in range(w-a):
        A[i][j+a]=1
  elif c==3:
    for i in range(b):
      A[i]=[1 for i in range(w)]
  else:
    for i in range(h-b):
      A[h-i]=[1 for i in range(w)]
ans=0
for i in range(h):
  ans+=A[i].count(0)
print(ans)

Fixed submission:
w,h,n=map(int,input().split())
A=[[0 for i in range(w)] for j in range(h)]
for i in range(n):
  a,b,c=map(int,input().split())
  if c==1:
    for i in range(h):
      for j in range(a):
        A[i][j]=1
  elif c==2:
    for i in range(h):
      for j in range(w-a):
        A[i][j+a]=1
  elif c==3:
    for i in range(b):
      A[i]=[1 for i in range(w)]
  else:
    for i in range(h-b):
      A[h-i-1]=[1 for i in range(w)]
ans=0
for i in range(h):
  ans+=A[i].count(0)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=input()
B=input()
s=0

ans=2*n
for i in range(n)
  if A[-i-1:]!=B[:i+1]:
    s=1
    print(ans)
    exit()
  else:
    ans-=1
print(ans)

Fixed submission:
n=int(input())
A=input()
B=input()
s=0

ans=n
D=[i for i in range(n)][::-1]
for i in D:
  if A[-i-1:]==B[:i+1]:
    
    print(ans)
    exit()
  else:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
A=list(input())
for i in A:
  if i=="C":
    if "I" in A[i+1:]:
      print("Yes")
      exit()
print("No")

Fixed submission:
A=list(input())
for i in range(len(A)):
  if A[i]=="C":
    if "F" in A[i+1:]:
      print("Yes")
      exit()
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s=input() ; n=len(s) ;a=""
for i in range(10000):
    s=s.replace("ST","")
    if a==s:
      print(len(s));exit()
    a=s
print(len(s))


Fixed submission:
s=input() ; n=len(s)
ss=n//2; tt=n//2
ans=0
for i in range(n):
    if s[i]=="S":
        ans=max(ans, ss-tt)
        ss-=1
    else:
        tt-=1
print(ans*2)

Buggy python submission (verdict: Runtime Error):
s=input() ; n=len(s)
for i in range(10000):
    s=s.replace("ST","")
    if a==s:
      print(len(s));exit()
    a=s
print(len(s))


Fixed submission:
s=input() ; n=len(s)
ss=n//2; tt=n//2
ans=0
for i in range(n):
    if s[i]=="S":
        ans=max(ans, ss-tt)
        ss-=1
    else:
        tt-=1
print(ans*2)
Buggy python submission (verdict: Runtime Error):
s=input()
s=list(s)
for i in s:
  if s.count(s[i])%2==1:
    print("No")
    exit()
print("Yes")

Fixed submission:
s=input()
s=list(s)
for i in s:
  if s.count(i)%2==1:
    print("No")
    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
s=input()
ans=""
for i in s:
  if i=="0" or i=="1":
    ans+=i
  else:
    if len(ans)!=0:
      del ans[-1]
print(ans)


Fixed submission:
s=input()
ans=""
for i in s:
  if i=="0" or i=="1":
    ans+=i
  else:
    if len(ans)!=0:
      ans=ans[:-1]

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input());print(sum(sorted(list(map(int,input().split())))[::2]))
print("RE WA?"

Fixed submission:
n=int(input())
A=sorted(list(map(int,input().split())))
print(sum(A[::2]))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
edges = [[] for i in range(n)]
visit = [False for i in range(n)]
def dfs(v):
    visit[v] = True
    for i in edges[v]:
        if not visit[i]:
            dfs(i)
for i in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
cnt = 0
for i in range(n):
    if not visit[i]:
        dfs(i)
        cnt += 1
print(cnt - 1)

Fixed submission:
import sys
sys.setrecursionlimit(2 * (10 ** 6))
n, m = map(int, input().split())
edges = [[] for i in range(n)]
visit = [False for i in range(n)]
def dfs(v):
    visit[v] = True
    for i in edges[v]:
        if not visit[i]:
            dfs(i)
for i in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
cnt = 0
for i in range(n):
    if not visit[i]:
        dfs(i)
        cnt += 1
print(cnt - 1)
Buggy python submission (verdict: Runtime Error):
class SegmentTree:
    def __init__(self, lis, ele, op):
        self.len = len(lis)
        self.n = 1 << ((self.len - 1).bit_length())
        self.op = op
        self.ele = ele
        self.tree = self._build(lis)
    def _build(self, lis):
        res_tree = [self.ele] * (self.n - 1) + lis + [self.ele] * (self.n - self.len)
        for i in range(self.n - 2, -1, -1):
            res_tree[i] = self.op(res_tree[i * 2 + 1], res_tree[i * 2 + 2])
        return res_tree
    def __get__(self, i):
        return self.tree[self.n + i - 1]
    def update(self, i, x):
        i += self.n - 1
        self.tree[i] = x
        while i > 0:
            i -= 1
            i >>= 1
            self.tree[i] = self.op(self.tree[i * 2 + 1], self.tree[i * 2 + 2])
    def query(self, l, r):
        l +=  self.n - 1
        r += self.n - 1
        L = self.ele
        R = self.ele
        while l < r:
            if l & 1 == 0:
                L = self.op(L, self.tree[l])
                l += 1
            if r & 1 == 0:
                r -= 1
                R = self.op(R, self.tree[r])
            l -= 1
            l >>= 1
            r >>= 1
        return self.op(L, R)
n, k = map(int, input().split())
ST = SegmentTree([0] * 200000, 0, max)
for i in range(n):
    a = int(input())
    res = ST.query(max(0, a - k), min(200000, a + k + 1))
    ST.update(a, res + 1)
print(ST.tree[1])

Fixed submission:
class SegmentTree:
    def __init__(self, lis, ele, op):
        self.len = len(lis)
        self.n = 1 << ((self.len - 1).bit_length())
        self.op = op
        self.ele = ele
        self.tree = self._build(lis)
    def _build(self, lis):
        res_tree = [self.ele] * (self.n - 1) + lis + [self.ele] * (self.n - self.len)
        for i in range(self.n - 2, -1, -1):
            res_tree[i] = self.op(res_tree[i * 2 + 1], res_tree[i * 2 + 2])
        return res_tree
    def __get__(self, i):
        return self.tree[self.n + i - 1]
    def update(self, i, x):
        i += self.n - 1
        self.tree[i] = x
        while i > 0:
            i -= 1
            i >>= 1
            self.tree[i] = self.op(self.tree[i * 2 + 1], self.tree[i * 2 + 2])
    def query(self, l, r):
        l +=  self.n - 1
        r += self.n - 1
        L = self.ele
        R = self.ele
        while l < r:
            if l & 1 == 0:
                L = self.op(L, self.tree[l])
                l += 1
            if r & 1 == 0:
                r -= 1
                R = self.op(R, self.tree[r])
            l -= 1
            l >>= 1
            r >>= 1
        return self.op(L, R)
n, k = map(int, input().split())
ST = SegmentTree([0] * 600000, 0, max)
for i in range(n):
    a = int(input())
    res = ST.query(max(0, a - k), min(600000, a + k + 1))
    ST.update(a, res + 1)
print(ST.tree[1])