Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02801 (python)

Fixed submission:
N=input()
L=["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"]
print(L[L.index(N)+1])

Buggy submission (verdict: Runtime Error):
N=input()
L=[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]
print(L[L.index(N)+1])
Problem p02910 (python)

Fixed submission:
import sys
L=list(input())
c=len(L)
for i in range(c):
  if i%2==0:
    if L[i]!="R" and L[i]!="D" and L[i]!="U":
      print("No")
      sys.exit()
  else:
    if L[i]!="L" and L[i]!="D" and L[i]!="U":
      print("No")
      sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
S=list(input())
c=len(R)
for i in range(c):
  if i%2==0:
    if L[i]!="R" and L[i]!="D" and L[i]!="U":
      print("No")
      sys.exit()
  else:
    if L[i]!="L" and L[i]!="D" and L[i]!="U":
      print("No")
      sys.exit()
print("Yes")
Problem p02971 (python)

Fixed submission:
L=list()
N=int(input())
for i in range(N):
  a=int(input())
  L.append(a)
c=max(L)
d=sorted(L)[-2]
for i in range(N):
  if L[i]==c:
    print(d)
  else:
    print(c)

Buggy submission (verdict: Runtime Error):
L=list()
N=int(input())
for i in range(N):
  a=int(input())
  L.append(a)
L=L.sorted(L)
c=L[-1]
d=L[-2]
for i in range(N):
  if L[i]==c:
    print(d)
  else:
    print(c)
Problem p03006 (python)

Fixed submission:
N=int(input())
if N==1:
  print(1)
  exit()
L=list()
R=list()
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
k=dict()
for i in range(N-1):
  for j in range(i+1,N):
    a,b=L[i]
    c,d=L[j]
    R.append([a-c,b-d])
    n=str(a-c)+" "+str(b-d)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
    R.append([c-a,d-b])
    n=str(c-a)+" "+str(d-b)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
op=max(k.values())
print(N-op)

Buggy submission (verdict: Runtime Error):
N=int(input())
L=list()
R=list()
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
k=dict()
for i in range(N-1):
  for j in range(i+1,N):
    a,b=L[i]
    c,d=L[j]
    R.append([a-c,b-d])
    n=str(a-c)+" "+str(b-d)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
    R.append([c-a,d-b])
    n=str(c-a)+" "+str(d-b)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
op=max(k.values())
print(N-op)
Problem p03150 (python)

Fixed submission:
S=input()
if S=="keyence":
  print("YES")
  exit()
for i in range(7):
  T=S[:i]+S[len(S)-7+i:]
  if T=="keyence":
    print("YES")
    exit()
print("NO")

Buggy submission (verdict: Runtime Error):
a=input()
c=len(a)
d=c-7
for i in range(8):
  if a[:i]+a[-(7-i):]=="keyence" or a[:i]=="keyence" or a[-(7-i):]=="keyence":
    print("YES")
    sys.exit()
print("NO")
Problem p03194 (python)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N,K=map(int,input().split())
L=factorization(K)
ans=1
for i in L:
  ans*=i[0]**(i[1]//N)
print(ans)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N,K=map(int,input().split())
L=factorization(N)
ans=1
for i in L:
  ans*=L[0]**(L[1]//N)
print(ans)
Problem p03338 (python)

Fixed submission:
N=int(input())
L=list(input())
maxa=-10
for i in range(N-1):
  a=set(L[:i+1])
  b=set(L[i+1:])
  maxa=max(maxa,len(a&b))
print(maxa)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
maxa=-10
for i in range(N-1):
  a=set(L[:i+1])
  b=set([i+1:])
  maxa=max(maxa,len(a&b))
print(maxa)
Problem p03424 (python)

Fixed submission:
N=int(input())
L=list(input().split())
L=set(L)
if len(L)==4:
  print("Four")
else:
  print("Three")

Buggy submission (verdict: Runtime Error):
N=int(input())
L=list(map(int,input().split()))
L=set(L)
if len(L)==4:
  print("Four")
else:
  print("Three")
Problem p03469 (python)

Fixed submission:
S=list(input())
S[3]="8"
print("".join(S))

Buggy submission (verdict: Runtime Error):
S=list(input())
S[3]=8
print("".join(S))
Problem p03485 (python)

Fixed submission:
a,b=map(int,input().split())
if (a+b)%2==0:
  print(int((a+b)/2))
else:
  print(int((1+a+b)/2))

Buggy submission (verdict: Runtime Error):
a,b=int(input().split())
if (a+b)%2==0:
  print((a+b)/2)
else:
  print((1+a+b)/2)

Buggy submission (verdict: Runtime Error):
a,b=int(input())
if (a+b)%2==0:
  print((a+b)/2)
else:
  print((1+a+b)/2)

Buggy submission (verdict: Runtime Error):
a,b=int(print())
if (a+b)%2==0:
  print((a+b)/2)
if (a+b)%2==1:
  print((a+b+1)/2)
Problem p03555 (python)

Fixed submission:
L=list(input())
R=list(input())
if L[0]==R[2] and L[1]==R[1] and L[2]==R[0]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
L=list(map(int,input().split()))
R=list(map(int,input().split()))
if L[0]==R[2] and L[1]==R[1] and L[2]==R[0]:
  print("YES")
else:
  print("NO")
Problem p03624 (python)

Fixed submission:
L=list(input())
L=list(set(L))
L=sorted(L)
R=["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(min(26,len(L))):
  if L[i]!=R[i]:
    print(R[i])
    exit()
if len(L)<26:
  print(R[len(L)])
  exit()
print("None")

Buggy submission (verdict: Runtime Error):
L=list(input())
L=list(set(L))
L=sorted(L)
R=["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 L[i]!=R[i]:
    print(R[i])
    exit()
print("None")
Problem p03625 (python)

Fixed submission:
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if len(R)==0:
  print(0)
  exit()
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])
Problem p03676 (python)

Fixed submission:
import collections

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
K = 2*(10**5)
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, K + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n=int(input())
print(n)
nCk=n
R=list()
L=list(map(int,input().split()))
c = collections.Counter(L)
nikai=c.most_common()[0][0]#2回出てくる数
for i in range(n+1):
  if L[i]==nikai:
    R.append(i)
#Rに二個のindがある。それぞれR[0]こ、N-R[1]
k=n-R[1]+R[0]
for i in range(1,n):
  nCk=cmb(n+1,i+1,mod)
  a = cmb(k,i,mod)
  print((nCk-a)%mod)
print(1)

Buggy submission (verdict: Runtime Error):
import collections

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
K = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, K + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n=int(input())
print(n)
nCk=n
R=list()
L=list(map(int,input().split()))
c = collections.Counter(L)
nikai=c.most_common()[0][0]#2回出てくる数
for i in range(n+1):
  if L[i]==nikai:
    R.append(i)
#Rに二個のindがある。それぞれR[0]こ、N-R[1]
k=n-R[1]+R[0]
for i in range(1,n):
  nCk=cmb(n+1,i+1,mod)
  a = cmb(k,i,mod)
  print((nCk-a)%mod)
print(1)
Problem p03696 (python)

Fixed submission:
N=int(input())
S=input()
i=0
hidari=str()
migi=str()
a=0
while i<N:
  if S[i]==")":
    hidari+="("
    i+=1
  else:
    break
while i<N:
  if S[i]=="(":
    a+=1
  else:
    a-=1
  i+=1
if a<0:
  hidari+=abs(a)*"("
elif a>0:
  migi+=a*")"
s=hidari+S+migi


i=0
hidari=str()
migi=str()
a=0
while i<N:
  if S[i]==")":
    hidari+="("
    i+=1
  else:
    break
while i<N:
  if S[i]=="(":
    if a<0:
      a=0
    a+=1
    mina=0
  else:
    a-=1
    if a<0:
      if mina>a:
        hidari+="("
  i+=1
if a>0:
  migi+=a*")"
t=hidari+S+migi
if len(s)==len(t):
  print(s)
elif len(s)>len(t):
  print(s)
else:
  print(t)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
i=0
hidari=str()
migi=str()
a=0
while S[i]==")":
  hidari+="("
  i+=1
while i<N:
  if S[i]=="(":
    a+=1
  else:
    a-=1
  i+=1
if a<0:
  hidari+=abs(a)*"("
elif a>0:
  migi+=a*")"
print(hidari+S+migi)
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
if b-a==c-b:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if b-a=c-b:
  print("YES")
else:
  print("NO")
Problem p03854 (python)

Fixed submission:
T=input()
while True:
  if T==str():
    print("YES")
    exit()
  if len(T)<5:
    print("NO")
    exit()
  if T[-5:]=="dream":
    T=str(T[:-5])
  elif T[-7:]=="dreamer":
    T=str(T[:-7])
  elif T[-5:]=="erase":
    T=str(T[:-5])
  elif T[-6:]=="eraser" :
    T=str(T[:-6])
  else:
    print("NO")
    exit()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
def saiki(T):
  if len(T)<=len(S):
    if T==S:
      print("YES")
      exit()
    return saiki(T+"dream"),saiki(T+"erase"),saiki(T+"dreamer"),saiki(T+"eraser")
S=input()
saiki("")
print("NO")
Problem p04014 (python)

Fixed submission:
import sys
def yakusu(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N=int(input())
K=int(input())
if N==K:
  print(N+1)
  exit()
if N<K:
  print(-1)
  exit()
L=list()
setL=set()
#N-Kはa-1の倍数
L=yakusu(N-K)
L=[i+1 for i in L]
for i in L:
  ans=0
  m=N
  while True:
    if m<i:
      ans+=m
      break
    else:
      ans+=m%i
      m=m//i
  if ans==K:
    print(i)
    exit()
print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=int(input())
if n==s:
  print(n+1)
  exit()
if (n+3)//2<=s:
  print(-1)
  exit()
ewew
Problem p04035 (python)

Fixed submission:
K=10**10
import sys
N,L=map(int,input().split())
T=list(map(int,input().split()))
for i in range(N-1):
  if T[i]+T[i+1]>=L:
    K=i
    print("Possible")
    break
if K==10**10:
  print("Impossible")
  sys.exit()
K=K+1
R=list(range(1,K))
M=list(range(K+1,N))
M.reverse()
R.extend(M)
R.append(K)
for i in range(N-1):
  print(R[i])

Buggy submission (verdict: Runtime Error):
import sys
K=10**10
N,L=map(int,input().split())
T=list(map(int,input().split()))
for i in range(N-1):
  if T[i]+T[i+1]>=L:
    K=i
    print("Possible")
    break
if K==10**10:
  print("Impossible")
K=K+1
R=list(range(1,K))
R.extend(list(range(K+1,N)))
R.append(K)
R=list(map(str,R))
for i in range(N-1):
  print(R[i])

Buggy submission (verdict: Runtime Error):
N,L=map(int,input().split())
T=list(map(int,input().split()))
for i in range(N-1):
  if T[i]+T[i+1]>=L:
    K=i
    break
K=K+1
R=list(range(1,K))
R.extend(list(range(K+1,N)))
R.append(K)
R=list(map(str,R))
print(" ".join(R))
Problem p03294 (python)

Fixed submission:
import fractions as math

n = input()
a = list(map(int, input().split()))

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

l = a[0]
for num in a[1:]:
    l = lcm(num, l)

ans = 0
for num in a:
    ans += (l - 1) % num

print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import imp
import os

import setuptools
from pkg_resources import parse_version
from setuptools import setup

if parse_version(setuptools.__version__) < parse_version('30.3.0'):
    raise RuntimeError('setuptools>=30.3.0 is required for "setup.cfg"')


def load_module(module_path):
    path = None
    for name in module_path.split('.'):
        file, path, description = imp.find_module(name, path)
        path = [path]
    return imp.load_module(name, file, path[0], description)


version = load_module('onlinejudge.__about__')

setup(
    name=version.__package_name__,
    version=version.__version__,
    author=version.__author__,
    author_email=version.__email__,
    url=version.__url__,
    license=version.__license__,
    description=version.__description__,
)

Buggy submission (verdict: Runtime Error):
import fraction as math

n = input()
a = list(map(int, input().split()))

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

l = a[0]
for num in a[1:]:
    l = lcm(num, l)

ans = 0
for num in a:
    ans += (l - 1) % num

print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = input()
a = list(map(int, input().split()))

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

l = a[0]
for num in a[1:]:
    l = lcm(num, l)

ans = 0
for num in a:
    ans += (l - 1) % num

print(ans)
Problem p03423 (python)

Fixed submission:
print(int(input())// 3)

Buggy submission (verdict: Runtime Error):
print(input() // 3)
Problem p02609 (python)

Fixed submission:
N = int(input())
X = input()

memo = {}


def popcount(n):
    return bin(n).count('1')


def f(n):
    if n == 0:
        return 0
    if n in memo:
        return memo[n]
    memo[n] = 1 + f(n % popcount(n))
    return memo[n]


def solve(N, X):
    Xint = int(X, 2)
    p = popcount(Xint)
    if 1 < p:
        x1 = Xint % (p - 1)
    x2 = Xint % (p + 1)
    ans = []
    b = 1
    if 1 < p:
        bmod1 = b % (p - 1)
    bmod2 = b % (p + 1)
    for i in range(N):
        if X[-1 - i] == '1':
            if 1 < p:
                ans.append(1 + f((x1 - bmod1) % (p - 1)))
            else:
                ans.append(0)
        else:
            ans.append(1 + f((x2 + bmod2) % (p + 1)))
        b <<= 1
        if 1 < p:
            bmod1 = bmod1 * 2 % (p - 1)
        bmod2 = bmod2 * 2 % (p + 1)

    return list(reversed(ans))


for x in solve(N, X):
    print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = input()

memo = {}


def popcount(n):
    return bin(n).count('1')


def f(n):
    if n == 0:
        return 0
    if n in memo:
        return memo[n]
    memo[n] = 1 + f(n % popcount(n))
    return memo[n]


Xint = int(X, 2)
p = popcount(Xint)
x1 = Xint % (p - 1) if 1 < p else None
x2 = Xint % (p + 1)
ans = []
b = 1
bmod1 = b % (p - 1) if 1 < p else None
bmod2 = b % (p + 1)
for i in range(N):
    if X[-1 - i] == '1':
        if 1 < p:
            ans.append(1 + f((x1 - bmod1) % (p - 1)))
        else:
            ans.append(1)
    else:
        ans.append(1 + f((x2 + bmod2) % (p + 1)))
    b <<= 1
    bmod1 = bmod1 * 2 % (p - 1) if 0 < p else None
    bmod2 = bmod2 * 2 % (p + 1)
for a in reversed(ans):
    print(a)
Problem p02744 (python)

Fixed submission:
from collections import deque

N = int(input())

queue = deque()
queue.append((0,))
while queue:
    s = queue.popleft()
    if len(s) == N:
        print(''.join('abcdefghij'[i] for i in s))
        continue
    for i in range(max(s) + 2):
        queue.append(s + (i,))

Buggy submission (verdict: Runtime Error):
from collections import deque

N = int(input())

queue = deque()
queue.append((0,)
while queue:
    s = queue.popleft()
    if len(s) == N:
        print(''.join('abcdefghij'[i] for i in s))
        continue
    for i in range(max(s) + 2):
        queue.append(s + (i,))
Problem p02900 (python)

Fixed submission:
from fractions import gcd


def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    m = 3
    while m ** 2 <= n:
        if n % m == 0:
            return False
        m += 2
    return True


A, B = map(int, input().split())
d = gcd(A, B)
n = 1
s = set()
while n ** 2 <= d:
    if d % n == 0:
        if is_prime(n):
            s.add(n)
        if is_prime(d // n):
            s.add(d // n)
    n += 1
s.add(1)
print(len(s))

Buggy submission (verdict: Runtime Error):
import math


def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    m = 3
    while m ** 2 <= n:
        if n % m == 0:
            return False
        m += 2
    return True


A, B = map(int, input().split())
d = math.gcd(A, B)
n = 1
s = set()
while n ** 2 <= d:
    if d % n == 0:
        if is_prime(n):
            s.add(n)
        if is_prime(d // n):
            s.add(d // n)
    n += 1
s.add(1)
print(len(s))
Problem p02957 (python)

Fixed submission:
A, B = map(int, input().split())
print((A + B) // 2 if abs(A - B) % 2 == 0 else 'IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())
print((A + B) // 2 if abs(A - B) % 2 == 0 else 'IMPOSSIBLE')
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
    print('Hello World')
else:
    print(int(input()) + int(input()))

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print('Hello World')
else:
    A, B = map(int, input().split())
    print(A + B)
Problem p03261 (python)

Fixed submission:
N = int(input())
words = []
for _ in range(N):
    words.append(input())
print('Yes' if all(words[i].startswith(words[i-1][-1]) for i in range(1, N)) and len(set(words)) == N else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
words = []
for _ in range(N):
    words.append(input())
print('Yes' if all(w[i].startswith(w[i-1][-1]) for i in range(1, N)) and len(set(words)) == N else 'No')
Problem p03962 (python)

Fixed submission:
print len(set(map(int, raw_input().split())))

Buggy submission (verdict: Runtime Error):
print len({map(int, raw_input().split())})
Problem p04043 (python)

Fixed submission:
xs = map(int, raw_input().split())
print 'YES' if sorted(xs) == [5, 5, 7] else 'NO'

Buggy submission (verdict: Runtime Error):
xs = map(int, raw_input())
print 'YES' if sorted(xs) == [5, 5, 7] else 'NO'
Problem p02564 (python)

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

sys.setrecursionlimit(10**6 + 5)

def dfs_numbering(st, M, V, ANS, cnt, v):
    ST = [st]
    while len(ST) > 0:
        # print(ST,V)
        i = ST[-1]
        if ANS[i] == -1:
            V[i] = v
            end = 1
            for x in M[i]:
                if V[x] == -1:
                    ST.append(x)
                    end = 0
                    # cnt = dfs_numbering(x, M, V, ANS, cnt, v)
            if end == 1:
                ST.pop()
                ANS[i] = cnt
                cnt += 1
        else:
            ST.pop()
    return cnt

class scc():
    def __init__(self, n):
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        cnt = 0
        for i in range(n):
            if V[i] == -1:
                cnt = dfs_numbering(i, self.M, V, ANS, cnt, 0)

        # print(ANS)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        # print(ANS1)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

n, m = map(int,input().split())

S = scc(n)
for i in range(m):
    frm, to = map(int,input().split())
    S.add_edge(frm, to)
ANS = S.scc_list()

print(len(ANS))
for i in range(len(ANS)):
    print(len(ANS[i]), end=" ")
    print(*ANS[i])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]


def dfs_numbering(i, M, V, ANS, cnt, v):
    V[i] = v
    for x in M[i]:
        if V[x] == -1:
            cnt = dfs_numbering(x, M, V, ANS, cnt, v)
    ANS[i] = cnt
    return cnt + 1

class scc():
    def __init__(self, n):
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        for i in range(n):
            if V[i] == -1:
                dfs_numbering(i, self.M, V, ANS, 0, 0)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

S = scc(n)
for i in range(m):
    S.add_edge(C[i][0], C[i][1])
ANS = S.scc_list()

print(len(ANS))
for i in range(len(ANS)):
    print(*([len(ANS[i])] + ANS[i]))
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()

# n = 3
# x = "100"

l = 2*10**5 + 5
A = [0] * l
for i in range(1,l):
    ab = format(i, "b")
    abo = ab.count("1")
    A[i] = i % abo

B = [-1] * l
B[0] = 0
# print(A[:10])

def dd(y):
    # print(y)
    if B[y] == -1:
        return dd(A[y])+1
    else:
        return B[y]

for i in range(1, l):
    # print(dd(i))
    B[i] = dd(i)

# print(B[:100])

m = x.count("1")
m0 = m-1
m00 = m0
if m0 == 0:
    m0 = 1

m1 = m+1
M0 = [1]
M1 = [1]
for i in range(l):
    M0.append((M0[-1]*2) % m0)
    M1.append((M1[-1]*2) % m1)

n0 = 0
n1 = 0
for i in range(n):
    if x[n-1-i] == "1":
        n0 = (n0 + M0[i]) % m0
        n1 = (n1 + M1[i]) % m1

for i in range(n):
    nn = 0
    if x[i] == "1":
        nn = (n0 - M0[n-i-1]) % m0
    else:
        nn = (n1 + M1[n-i-1]) % m1
    print(B[nn]+1 if (m00!=0 or x[i]!="1") else 0)

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

l = 2*10**5 + 5
A = [0] * l
for i in range(1,l):
    ab = format(i, "b")
    abo = ab.count("1")
    A[i] = i % abo

B = [-1] * l
B[0] = 0
# print(A[:10])

def dd(y):
    # print(y)
    if B[y] == -1:
        return dd(A[y])+1
    else:
        return B[y]

for i in range(1, l):
    # print(dd(i))
    B[i] = dd(i)

# print(B[:10000])

m = x.count("1")
m0 = m-1
m1 = m+1
M0 = [1]
M1 = [1]
for i in range(l):
    M0.append((M0[-1]*2) % m0)
    M1.append((M1[-1]*2) % m1)

n0 = 0
n1 = 0
for i in range(n):
    if x[n-1-i] == "1":
        n0 = (n0 + M0[i]) % m0
        n1 = (n1 + M1[i]) % m1

for i in range(n):
    nn = 0
    if x[i] == "1":
        nn = (n0 - M0[n-i-1]) % m0
    else:
        nn = (n1 + M1[n-i-1]) % m1
    print(B[nn]+1)