Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M=[int(i) for i in input().split()]
a=[]
b=[]
c=[]
flag=False
for i in range(M):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
    if x==1:
        c.append(y)
for i in range(M):
    if b[i]==N:
        flag=a[i] in c

if flag==False:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Fixed submission:
N,M=[int(i) for i in input().split()]
a=[]
b=[]
c=[]
for i in range(M):
    x,y=[int(i) for i in input().split()]
    if x==1 :
        c.append(y)
    if y==N:
        c.append(x)
if len(c)==len(set(c)):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N,M=[int(i) for i in input().split()]
a=[]
b=[]
c=[]
flag=0
for i in range(M):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
    if x==1:
        c.append(y)
for i in range(M):
    if b[i]==N:
        if a[i] in c:
            flag=1
if flag==0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Fixed submission:
N,M=[int(i) for i in input().split()]
a=[]
b=[]
c=[]
for i in range(M):
    x,y=[int(i) for i in input().split()]
    if x==1 :
        c.append(y)
    if y==N:
        c.append(x)
if len(c)==len(set(c)):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[],b=[],c=[]
flag=0
for i in range(M):
    x,y=map(int,input().split())
    x.append(a)
    y.append(b)
    if x==1:
        c.append(y)
for i in range(M):
    if b[i]==N:
        if a[i] in c:
            flag+=1
if flag==0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Fixed submission:
N,M=[int(i) for i in input().split()]
a=[]
b=[]
c=[]
for i in range(M):
    x,y=[int(i) for i in input().split()]
    if x==1 :
        c.append(y)
    if y==N:
        c.append(x)
if len(c)==len(set(c)):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
a=[]
b=[]
c=[]
flag=0
for i in range(M):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
    if x==1:
        c.append(y)
for i in range(M):
    if b[i]==N:
        if a[i] in c:
            flag+=1
if flag==0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")



Fixed submission:
N,M=[int(i) for i in input().split()]
a=[]
b=[]
c=[]
for i in range(M):
    x,y=[int(i) for i in input().split()]
    if x==1 :
        c.append(y)
    if y==N:
        c.append(x)
if len(c)==len(set(c)):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
S=input()[:-1]
Q=int(input())
r = False
for _ in range(Q):
  qs = input()[:-1].split(' ')
  if len(qs) == 1:
    r = not r
  else:
    if (qs[1] == '1' and (not r)) or (qs[1] == '2' and r):
      S = qs[2] + S
    else:
      S = S + qs[2]
if r:
  print(S[::-1])
else:
  print(S)



Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
S=deque(input()[:-1])
Q=int(input())
r = False
for _ in range(Q):
  qs = input()[:-1].split(' ')
  if len(qs) == 1:
    r = not r
  else:
    if (qs[1] == '1' and (not r)) or (qs[1] == '2' and r):
      S.appendleft(qs[2])
    else:
      S.append(qs[2])
if r:
  print(''.join(reversed(S)))
else:
  print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
r = False
for _ in range(Q):
  qs = input().split(' ')
  if len(qs) == 1:
    r = not r
  else:
    if (qs[1] == '1' and (not r)) or (qs[1] == '2' and r):
      S = qs[2] + S
    else:
      S = S + qs[2]
if r:
  print(S[::-1])
else:
  print(S)



Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
S=deque(input()[:-1])
Q=int(input())
r = False
for _ in range(Q):
  qs = input()[:-1].split(' ')
  if len(qs) == 1:
    r = not r
  else:
    if (qs[1] == '1' and (not r)) or (qs[1] == '2' and r):
      S.appendleft(qs[2])
    else:
      S.append(qs[2])
if r:
  print(''.join(reversed(S)))
else:
  print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for _ in range(Q):
  qs = input().split(' ')
  if len(qs) == 1:
    S = S[::-1]
  else:
    if qs[1] == '1':
      S = qs[2] + S
    else:
      S = S + qs[2]
print(S)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
S=deque(input()[:-1])
Q=int(input())
r = False
for _ in range(Q):
  qs = input()[:-1].split(' ')
  if len(qs) == 1:
    r = not r
  else:
    if (qs[1] == '1' and (not r)) or (qs[1] == '2' and r):
      S.appendleft(qs[2])
    else:
      S.append(qs[2])
if r:
  print(''.join(reversed(S)))
else:
  print(''.join(S))
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
sc = [list(map(int, input().split())) for _ in range(m)]


ans = -1
for i in range(10**(n-1), 10**n):
    for s, c in sc:
        if str(i)[s-1] != str(c):
            break
    else:
        ans = i
        break
if n == 1:
    if m == 0 or set(sc) == {[1, 0]}:
        ans = 0
print(ans)


Fixed submission:
n, m = [int(i) for i in input().split()]
sc = [list(map(int, input().split())) for _ in range(m)]


ans = -1
for i in range(10**(n-1) if n > 1 else 0, 10**n):
    for s, c in sc:
        if str(i)[s-1] != str(c):
            break
    else:
        ans = i
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import functools

MOD = 10**9 + 7

N = int(input())
A = [int(i) for i in input().split()]


def lcm(a, b):
    gcd = fractions.gcd(a, b)
    return (a * b) // gcd


LCM = functools.reduce(lcm, A)
ans = sum([(LCM // a) % MOD for a in A]) % MOD

print(ans)


Fixed submission:
import functools
import fractions

MOD = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]

L = functools.reduce(lambda a, b: a // fractions.gcd(a, b) * b, A) % MOD
ans = 0

for a in A:
    ans += L * pow(a, MOD - 2, MOD)
    ans %= MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import functools

MOD = 10**9 + 7

N = int(input())
A = [int(i) for i in input().split()]


def lcm(a, b):
    gcd = fractions.gcd(a, b)
    return (a * b) // gcd


LCM = functools.reduce(lcm, A)
ans = sum([(LCM // a) % MOD for a in A]) % MOD

print(ans)


Fixed submission:
import functools
import fractions

MOD = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]

L = functools.reduce(lambda a, b: a // fractions.gcd(a, b) * b, A) % MOD
ans = 0

for a in A:
    ans += L * pow(a, MOD - 2, MOD)
    ans %= MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    N, A, B = [int(i) for i in input().split()]
    diff = B - A
    if diff % 2 == 0:
        ans = diff // 2
    else:
        ans = min(B - 1, N - A, (A - 1) + 1 + (diff - 1) // 2, (N - B) + 1 (diff - 1) // 2)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, A, B = [int(i) for i in input().split()]
    diff = B - A
    if diff % 2 == 0:
        ans = diff // 2
    else:
        ans = min(B - 1, N - A, (A - 1) + 1 + (diff - 1) // 2, (N - B) + 1 + (diff - 1) // 2)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N, A, B = [int(i) for i in input().split()]
    diff = B - A
    if diff % 2 == 0:
        ans = diff // 2
    else:
        ans = min(B - 1, N - A, (A - 1) + 1 + (diff - 1) // 2, (N - B) + 1 (diff - 1) // 2)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, A, B = [int(i) for i in input().split()]
    diff = B - A
    if diff % 2 == 0:
        ans = diff // 2
    else:
        ans = min(B - 1, N - A, (A - 1) + 1 + (diff - 1) // 2, (N - B) + 1 + (diff - 1) // 2)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def index(l, x, default=None):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    b = []

    ans = -1
    tmp_index = 0
    for i in range(N):
        if index(a[tmp_index:], i + 1) is None:
            break
        else:
            tmp_index = index(a[tmp_index:], i + 1)
            b.append(i + 1)

    if len(b) == 0:
        print(ans)
        return None
    for i, e in enumerate(b):
        if e != i + 1:
            break
    else:
        ans = N - len(b)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    counter = 0
    for a in A:
        if a == counter + 1:
            counter += 1
    if counter == 0:
        ans = -1
    else:
        ans = N - counter
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

MOD = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]


def main():
    ans = sum([a ^ b for (a, b) in itertools.combinations(A, 2)]) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import itertools

MOD = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]


def main():
    count_1 = [0] * 61
    for i in range(60):
        tmp = 0
        for j, a in enumerate(A):
            tmp += (a >> i) & 1
        count_1[i] += tmp
    ans = 0
    for i, c1 in enumerate(count_1):
        c0 = len(A) - c1
        ans += c0 * c1 * 2**i
    ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, d = [int(i) for i in input().split()]
n = {i for i in range(a, b+1) if i % c != 0 and i % d != 0}
ans = len(n)
print(ans)

Fixed submission:
import fractions


def anti_division(n, d1, d2):
    g = fractions.gcd(d1, d2)
    l = (d1 * d2) // g
    ret = n - (n//d1 + n//d2) + n//l
    return ret


a, b, c, d = [int(i) for i in input().split()]
ans = anti_division(b, c, d) - anti_division(a - 1, c, d)
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b, c, d = [int(i) for i in input().split()]
n = {i for i in range(a, b+1) if i % c != 0 and i % d != 0}4 9 2 3
ans = len(n)
print(ans)

Fixed submission:
import fractions


def anti_division(n, d1, d2):
    g = fractions.gcd(d1, d2)
    l = (d1 * d2) // g
    ret = n - (n//d1 + n//d2) + n//l
    return ret


a, b, c, d = [int(i) for i in input().split()]
ans = anti_division(b, c, d) - anti_division(a - 1, c, d)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

head = int(S[:2])
tail = int(s[2:])

ans = "NA"
if 1 <= head <= 12:
    if 1 <= tail <= 12:
        ans = "AMBIGUOUS"
    else:
        "YYMM"
elif 1 <= tail <= 12:
    ans = "MMYY"
    
print(ans)

Fixed submission:
S = input()

head = int(S[:2])
tail = int(S[2:])

ans = "NA"
if 1 <= head <= 12:
    if 1 <= tail <= 12:
        ans = "AMBIGUOUS"
    else:
        ans = "MMYY"
elif 1 <= tail <= 12:
    ans = "YYMM"

print(ans)
Buggy python submission (verdict: Runtime Error):
import math


n, k = [int(i) for i in input().split()]
prob = 0
for i in range(1, n + 1):
    if i >= k:
        exp = 0
    else:
        exp = math.ceil(math.log2(k) - math.log2(i))
    prob += (1 / n) * (1 / 2) ** exp
print(prob)


Fixed submission:
import math


n, k = [int(i) for i in input().split()]
prob = 0
for i in range(1, n + 1):
    if i >= k:
        exp = 0
    else:
        exp = math.ceil(math.log2(k) - math.log2(i))
    prob += (1 / n) * (1 / 2) ** exp
print(prob)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
from collections import deque

H, W = [int(i) for i in input().split()]
grid = [list(input()) for _ in range(H)]
reached = [[0] * W for _ in range(H)]

queue = deque()
for y, x in product(range(H), range(W)):
    if grid[y][x] == "#":
        queue.append((y, x, 0))

if len(queue) == H * W:
    print(0)
    exit()

ans = 0
while queue:
    y, x, steps = queue.popleft()
    if not (0 <= y < H and 0 <= x < W):
        continue
    if reached[y][x]:
        continue
    reached[y][x] = 1
    ans = max(ans, steps)
    for dy, dx in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        queue.append((y+dy, x+dx, steps+1))
print(ans)


Fixed submission:
from itertools import product
from collections import deque

H, W = [int(i) for i in input().split()]
grid = [list(input()) for _ in range(H)]
reached = [[0] * W for _ in range(H)]

queue = deque()
for y, x in product(range(H), range(W)):
    if grid[y][x] == "#":
        queue.append((y, x, 0))

if len(queue) == H * W:
    print(0)
    exit()

while queue:
    y, x, steps = queue.popleft()
    for dy, dx in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        ny, nx = y + dy, x + dx
        if not (0 <= ny < H and 0 <= nx < W):
            continue
        if reached[ny][nx]:
            continue
        reached[ny][nx] = 1
        queue.append((ny, nx, steps+1))
print(steps)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import functools


n = int(input())
a = [int(i) for i in input().split()]
ans = 0

for i in range(n):
    m = functools.reduce(fractions.gcd, a[:i] + a[i+1:])
    ans = max(ans, m)

print(ans)


Fixed submission:
import fractions
import functools


n = int(input())
a = [int(i) for i in input().split()]
ans = 0

# a_0 ~ a_i の 最大公約数
l_gcd = [0]
l_append = l_gcd.append
# a_i ~ a_n-1 の最大公約数
r_gcd = []
r_append = r_gcd.append

for i, a_i in enumerate(a):
    if i == 0:
        l_append(a_i)
    else:
        l_append(fractions.gcd(a_i, l_gcd[i]))

for i, a_i in enumerate(reversed(a)):
    if i == 0:
        r_append(a_i)
    else:
        r_append(fractions.gcd(a_i, r_gcd[i-1]))
r_gcd.reverse()
r_append(0)

m = []
m_append = m.append
for i in range(n):
    m_append(fractions.gcd(l_gcd[i], r_gcd[i+1]))
ans = max(m)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(i) for i in input().split()]
viewable = []

max_h = h[0]
for h in H:
    if h >= max_h:
        viewable.append(1)
    else:
        viewable.append(0)
    max_h = max(max_h, h)

ans = sum(viewable)
print(ans)

Fixed submission:
N = int(input())
H = [int(i) for i in input().split()]
viewable = []

max_h = H[0]
for h in H:
    if h >= max_h:
        viewable.append(1)
    else:
        viewable.append(0)
    max_h = max(max_h, h)

ans = sum(viewable)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, q = [int(i) for i in input().split()]
s = input()

count = [0] * (n + 1)
for i in range(n):
    count[i+1] += count[i]
    if s[i:i+2] == "AC":
        count[i+1] += 1
for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(count(r-1) - count(l-1))


Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()

count = [0] * (n + 1)
for i in range(n):
    count[i+1] += count[i]
    if s[i:i+2] == "AC":
        count[i+1] += 1
for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(count[r-1] - count[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
import sys


input = sys.stdin.readline

n, q = [int(i) for i in input().strip().split()]
s = input().strip()
for i in range(q):
    l, r = [int(i) for i in input().strip().split()]
    l -= 1
    substr = s[l:r]
    print(len(re.findall(r"AC", substr)))


Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()

count = [0] * (n + 1)
for i in range(n):
    count[i+1] += count[i]
    if s[i:i+2] == "AC":
        count[i+1] += 1
for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(count[r-1] - count[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re


n, q = [int(i) for i in input().split()]
s = input()
for i in range(q):
    l, r = [int(i) for i in input().split()]
    l -= 1
    substr = s[l:r]
    print(len(re.findall(r"AC", substr)))


Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()

count = [0] * (n + 1)
for i in range(n):
    count[i+1] += count[i]
    if s[i:i+2] == "AC":
        count[i+1] += 1
for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(count[r-1] - count[l-1])
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

A, B, K = [int(i) for i in input()]

count = 0
for i in range(gcd(a, b), 0, -1):
    if A % i == 0 and B % i == 0:
        count += 1
        if count == K:
            print(i)
            break


Fixed submission:
from fractions import gcd

A, B, K = [int(i) for i in input().split()]

count = 0
for i in range(gcd(A, B), 0, -1):
    if A % i == 0 and B % i == 0:
        count += 1
        if count == K:
            print(i)
            break

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

A, B, K = [int(i) for i in input()]

gcd_ = gcd(A, B)
count = 0
flg = 0
for n in range(gcd_, 0, -1):
    if flg:
        break
    if A % n == 0 and B % n == 0:
        count += 1
        if count == K:
            print(n)
            flg = 1
            break


Fixed submission:
from fractions import gcd

A, B, K = [int(i) for i in input().split()]

count = 0
for i in range(gcd(A, B), 0, -1):
    if A % i == 0 and B % i == 0:
        count += 1
        if count == K:
            print(i)
            break
Buggy python submission (verdict: Runtime Error):
h, w, _ = [int(i) for i in input()]
ans = h * w // 2
print(ans)


Fixed submission:
h, w, _ = [int(i) for i in input().split()]
ans = h * w // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, w = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for _ in range(n)]

# i番目以降の品物で、容量がjのときの価値の最大値


def value(i, j):
    # もう品物がない
    if i == n:
        ret = 0
    # 品物が入らない
    elif j < wv[i][0]:
        ret = value(i+1, j)
    # 品物を入れない場合と入れる場合
    else:
        ret = max(value(i+1, j), value(i+1, j-wv[i][0]) + wv[i][1])
    return ret


print(value(0, w))


Fixed submission:
import collections


Item = collections.namedtuple("Item", ("weight", "value"))


def main():
    N, W = [int(i) for i in input().split()]
    items = [Item(int(i), int(j))for (i, j) in [input().split() for _ in range(N)]]
    # 選択肢をn番目の品物まで、重さを最大wとしたときの価値の最大値
    dp = [[0] * (W + 1) for _ in range(N + 1)]

    # n番目の品物まで含む
    for n in range(1, N + 1):
        # 重さの最大値がw
        for w in range(W + 1):
            # n番目の品物
            item = items[n - 1]
            # 買う（＝買える）
            if w - item.weight >= 0:
                dp[n][w] = max(dp[n][w], dp[n - 1][w - item.weight] + item.value)
            # 買わない（＝買えない）場合も行う
            dp[n][w] = max(dp[n][w], dp[n - 1][w])

    ans = dp[N][W]
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import collections


MAX_N = 110
MAX_V = 100100

Item = collections.namedtuple("Item", ("weight", "value"))


def main():
    N, W = [int(i) for input().split()]
    items = [Item(int(i), int(j)) for (i, j) in [input().split() for _ in range(N)]]
    dp = [[float('inf')] * MAX_V for _ in range(MAX_N)]

    dp[0][0] = 0

    for i in range(N):
        item = items[i]
        for sum_v in range(MAX_V):
            # i番目の品物を選ぶ
            if sum_v - item.value >= 0:
                dp[i + 1][sum_v] = max(dp[i + 1][sum_v], dp[i][sum_v - item.value] + item.weight)
            dp[i + 1][sum_v] = max(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0
    for sum_v in range(MAX_V):
        if dp[N][sum_v] <= W:
            ans = sum_v

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import collections


MAX_N = 110
MAX_V = 100100

Item = collections.namedtuple("Item", ("weight", "value"))


def main():
    N, W = [int(i) for i in input().split()]
    items = [Item(int(i), int(j)) for (i, j) in [input().split() for _ in range(N)]]
    dp = [[float('inf')] * MAX_V for _ in range(MAX_N)]

    dp[0][0] = 0

    for i in range(N):
        item = items[i]
        for sum_v in range(MAX_V):
            # i番目の品物を選ぶ
            if sum_v - item.value >= 0:
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - item.value] + item.weight)
            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0
    for sum_v in range(MAX_V):
        if dp[N][sum_v] <= W:
            ans = sum_v

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2 << 30)

n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(2 << 28)

n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(2 << 28)

n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(2 << 28)

n, m = [int(i) for i in input().split()]
al = [set() for _ in range(n)]
for _ in range(m):
    x, y = [int(i) for i in input().split()]
    al[x-1].add(y-1)

dp = [-1] * n


def rec(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for nv in al[v]:
        ret = max(ret, rec(nv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(n):
    ans = max(ans, rec(v))

print(ans)