Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = ""
def next_animal(pre,now,letter):
    if pre == "S" and now == "S" and letter == "o":
        return "S"
    if pre == "S" and now == "S" and letter == "x":
        return "W"
    if pre == "S" and now == "W" and letter == "o":
        return "W"
    if pre == "S" and now == "W" and letter == "x":
        return "S"
    if pre == "W" and now == "S" and letter == "o":
        return "W"
    if pre == "W" and now == "S" and letter == "x":
        return "S"
    if pre == "W" and now == "W" and letter == "o":
        return "S"
    if pre == "W" and now == "W" and letter == "x":
        return "W"

for case in range(4):
    if case == 0:
        ans = "SS"
    if case == 1:
        ans = "SW"
    if case == 2:
        ans = "WS"
    if case == 3:
        ans = "WW"
    for i in range(1,n-1):
        next = next_animal(ans[-1],ans[-2],s[i])
        ans += next
    if ans[-1] == next_animal(ans[1],ans[0],s[0]) and ans[0] == next_animal(ans[-2],ans[-1],s[-1]):
        print(ans)
        exit()

print(-1)

Fixed submission:
n = int(input())
s = input()
ans = ""
def next_animal(pre,now,letter):
    if pre == "S" and now == "S" and letter == "o":
        return "S"
    if pre == "S" and now == "S" and letter == "x":
        return "W"
    if pre == "S" and now == "W" and letter == "o":
        return "W"
    if pre == "S" and now == "W" and letter == "x":
        return "S"
    if pre == "W" and now == "S" and letter == "o":
        return "W"
    if pre == "W" and now == "S" and letter == "x":
        return "S"
    if pre == "W" and now == "W" and letter == "o":
        return "S"
    if pre == "W" and now == "W" and letter == "x":
        return "W"

for case in range(4):
    if case == 0:
        ans = "SS"
    if case == 1:
        ans = "SW"
    if case == 2:
        ans = "WS"
    if case == 3:
        ans = "WW"
    for i in range(1,n-1):
        next = next_animal(ans[-1],ans[-2],s[i])
        ans += next
    if ans[-1] == next_animal(ans[1],ans[0],s[0]) and ans[0] == next_animal(ans[-2],ans[-1],s[-1]):
        print(ans)
        exit()

print(-1)
Buggy python submission (verdict: Runtime Error):
a.b=map(int,input().split())
if a==1:
    if b==1:
        print('Draw')
    else:
        print('Alice')
else:
    if b==1:
        print('Bob')
    else:
        if a>b:
            print('Alice')
        elif a==b:
            print('Draw')
        else:
            print('Bob')

Fixed submission:
a,b=map(int,input().split())
if a==1:
    if b==1:
        print('Draw')
    else:
        print('Alice')
else:
    if b==1:
        print('Bob')
    else:
        if a>b:
            print('Alice')
        elif a==b:
            print('Draw')
        else:
            print('Bob')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
global count
count = 0
def solve(a):
    count += 1
    if count > 10**7:
        print('NO')
        exit()
    if min(a) < 0:
        return False

    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

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

if sum(a) % (n*(n+1)//2) != 0:
    print('NO')
    exit()
else:
    k = sum(a)// (n*(n+1)//2)


for i in range(n-1):
    d = a[i+1] - a[i] - k

    if d > 0 or d % n != 0:
        print('NO')
        exit()

print('YES')

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

def solve(a):
    if min(a) < 0:
        return False
    
    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

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

if sum(a) % (n*(n+1)//2) != 0:
    print('NO')
    exit()
else:
    k = sum(a)// (n*(n+1)//2)


for i in range(n-1):
    d = a[i+1] - a[i] - k

    if d > 0 or d % n != 0:
        print('NO')
        exit()

print('YES')

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

def solve(a):
    print(a)
    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            if a[j] < 0:
                return False
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

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

if sum(a) % (n*(n+1)//2) != 0:
    print('NO')
    exit()
else:
    k = sum(a)// (n*(n+1)//2)


for i in range(n-1):
    d = a[i+1] - a[i] - k

    if d > 0 or d % n != 0:
        print('NO')
        exit()

print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
mod = 10**9+7
ans=[1]*12
prime=[2,3,5,7,11,13,17,19,23,27,29,31]
for i in range(1,n+1):
    j=i
    while j>1:
        for k in range(12):
            if j%prime[k]==0:
                ans[k]=(ans[k]+1)%mod
                j=j//prime[k]
A=1
for m in range(12):
    A = (A*ans[m])%mod
print(A)

Fixed submission:
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
n = int(input())
prime = primes(n)
a = [1]*n
for i in range(1,n+1):
    for p in prime:
        while i%p == 0:
            i = i//p
            a[p-1] += 1
ans = 1
for i in a:
    ans *= i
mod = 10**9 + 7
print(ans%mod)
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
for i in range(k+1):
    for j in range(k+1):
            if k>=s-i-j>=0:
                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 k in range(k+1):
            if i+j+k==s:
                ans+=1
print(ans)


Fixed submission:
k,s=map(int,input().split())
ans=0
for i in range(k+1):
    for j in range(k+1):
            if k>=s-i-j>=0:
                ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x=map(int,input().split())
ans=0
for i in range(a,b+1):
    if i%x==0:
        ans +=1
print(ans)

Fixed submission:
a,b,x = map(int,input().split())
p = a//x
q = b//x
if a%x == 0:
    print(q-p+1)
else:
    print(q-p)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
data = [list(map(int,input().split())) for _ in range(n)]
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納　par[x] == x の時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0)
        self.rank = [0] * (n+1)
        # 各々の集合の要素数（根が代表して値を持っておく）
        self.count = [1] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        # 根でないなら親の要素で再検索
        else:
            # 検索する過程で親を更新
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.count[y] += self.count[x]
            self.count[x] = 0
        else:
            self.par[y] = x
            self.count[x] += self.count[y]
            self.count[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属しているか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 属している集合の要素数
    def size(self,x):
        q = UnionFind.find(self,x)
        return self.count[q]

u = UnionFind(n)
for i in range(1,m+1):
    p = 0
    for j in range(n):
        if p == 0 and i in data[j][1:]:
            q = j
            p = 1
        elif i in data[j][1:] and not u.same_check(j,q):
            u.union(j,q)

if u.size(0) == n:
    print('YES')
else:
    print('NO')

Fixed submission:
import sys
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納　par[x] == x の時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0)
        self.rank = [0] * (n+1)
        # 各々の集合の要素数（根が代表して値を持っておく）
        self.count = [1] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        # 根でないなら親の要素で再検索
        else:
            # 検索する過程で親を更新
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.count[y] += self.count[x]
            self.count[x] = 0
        else:
            self.par[y] = x
            self.count[x] += self.count[y]
            self.count[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属しているか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 属している集合の要素数
    def size(self,x):
        q = UnionFind.find(self,x)
        return self.count[q]

N,M=map(int,input().split())
K=[set() for i in range(M)]
tree=UnionFind(N)
for i in range(N):
    L=[int(i)-1 for i in input().split()]
    for m in L[1:]:
        K[m].add(i)
for i in range(M):
    Ki=list(K[i])
    if len(Ki)==0:
        continue
    for h in range(len(Ki)):
        tree.union(Ki[h],Ki[0])
for i in range(N):
    if not tree.same_check(0,i):
        print('NO')
        sys.exit()
print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans_t, ans_a = map(int,input().split())
for i in range(n-1):
    t, a = map(int,input().split())
    now_t, now_a = t, a
    q = True
    while q:
        if ans_t <= now_t and ans_a <= now_a:
            q = False
            ans_t = now_t
            ans_a = now_a
        else:
            now_t += t
            now_a += a

print(ans_a + ans_t)

Fixed submission:
n = int(input())
ans_t, ans_a = map(int,input().split())
for i in range(n-1):
    t, a = map(int,input().split())

    if ans_t % t == 0:
        p = ans_t//t
    else:
        p = ans_t//t + 1
    if ans_a % a == 0:
        q = ans_a // a
    else:
        q = ans_a// a + 1

    r = max(p, q)
    ans_a = a * r
    ans_t = t * r


print(ans_a + ans_t)
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
a = 0

for t in s:
    if t == 'p':
        a += 1


print(n//2 - b)

Fixed submission:
s = input()
n = len(s)
a = 0

for t in s:
    if t == 'p':
        a += 1


print(n//2 - a)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
i = 0
while i < n-1:
    if s[i] == "S" and s[i+1] == "T":
        s = s[:i] + s[i+2:]
        i = 0
        n -= 2
    else:
        i += 1

print(n)


Fixed submission:
s = input()
y = [0]
z = []
for t in s:
    if t == "S":
        y.append(t)
    elif y[-1] == "S":
        del y[-1]
    else:
        z.append(t)

print(len(y) + len(z) - 1)
Buggy python submission (verdict: Time Limit Exceeded):
alphabet_small = {chr(i):i-97 for i in range(97, 97+26)}
s = input()
k = int(input())
ans =""
for character in s:
    i = alphabet_small[character]
    #print(i,character)
    if i != 0 and k >= 26 - i:
        k -= 26 - i
        ans += "a"
    else:
        ans += character


if k > 0:
    k %= 26
    ans = ans[:-1] + chr((alphabet_small[ans[-1]]+k)%26+97)

print(ans)

Fixed submission:
alphabet_small = {chr(i):i-97 for i in range(97, 97+26)}
s = input()
k = int(input())
ans =""
for character in s:
    i = alphabet_small[character]
    #print(i,character)
    if i != 0 and k >= 26 - i:
        k -= 26 - i
        ans += "a"
    else:
        ans += character


if k > 0:
    k %= 26
    ans = ans[:-1] + chr((alphabet_small[ans[-1]]+k)%26+97)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
alphabet_small = [chr(i) for i in range(97, 97+26)]
s = input()
k = int(input())
ans = ""
for num,character in enumerate(s):
    for i in range(26):
        if character == alphabet_small[i]:
            if i != 0 and k >= 26-i:
                k -= 26-i
                ans += "a"
            else:
                ans += character
            break

if k > 0:
    k %= 26
    for i in range(26):
        if ans[-1] == alphabet_small[i]:
            ans = ans[:-1] + alphabet_small[(i+k)%26]
            break

print(ans)

Fixed submission:
alphabet_small = {chr(i):i-97 for i in range(97, 97+26)}
s = input()
k = int(input())
ans =""
for character in s:
    i = alphabet_small[character]
    #print(i,character)
    if i != 0 and k >= 26 - i:
        k -= 26 - i
        ans += "a"
    else:
        ans += character


if k > 0:
    k %= 26
    ans = ans[:-1] + chr((alphabet_small[ans[-1]]+k)%26+97)

print(ans)
Buggy python submission (verdict: Runtime Error):
print(int(input())*(int(input())+1)//2)

Fixed submission:
n=int(input())
print(n*(n+1)//2)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
k = int(input())

while k > 0:
  if a > b:
    b *= 2
    k -= 1

while k > 0:
  if b > c:
    c *= 2
    k -= 1
    
if a < b and b < c:
  print("Yes")
else
  print("No")
    

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

while a >= b:
    b *= 2
    ct += 1
    
while b >= c:
    c *= 2
    ct += 1
    

if ct <= k:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))

if a[0] < 10 && a[1] < 10:
  print(a[0] * a[1])
else:
  print(-1)

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

if a[0] < 10 and a[1] < 10:
  print(a[0] * a[1])
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
import math
a = int(input())
flag = False
i = 0

while i <= math.sqrt(a):
  b = divmod(a)
  if b[0] < 10 and b[1] == 0:
    flag = True
  else:
    i+=1
    
if flag:
  print("Yes")
else:
  print("No")



Fixed submission:
import math
a = int(input())
flag = False
i = 1

while i <= math.sqrt(a):
  b = divmod(a,i)
  if b[0] < 10 and b[1] == 0:
    flag = True
  i+=1
    
if flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
H = list(map(int,input().split()))
h = H[0]
w = H[1]
x = H[2]
y = H[3]

if (h-2*x)*(w-2*y)!=0 or ((h-2*x==0) and (w-2*y==0)) and (x != h x != 0 or y != 0 y != w):
  a = 1
else:
  a = 0

print(h*w/2,a)

Fixed submission:
H = list(map(int,input().split()))
h = H[0]
w = H[1]
x = H[2]
y = H[3]

if (h-2*x==0) and (w-2*y==0):
  a = 1
else:
  a = 0

print(h*w/2,a)
Buggy python submission (verdict: Runtime Error):
a,b,c,n=map(int,input().split())
count=0
for i in range(n//a)
  for j in range(n//b)
  	if n-i*a-j*b>=0 && n-i*a-j*b%c==0:
      count++
print(count)

Fixed submission:
a,b=map(int,input().split())
print(a-b+1)
Buggy python submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t*(b//a))


Fixed submission:
a,b,t=list(map(int,input().split()))
print((t//a)*b)

Buggy python submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t(*b//a))


Fixed submission:
a,b,t=list(map(int,input().split()))
print((t//a)*b)

Buggy python submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t*b(//a))


Fixed submission:
a,b,t=list(map(int,input().split()))
print((t//a)*b)

Buggy python submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t*b//a)

Fixed submission:
a,b,t=list(map(int,input().split()))
print((t//a)*b)
Buggy python submission (verdict: Runtime Error):
a,b=int(input())
print(max(a,b)+max(max(a,b)-1,min(a,b)))

Fixed submission:
a,b=map(int,input().split())
print(max(a,b)+max(max(a,b)-1,min(a,b)))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
print((a+b+1)//2)

Fixed submission:
a,b=map(int,input().split())
print((a+b+1)//2)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
import math
from functools import reduce
import fractions

def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

c = fractions.gcd(*a)

for i in a:
  if i - k > 0 and (i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")
 

Fixed submission:
import numpy as np
import sys
import math
from functools import reduce
import fractions as fr

def gcd(*numbers):
    return reduce(fr.gcd, numbers)

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

c = int(gcd(*a))

for i in a:
  if i - k >= 0 and (i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []

for i in range(len(a) - 1):
  b.append(abs(a[i]-a[i+1]))
  
c = int(np.min(b))

for i in a:
  if abs(i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")
 

Fixed submission:
import numpy as np
import sys
import math
from functools import reduce
import fractions as fr

def gcd(*numbers):
    return reduce(fr.gcd, numbers)

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

c = int(gcd(*a))

for i in a:
  if i - k >= 0 and (i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []

for i in range(len(a) - 1):
  b.append(abs(a[i]-a[i+1]))
  
c = np.min(b)

for i in a:
  if abs(i-k) % c == 0:
    print("POSIIBLE")
    sys.exit()
    
print("IMPOSIIBLE")
 

Fixed submission:
import numpy as np
import sys
import math
from functools import reduce
import fractions as fr

def gcd(*numbers):
    return reduce(fr.gcd, numbers)

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

c = int(gcd(*a))

for i in a:
  if i - k >= 0 and (i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sorted()

print(s[len(s)-1] - s[0])

Fixed submission:
n = int(input())
s = list(map(int,input().split()))
s.sort()

print(s[len(s)-1] - s[0])

Buggy python submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sort()

print(s[len(s)-1] - s[0])

Fixed submission:
n = int(input())
s = list(map(int,input().split()))
s.sort()

print(s[len(s)-1] - s[0])

Buggy python submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sorted

print(s[len(s)-1] - s[0])

Fixed submission:
n = int(input())
s = list(map(int,input().split()))
s.sort()

print(s[len(s)-1] - s[0])

Buggy python submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sort

print(s[len(s)-1] - s[0])

Fixed submission:
n = int(input())
s = list(map(int,input().split()))
s.sort()

print(s[len(s)-1] - s[0])
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
 if a+c==2*b:
  print(Yes)
  else:
  print(No)


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

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a+c==2*b:
  print(Yes)
else:
  print(No)

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

Buggy python submission (verdict: Runtime Error):
a,b,c=(map(int,input().split()))
print((a+c==2*b?Yes:No))


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

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
if a+c==2*b:
  print(Yes)
else:
  print(No)


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

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
if a+c==b:
  print(Yes)
else:
  print(No)


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

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split))
if a[0]+a[2]==2*a[1]:
  print(Yes)
else:
  print(No)


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

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split))
if a[0]+a[2]==2*a[1]:
  print(Yes)
  else:
  print(No)

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

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
print((a[0]+a[2]=2*a[1]?Yes:No))

Fixed submission:
a,b,c=map(int,input().split())
if a+c==2*b:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
import sys
range = xrange
input = raw_input

def find_SCC(coupl):
    SCC, S, P = [], [], []
    depth = [0] * len(coupl)
 
    stack = list(range(len(coupl)))
    while stack:
        node = stack.pop()
        if node < 0:
            d = depth[~node] - 1
            if P[-1] > d:
                SCC.append(S[d:])
                del S[d:], P[-1]
                for node in SCC[-1]:
                    depth[node] = -1
        elif depth[node] > 0:
            while P[-1] > depth[node]:
                P.pop()
        elif depth[node] == 0:
            S.append(node)
            P.append(len(S))
            depth[node] = len(S)
            stack.append(~node)
            stack += coupl[node]
    return SCC[::-1]

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1

coupl = [[] for _ in range(n)]
for _ in range(m):
  	u = inp[ii] - 1; ii += 1
    v = inp[ii] - 1; ii += 1
    coupl[u].append(v)

SCC = find_SCC(coupl)
out = [len(SCC)]
for scc in SCC:
	out.append(len(scc))
    for node in scc:
    	out.append(node + 1)
print ' '.join(str(x) for x in out)

Fixed submission:
import sys
range = xrange
input = raw_input
 
def find_SCC(coupl):
    SCC, S, P = [], [], []
    depth = [0] * len(coupl)
 
    stack = list(range(len(coupl)))
    while stack:
        node = stack.pop()
        if node < 0:
            d = depth[~node] - 1
            if P[-1] > d:
                SCC.append(S[d:])
                del S[d:], P[-1]
                for node in SCC[-1]:
                    depth[node] = -1
        elif depth[node] > 0:
            while P[-1] > depth[node]:
                P.pop()
        elif depth[node] == 0:
            S.append(node)
            P.append(len(S))
            depth[node] = len(S)
            stack.append(~node)
            stack += coupl[node]
    return SCC[::-1]
 
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
 
n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
 
coupl = [[] for _ in range(n)]
for _ in range(m):
    u = inp[ii]; ii += 1
    v = inp[ii]; ii += 1
    coupl[u].append(v)
 
SCC = find_SCC(coupl)
out = [len(SCC)]
for scc in SCC:
    out.append(len(scc))
    for node in scc:
        out.append(node)
print ' '.join(str(x) for x in out)