Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
l=sorted(list(map(int,input().split())))
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]+l[j]>l[k]:
                ans+=1
print(ans)

Fixed submission:
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        x=bisect.bisect_left(l,l[i]+l[j])-j-1
        ans+=max(0,x)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n+1):
    print(a.index(i)+1,end=" ")

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
for i in range(n):
    s[a[i]-1]=i+1
print(*s)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
for i in range(n):
    c=a.index(i+1)
    s[i]=c+1
for i in range(n):
    print(s[i],end=" ")

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
for i in range(n):
    s[a[i]-1]=i+1
print(*s)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
for i in range(n):
    c=a.index(i+1)
    s[i]=c+1
for i in range(n):
    print(s[i],end=" ")

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
for i in range(n):
    s[a[i]-1]=i+1
print(*s)
Buggy python submission (verdict: Time Limit Exceeded):
def divisors(n):
   d=[]
   for i in range(1,int(n**0.5)+1):
       if n%i==0:
           d.append(i)
           if i!=n//i:
               d.append(n//i)
   d.sort()
   return d
n=int(input())
table=[0]*(n+1)
ball=[]
a=list(map(int,input().split()))[::-1]
for i in range(n):
    if table[n-i]!=a[i]:
        ball.append(n-i)
        for j in divisors(n-i):
            table[j]=1-table[j]
print(len(ball))
if len(ball)!=0:
    print(*ball)

Fixed submission:
def divisors(n):
   d=[]
   for i in range(1,int(n**0.5)+1):
       if n%i==0:
           d.append(i)
           if i!=n//i:
               d.append(n//i)
   d.sort()
   return d
n=int(input())
table=[0]*(n+1)
ball=[]
a=list(map(int,input().split()))[::-1]
for i in range(n):
    if table[n-i]!=a[i]:
        ball.append(n-i)
        for j in divisors(n-i):
            table[j]=1-table[j]
print(len(ball))
if len(ball)!=0:
    print(*ball)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n-k+1,p)
invf=[]
for i in f:
    invf.append(pow(i,-1,p))
ans=[]
for i in range(1,k+1):
    if i>n-k+1:
        ans.append(0)
        continue
    ans.append(((f[n-k+1]*invf[n-k+1-i])%p)*((invf[i]*f[k-1])%p)*((invf[i-1]*invf[k-i]))%p)
for i in ans:
    print(i%p)

Fixed submission:
n,k=map(int,input().split())
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
invf=[]
for i in f:
    invf.append(pow(i,-1,p))
ans=[]
for i in range(1,k+1):
    if i>n-k+1:
        ans.append(0)
        continue
    ans.append(((f[n-k+1]*invf[n-k+1-i])%p)*((invf[i]*f[k-1])%p)*((invf[i-1]*invf[k-i]))%p)
for i in ans:
    print(i%p)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n-k+1,p)
invf=[]
for i in f:
    invf.append(pow(i,-1,p))
ans=[]
for i in range(1,k+1):
    ans.append(f[n-k+1]*invf[n-k+1-i]*invf[i]*i**(k-i))
for i in ans:
    print(i%p)

Fixed submission:
n,k=map(int,input().split())
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
invf=[]
for i in f:
    invf.append(pow(i,-1,p))
ans=[]
for i in range(1,k+1):
    if i>n-k+1:
        ans.append(0)
        continue
    ans.append(((f[n-k+1]*invf[n-k+1-i])%p)*((invf[i]*f[k-1])%p)*((invf[i-1]*invf[k-i]))%p)
for i in ans:
    print(i%p)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[]
time=0
for i in range(n):
    x,y=map(int,input().split())
    a.append([x,y])
c=sorted(set([a[i][1] for i in range(n)]))
for i in c:
    for x,y in a:
        if i==y:
            time+=x
            if time>y:
                print("No")
                exit()
print("Yes")

Fixed submission:
n=int(input())
a,f,b=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[1]),1,0
for i in range(n):
    b+=a[i][0] 
    if b>a[i][1]: 
        f=0 
print('Yes' if f==1 else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[]
time=0
for i in range(n):
    x,y=map(int,input().split())
    a.append([x,y])
c=sorted(set([a[i][1] for i in range(n)]))
for i in c:
    for x,y in a:
        if i==y:
            time+=x
            if time>y:
                print("No")
                exit()
print("Yes")

Fixed submission:
n=int(input())
a,f,b=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[1]),1,0
for i in range(n):
    b+=a[i][0] 
    if b>a[i][1]: 
        f=0 
print('Yes' if f==1 else 'No')
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=set([int(input()) for j in range(m)])
dp=[0]*(n+1)
dp[0]=1
if not a[0]==1:
    dp[1]=1
else:
    dp[1]=0
for i in range(n-1):
    if i+2 in a:
        dp[i+2]=0
    else:
        dp[i+2]=(dp[i+1]+dp[i])%(10**9+7)
print(dp[n])

Fixed submission:
n,m=map(int,input().split())
a=set([int(input()) for j in range(m)])
dp=[0]*(n+1)
dp[0]=1
if not 1 in a:
    dp[1]=1
else:
    dp[1]=0
for i in range(n-1):
    if i+2 in a:
        dp[i+2]=0
    else:
        dp[i+2]=(dp[i+1]+dp[i])%(10**9+7)
print(dp[n])
Buggy python submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())),reverse=True)
ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort(reverse=True)
ans=[]
for i in range(min(k,x*y)):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Fixed submission:
a=[int(input()) for i in range(5)]
k=int(input())
for i in range(4):
    for j in range(i+1,5):
        if a[j]-a[i]>k:
            print(":(")
            exit()
print("Yay!")
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())),reverse=True)
ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort(reverse=True)
ans=[]
for i in range(min(k,x*y)):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Fixed submission:
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())),reverse=True)
ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort(reverse=True)
ans=[]
for i in range(min(k,x*y)):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**9+5]*n
dp[0]=0
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split()) #足場は0番目からn-1番目までのn個
h=list(map(int,input().split())) #h[i]はi番目の足場の高さ
DP=[10**9+1]*n
DP[0]=0 #0番目の足場に到達するのに必要なコストは0
DP[1]=abs(h[1]-h[0]) 

#j番目からi番目まで飛ぶ場合の追加コストはabs(h[i]-h[j])、ただしi-1<=j<=i-k

for i in range(2,n):
    for j in range(max(0,i-k),i):
        DP[i]=min(DP[i],DP[j]+abs(h[i]-h[j]))
print(DP[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split()) #足場は0番目からn-1番目までのn個
h=list(map(int,input().split())) #h[i]はi番目の足場の高さ
DP=[10**9+1]*n
DP[0]=0 #0番目の足場に到達するのに必要なコストは0
DP[1]=abs(h[1]-h[0]) 

#j番目からi番目まで飛ぶ場合の追加コストはabs(h[i]-h[j])、ただしi-1<=j<=i-k

for i in range(2,n):
    for j in range(max(0,i-k),i):
        DP[i]=min(DP[i],DP[j]+abs(h[i]-h[j]))
print(DP[-1])

Fixed submission:
n,k=map(int,input().split()) #足場は0番目からn-1番目までのn個
h=list(map(int,input().split())) #h[i]はi番目の足場の高さ
DP=[10**9+1]*n
DP[0]=0 #0番目の足場に到達するのに必要なコストは0
DP[1]=abs(h[1]-h[0]) 

#j番目からi番目まで飛ぶ場合の追加コストはabs(h[i]-h[j])、ただしi-1<=j<=i-k

for i in range(2,n):
    for j in range(max(0,i-k),i):
        DP[i]=min(DP[i],DP[j]+abs(h[i]-h[j]))
print(DP[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,mw=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(mw+1)] for _ in range(n+1)]
for i in range(n):
    weight,value=l[i]
    for j in range(mw+1):
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
        if j+weight<=mw:
            dp[i+1][j+weight]=max(dp[i][j+weight],dp[i][j]+value)
print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        weight,value=a[i]
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        if j+weight<=w:
            dp[i+1][j+weight]=max(dp[i][j+weight],dp[i][j]+value)
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(W+1)] for _ in range(n+1)]
for i in range(n):
    weight,value=a[i]
    for j in range(W+1):
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        if j+weight<=W:
            dp[i+1][j+weight]=max(dp[i][j+weight],dp[i][j]+value)
print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        weight,value=a[i]
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        if j+weight<=w:
            dp[i+1][j+weight]=max(dp[i][j+weight],dp[i][j]+value)
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        weight,value=a[i]
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        if j+weight<=w:
            dp[i+1][j+weight]=max(dp[i][j+weight],dp[i][j]+value)
print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        weight,value=a[i]
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        if j+weight<=w:
            dp[i+1][j+weight]=max(dp[i][j+weight],dp[i][j]+value)
print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
import math
def ggcd(a):
    if len(a)==0:
        return 0
    i=0
    return math.gcd(a[i],ggcd(a[i+1:]))
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n-1):
    b.append(abs(a[i]-a[i+1]))
c=ggcd(b)
d=abs(x-a[0])
print(math.gcd(c,d))

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
import math
def ggcd(a):
    if len(a)==0:
        return 0
    i=0
    return math.gcd(a[i],ggcd(a[i+1:]))
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n-1):
    b.append(abs(a[i]-a[i+1]))
c=ggcd(b)
d=abs(x-a[0])
print(math.gcd(c,d))

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

Buggy python submission (verdict: Runtime Error):
import math
def ggcd(a):
    if len(a)==0:
        return 0
    i=0
    return math.gcd(a[i],ggcd(a[i+1:]))
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n-1):
    b.append(abs(a[i]-a[i+1]))
c=ggcd(b)
d=abs(x-a[0])
print(math.gcd(c,d))

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)
Buggy python submission (verdict: Runtime Error):
s=input()
w=set()
for i in (len(s)):
    w.add(s[i])
if len(s)==len(w):
    print("Yes")
else:
    print("No")

Fixed submission:
s=input()
w=set()
for i in range(len(s)):
    w.add(s[i])
if len(s)==len(w):
    print("yes")
else:
    print("no")
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
v=[[0]*13 for i in range(n+1)]
v[0][0]=1
m=10**9+7
for i in range(n):
    for j in range(13):
        for k in range(10):
            x=(10*j+k)%13
            v[i+1][x]=(v[i+1][x]+(1 if s[i]=='?' or s[i]==str(k) else 0)*v[i][j])%m
print(v[n][5])


Fixed submission:
s=input()
n=len(s)
v=[[0]*13 for i in range(n+1)]
v[0][0]=1
m=10**9+7
for i in range(n):
    for j in range(13):
        for k in range(10):
            x=(10*j+k)%13
            v[i+1][x]=(v[i+1][x]+(1 if s[i]=='?' or s[i]==str(k) else 0)*v[i][j])%m
print(v[n][5])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [int(_) for _ in input().split()]

inf = 10**10
dp = [inf]*n

dp[0] = 0

for i in range(n):
    for j in range(i+1, min(n, i+k+1)):
        dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]))

print(dp[n-1])


Fixed submission:
n, k = map(int, input().split())
h = [int(_) for _ in input().split()]

inf = 10**10
dp = [inf]*n

dp[0] = 0

for i in range(n):
    for j in range(i+1, min(n, i+k+1)):
        dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
N=int(input())
A=list(map(int,input().split(' ')))
L = 1
def lcm(x,y):
    return x//gcd(x,y)*y
for a in A:
    L = lcm(L,a)
print(sum([L//a for a in A])%(10**9+7))

Fixed submission:
from fractions import gcd
N=int(input())
A=list(map(int,input().split(' ')))
ans = 0
L = 1
def lcm(x,y):
    return x//gcd(x,y)*y
for a in A:
    newL = lcm(L,a)
    ans = ans*(newL//L) + newL//a
    L = newL
print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
import time
print((time.time()%10)^int(input()))

Fixed submission:
print(int(input())^1)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
V=2*N+2
INF=10**14
G=[[] for i in range(V)]
D=[INF]*V
PV,PE=[0]*V,[0]*V
def ae(fr,to,ca,co):
  global G
  G[fr].append([to,ca,co,len(G[to]),0])
  G[to].append([fr,0,-co,len(G[fr])-1,0])

def mcf(s,t,f):
  global G,V,INF,D,PV,PE
  for i in range(V):
    for j in range(len(G[i])):
      G[i][j][4]=0
  r=0
  z=f
  while z>0:
    D=[INF]*V
    D[s]=0
    ud=True
    while ud:
      ud=False
      for x in range(V):
        if D[x]==INF:
          continue
        for i in range(len(G[x])):
          if G[x][i][1]>0 and D[G[x][i][0]]>D[x]+G[x][i][2]:
            D[G[x][i][0]]=D[x]+G[x][i][2]
            PV[G[x][i][0]]=x
            PE[G[x][i][0]]=i
            ud=True
    if D[t]==INF:
      return -INF
    d=z
    x=t
    while x!=s:
      d=min(d,G[PV[x]][PE[x]][1])
      x=PV[x]
    z-=d
    r+=d*D[t]
    x=t
    while x!=s:
      G[PV[x]][PE[x]][1]-=d
      G[PV[x]][PE[x]][4]+=d
      G[x][G[PV[x]][PE[x]][3]][1]+=d
      G[x][G[PV[x]][PE[x]][3]][4]-=d
      x=PV[x]
  return r

s=N*2
t=s+1
for i in range(N):
  ae(s,i,K,0)
  ae(N+i,t,K,0)
  for j in range(N):
    ae(i,N+j,1,10**10-A[i][j])
ae(s,t,N*K,10**10)
print(N*K*10**10-mcf(s,t,N*K))
P=[['.']*N for i in range(N)]
for i in range(N):
  for j in range(len(G[i])):
    if G[i][j][4]>0:
      P[i][G[i][j][0]-N]='X'
  print(''.join(P[i]))

Fixed submission:
N,K=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
V=2*N+2
INF=10**14
G=[[] for i in range(V)]
D=[INF]*V
PV,PE=[0]*V,[0]*V
def ae(fr,to,ca,co):
  global G
  G[fr].append([to,ca,co,len(G[to]),0])
  G[to].append([fr,0,-co,len(G[fr])-1,0])

def mcf(s,t,f):
  global G,V,INF,D,PV,PE
  for i in range(V):
    for j in range(len(G[i])):
      G[i][j][4]=0
  r=0
  z=f
  while z>0:
    D=[INF]*V
    D[s]=0
    ud=True
    while ud:
      ud=False
      for x in range(V):
        if D[x]==INF:
          continue
        for i in range(len(G[x])):
          if G[x][i][1]>0 and D[G[x][i][0]]>D[x]+G[x][i][2]:
            D[G[x][i][0]]=D[x]+G[x][i][2]
            PV[G[x][i][0]]=x
            PE[G[x][i][0]]=i
            ud=True
    if D[t]==INF:
      return -INF
    d=z
    x=t
    while x!=s:
      d=min(d,G[PV[x]][PE[x]][1])
      x=PV[x]
    z-=d
    r+=d*D[t]
    x=t
    while x!=s:
      G[PV[x]][PE[x]][1]-=d
      G[PV[x]][PE[x]][4]+=d
      G[x][G[PV[x]][PE[x]][3]][1]+=d
      G[x][G[PV[x]][PE[x]][3]][4]-=d
      x=PV[x]
  return r

s=N*2
t=s+1
for i in range(N):
  ae(s,i,K,0)
  ae(N+i,t,K,0)
  for j in range(N):
    ae(i,N+j,1,10**10-A[i][j])
ae(s,t,N*K,10**10)
print(N*K*10**10-mcf(s,t,N*K))
P=[['.']*N for i in range(N)]
for i in range(N):
  for j in range(len(G[i])):
    if G[i][j][4]>0:
      P[i][G[i][j][0]-N]='X'
  print(''.join(P[i]))
Buggy python submission (verdict: Runtime Error):
def SCC(G):
  D=[]
  C=[len(G)-1]
  U=[1]*len(G)
  def DFS(x):
    if U[x]:
      U[x]=0
      for i in range(len(G[x])):
        DFS(G[x][i])
      D.append(x)
  
  for i in range(len(G)):
    if U[i]:
      DFS(i)
  GR=[[] for i in range(len(G))]
  for i in range(N):
    for j in range(len(G[i])):
      GR[G[i][j]].append(i)
  R=[]
  U=[1]*len(G)
  def DFSR(x):
    if U[x]:
      R[-1].append(x)
      U[x]=0
      for i in range(len(GR[x])):
        DFSR(GR[x][i])
  
  for i in range(len(G)-1,-1,-1):
    if U[D[i]]:
      R.append([])
      DFSR(D[i])
  return R

import sys
S=sys.stdin.readlines()
N,M=map(int,S[0].split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,S[i+1].split())
  G[a].append(b)
P=SCC(G)
print(len(P))
for i in range(len(P)):
  print(*([len(P[i])]+P[i]))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
def SCC(G):
  D=[]
  C=[len(G)-1]
  U=[1]*len(G)
  def DFS(x):
    if U[x]:
      U[x]=0
      for i in range(len(G[x])):
        DFS(G[x][i])
      D.append(x)
  
  for i in range(len(G)):
    if U[i]:
      DFS(i)
  GR=[[] for i in range(len(G))]
  for i in range(N):
    for j in range(len(G[i])):
      GR[G[i][j]].append(i)
  R=[]
  U=[1]*len(G)
  def DFSR(x):
    if U[x]:
      R[-1].append(x)
      U[x]=0
      for i in range(len(GR[x])):
        DFSR(GR[x][i])
  
  for i in range(len(G)-1,-1,-1):
    if U[D[i]]:
      R.append([])
      DFSR(D[i])
  return R

S=sys.stdin.readlines()
N,M=map(int,S[0].split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,S[i+1].split())
  G[a].append(b)
P=SCC(G)
print(len(P))
for i in range(len(P)):
  print(*([len(P[i])]+P[i]))
Buggy python submission (verdict: Runtime Error):
from math import *
from cmath import rect

def dft(f,x):
  if len(f)==1:
    return
  f0,f1=f[0::2],f[1::2]
  dft(f0,x)
  dft(f1,x)
  z=rect(1,x*2*acos(-1)/len(f))
  n=1+0j
  for i in range(len(f)):
    f[i]=f0[i%len(f0)]+n*f1[i%len(f1)]
    n=n*z

def pm(p,q):
  siz=1
  while len(p)+len(q)>siz:
    siz*=2
  np=[]
  nq=[]
  for i in range(len(p)):
    np.append(rect(p[i],0))
  for i in range(len(q)):
    nq.append(rect(q[i],0))
  while len(np)<siz:
    np.append(0+0j)
  while len(nq)<siz:
    nq.append(0+0j)
  dft(np,1)
  dft(nq,1)
  for i in range(siz):
    np[i]=np[i]*nq[i]
  dft(np,-1)
  EPS=0.1
  for i in range(siz):
    np[i]=int(np[i].real/siz+EPS)
  return np

H,W,K=map(int,input().split())
C=[input() for i in range(H)]
DP=0
X=[]
P=0

def poly(x):
  r=[0]*x
  r.append(1)
  r[0]+=1
  return r

def knapsack(L):
  if len(L)==1:
    return poly(L[0])
  a=knapsack(L[:len(L)//2])
  b=knapsack(L[len(L)//2:])
  return pm(a,b)[:K+1]

for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  DP=knapsack(X)[K]
  if len(DP)>K:
    P+=DP[K]
print(P)

Fixed submission:
H,W,K=map(int,input().split())
S=[input() for i in range(H)]
P=0
Q=0
for i in range(1<<H):
  for j in range(1<<W):
    Q=0
    for k in range(H):
      for l in range(W):
        if S[k][l]=='#' and i&(1<<k)!=0 and j&(1<<l)!=0:
          Q+=1
    if Q==K:
      P+=1
print(P)

Buggy python submission (verdict: Runtime Error):
from math import *
from cmath import rect

def dft(f,x):
  if len(f)==1:
    return
  f0,f1=f[0::2],f[1::2]
  dft(f0,x)
  dft(f1,x)
  z=rect(1,x*2*acos(-1)/len(f))
  n=1+0j
  for i in range(len(f)):
    f[i]=f0[i%len(f0)]+n*f1[i%len(f1)]
    n=n*z

def pm(p,q):
  siz=1
  while len(p)+len(q)>siz:
    siz*=2
  np=[]
  nq=[]
  for i in range(len(p)):
    np.append(rect(p[i],0))
  for i in range(len(q)):
    nq.append(rect(q[i],0))
  while len(np)<siz:
    np.append(0+0j)
  while len(nq)<siz:
    nq.append(0+0j)
  dft(np,1)
  dft(nq,1)
  for i in range(siz):
    np[i]=np[i]*nq[i]
  dft(np,-1)
  EPS=0.1
  for i in range(siz):
    np[i]=int(np[i].real/siz+EPS)
  return np

H,W,K=map(int,input().split())
C=[input() for i in range(H)]
DP=[0]*(K+1)
X=[]
P=0

def poly(x):
  r=[0]*x
  r.append(1)
  r[0]+=1
  return r

def knapsack(L):
  if len(L)==1:
    return poly(L[0])
  a=knapsack(L[:len(L)//2])
  b=knapsack(L[len(L)//2:])
  return pm(a,b)[:K+1]

for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  P+=knapsack(X)[K]
print(P)

Fixed submission:
H,W,K=map(int,input().split())
S=[input() for i in range(H)]
P=0
Q=0
for i in range(1<<H):
  for j in range(1<<W):
    Q=0
    for k in range(H):
      for l in range(W):
        if S[k][l]=='#' and i&(1<<k)!=0 and j&(1<<l)!=0:
          Q+=1
    if Q==K:
      P+=1
print(P)
Buggy python submission (verdict: Time Limit Exceeded):
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
T=[int(input())-1 for i in range(D)]
X=[0]*26
Y=[0]*26
M=int(input())
d,q=0,0
P=0
for i in range(D):
  P+=S[i][T[i]]
  for j in range(26):
    X[j]+=C[j]
  X[T[i]]=0
  for j in range(26):
    Y[j]+=X[j]
for i in range(M):
  d,q=map(int,input().split())
  d,q=d-1,q-1
  P-=S[d][T[d]]
  P+=S[d][q]
  for j in range(26):
    X[j]=0
  Y[T[d]],Y[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=T[j]
    for j in range(26):
      X[j]+=C[j]
    X[Z]=0
    Y[T[d]]+=X[T[d]]
    Y[q]+=X[q]
  T[d]=q
  print(P-sum(Y))

Fixed submission:
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
T=[int(input())-1 for i in range(D)]
X=[0]*26
Y=[0]*26
M=int(input())
d,q=0,0
P=0
for i in range(D):
  P+=S[i][T[i]]
  for j in range(26):
    X[j]+=C[j]
  X[T[i]]=0
  for j in range(26):
    Y[j]+=X[j]
for i in range(M):
  d,q=map(int,input().split())
  d,q=d-1,q-1
  P-=S[d][T[d]]
  P+=S[d][q]
  for j in range(26):
    X[j]=0
  Y[T[d]],Y[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=T[j]
    X[T[d]]+=C[T[d]]
    X[q]+=C[q]
    X[Z]=0
    Y[T[d]]+=X[T[d]]
    Y[q]+=X[q]
  T[d]=q
  print(P-sum(Y))
Buggy python submission (verdict: Runtime Error):
print(('pphbhhphph'[int(input())])+'on')

Fixed submission:
print(('pphbhhphph'[int(input()[-1])])+'on')