Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M= map(int, input().split())
L1, R1= map(int, input().split())
Ans = set(range(L1, R1+1))

for x in range(M-1):
    L, R = map(int, input().split())
    List = set(range(L, R+1))
    Ans = (Ans) & (List)

print(len(Ans))

Fixed submission:
A, B= map(int, input().split())
import math

if A >= 13:
    print(B)
if A >=6 and A <= 12:
    print(math.floor(B/2))
if A <= 5:
    print("0")
Buggy python submission (verdict: Time Limit Exceeded):
N, M= map(int, input().split())
L1, R1= map(int, input().split())
Ans = set(range(L1, R1+1))

for x in range(M-1):
    L, R = map(int, input().split())
    List = set(range(L, R+1))
    Ans = (Ans) & (List)

print(len(Ans))

Fixed submission:
N, M= map(int, input().split())
L1, R1= map(int, input().split())

for x in range(M-1):
    L, R = map(int, input().split())
    if L > L1:
        L1 = int(L)
    if R < R1:
        R1 = int(R)

if R1 == L1:
    print("1")
if L1 > R1:
    print("0")
if L1 < R1: 
	print(R1-L1+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= map(int, input().split())
L1, R1= map(int, input().split())
Ans = list(range(L1, R1+1))

for x in range(M-1):
    L, R = map(int, input().split())
    List = list(range(L, R+1))
    Ans = list(set(Ans) & set(List))

print(len(Ans))

Fixed submission:
N, M= map(int, input().split())
L1, R1= map(int, input().split())

for x in range(M-1):
    L, R = map(int, input().split())
    if L > L1:
        L1 = int(L)
    if R < R1:
        R1 = int(R)

if R1 == L1:
    print("1")
if L1 > R1:
    print("0")
if L1 < R1: 
	print(R1-L1+1)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

N, M  = map(int,input().split())
A = sorted(list(map(int,input().split())))
D = []

for i in range(M):
    B, C = map(int,input().split())
    D.append((B,C))

D.sort(key = lambda x:x[1],reverse = True)

cnt = 0
ans = []
for b, c in D:
    for i in range(b):
        ans.append(c)
    cnt += b
    if cnt >=N:
        break
#print(D)
#print(ans)
res = sum(A)
for i in range(len(ans)):
    if ans[i]-A[i]>0:
        res += ans[i] - A[i]
    else:
        break
print(res)

Fixed submission:
import bisect
import itertools

N, M  = map(int,input().split())
A = sorted(list(map(int,input().split())))
D = []

for i in range(M):
    B, C = map(int,input().split())
    D.append((B,C))

D.sort(key = lambda x:x[1],reverse = True)

cnt = 0
ans = []
for b, c in D:
    for i in range(b):
        ans.append(c)
    cnt += b
    if cnt >=N:
        break
#print(D)
#print(ans)
res = sum(A)
for i in range(min(N,len(ans))):
    if ans[i]-A[i]>0:
        res += ans[i] - A[i]
    else:
        break
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline

import bisect

N, M  = map(int,input().split())
A = sorted(list(map(int,input().split())))

for i in range(M):
    B, C = map(int,input().split())
    index = bisect.bisect_left(A,C)
    if B < index :
        A = [C] * (B) + A[B:]
    else:
        A = [C] * (index) + A[index:]
    A.sort()
print(sum(A))

Fixed submission:
import bisect
import itertools

N, M  = map(int,input().split())
A = sorted(list(map(int,input().split())))
D = []

for i in range(M):
    B, C = map(int,input().split())
    D.append((B,C))

D.sort(key = lambda x:x[1],reverse = True)

cnt = 0
ans = []
for b, c in D:
    for i in range(b):
        ans.append(c)
    cnt += b
    if cnt >=N:
        break
#print(D)
#print(ans)
res = sum(A)
for i in range(min(N,len(ans))):
    if ans[i]-A[i]>0:
        res += ans[i] - A[i]
    else:
        break
print(res)

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

N, M  = map(int,input().split())
A = sorted(list(map(int,input().split())))

for i in range(M):
    B, C = map(int,input().split())
    index = bisect.bisect_left(A,C)
    if B < index :
        A = [C] * (B) + A[B:]
    else:
        A = [C] * (index) + A[index:]
    A.sort()
print(sum(A))

Fixed submission:
import bisect
import itertools

N, M  = map(int,input().split())
A = sorted(list(map(int,input().split())))
D = []

for i in range(M):
    B, C = map(int,input().split())
    D.append((B,C))

D.sort(key = lambda x:x[1],reverse = True)

cnt = 0
ans = []
for b, c in D:
    for i in range(b):
        ans.append(c)
    cnt += b
    if cnt >=N:
        break
#print(D)
#print(ans)
res = sum(A)
for i in range(min(N,len(ans))):
    if ans[i]-A[i]>0:
        res += ans[i] - A[i]
    else:
        break
print(res)
Buggy python submission (verdict: Runtime Error):
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = fractions.gcd(L[i-1], A[i-1])
    R[-i-1] = fractions.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = fractions.gcd(L[i], R[i])

print(max(ans))

Fixed submission:
A, B, T = map(int, input().split())
ans = ((T + 0.5) // A ) * B
print(round(ans))
Buggy python submission (verdict: Runtime Error):
import math
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i-1])
    R[-i-1] = math.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = math.gcd(L[i], R[i])

print(max(ans))

Fixed submission:
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = fractions.gcd(L[i-1], A[i-1])
    R[-i-1] = fractions.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = fractions.gcd(L[i], R[i])

print(max(ans))

Buggy python submission (verdict: Runtime Error):
import math
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i-1])
    R[-i-1] = math.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = math. gcd(L[i], R[i])

print(max(ans))

Fixed submission:
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = fractions.gcd(L[i-1], A[i-1])
    R[-i-1] = fractions.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = fractions.gcd(L[i], R[i])

print(max(ans))

Buggy python submission (verdict: Runtime Error):
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i-1])
    R[-i-1] = math.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = math. gcd(L[i], R[i])

print(max(ans))

Fixed submission:
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = fractions.gcd(L[i-1], A[i-1])
    R[-i-1] = fractions.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = fractions.gcd(L[i], R[i])

print(max(ans))
Buggy python submission (verdict: Runtime Error):
A = input()
B = input()
C = input()
D = input()
E = input()

AA = int(A)
BB = int(B)
CC = int(C)
DD = int(D)
EE = int(E)

a = A[-1]
b = B[-1]
c = C[-1]
d = D[-1]
e = E[-1]

aa = int(a)
bb = int(b)
cc = int(c)
dd = int(d)
ee = int(e)

data = [aa ,bb, cc, dd, ee]
def func(x):
    if(x==0): return False
    else: return True
    
filtered = filter(func, data)

kk =min (filtered)
n = int(0)

if aa == 0 :
    n = n+AA
else:
    n = n+AA+10-aa
if bb == 0 :
    n = n+BB
else:
    n = n+BB+10-bb
if cc == 0 :
    n = n+CC
else:
    n = n+CC+10-cc
if dd == 0 :
    n = n+DD
else:
    n = n+DD+10-dd
if ee == 0 :
    n = n+EE
else:
    n = n+EE+10-ee
print(n+kk-10)

Fixed submission:
A = input()
B = input()
C = input()
D = input()
E = input()

AA = int(A)
BB = int(B)
CC = int(C)
DD = int(D)
EE = int(E)

a = A[-1]
b = B[-1]
c = C[-1]
d = D[-1]
e = E[-1]

aa = int(a)
bb = int(b)
cc = int(c)
dd = int(d)
ee = int(e)

data = [aa ,bb, cc, dd, ee]
def func(x):
    if(x==0): return False
    else: return True
    
filtered = filter(func, data)

if aa==bb==cc==dd==ee==0:
    kk =int(10)
else:
    kk = min (filtered)

n = int(0)

if aa == 0 :
    n = n+AA
else:
    n = n+AA+10-aa
if bb == 0 :
    n = n+BB
else:
    n = n+BB+10-bb
if cc == 0 :
    n = n+CC
else:
    n = n+CC+10-cc
if dd == 0 :
    n = n+DD
else:
    n = n+DD+10-dd
if ee == 0 :
    n = n+EE
else:
    n = n+EE+10-ee
print(n+kk-10)

Buggy python submission (verdict: Runtime Error):
E = input()

AA = int(A)
BB = int(B)
CC = int(C)
DD = int(D)
EE = int(E)

a = A[-1]
b = B[-1]
c = C[-1]
d = D[-1]
e = E[-1]

aa = int(a)
bb = int(b)
cc = int(c)
dd = int(d)
ee = int(e)

data = [aa ,bb, cc, dd, ee]
def func(x):
    if(x==0): return False
    else: return True
    
filtered = filter(func, data)

kk =min (filtered)
n = int(0)

if aa == 0 :
    n = n+AA
else:
    n = n+AA+10-aa
if bb == 0 :
    n = n+BB
else:
    n = n+BB+10-bb
if cc == 0 :
    n = n+CC
else:
    n = n+CC+10-cc
if dd == 0 :
    n = n+DD
else:
    n = n+DD+10-dd
if ee == 0 :
    n = n+EE
else:
    n = n+EE+10-ee
print(n+kk-10)

Fixed submission:
A = input()
B = input()
C = input()
D = input()
E = input()

AA = int(A)
BB = int(B)
CC = int(C)
DD = int(D)
EE = int(E)

a = A[-1]
b = B[-1]
c = C[-1]
d = D[-1]
e = E[-1]

aa = int(a)
bb = int(b)
cc = int(c)
dd = int(d)
ee = int(e)

data = [aa ,bb, cc, dd, ee]
def func(x):
    if(x==0): return False
    else: return True
    
filtered = filter(func, data)

if aa==bb==cc==dd==ee==0:
    kk =int(10)
else:
    kk = min (filtered)

n = int(0)

if aa == 0 :
    n = n+AA
else:
    n = n+AA+10-aa
if bb == 0 :
    n = n+BB
else:
    n = n+BB+10-bb
if cc == 0 :
    n = n+CC
else:
    n = n+CC+10-cc
if dd == 0 :
    n = n+DD
else:
    n = n+DD+10-dd
if ee == 0 :
    n = n+EE
else:
    n = n+EE+10-ee
print(n+kk-10)
Buggy python submission (verdict: Runtime Error):
N = int(input())
str =input()

S = str.count("R")
if S > N//2 :
    print("Yes")
else:
    print("No")

Fixed submission:
A, B, C = map(int, input().split())
if A == B == C:
    print("Yes")
else:
    print("No")

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

S = str.count("R")
if S > N//2 :
    print("Yes")
else:
    print("No")

Fixed submission:
A, B, C = map(int, input().split())
if A == B == C:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N ,Q = map(int, input().split())
S = list(input())
ans = [0]*N
jdg = S[0]
cnt = 0
for i in range(1,N):
    if jdg == "A" and S[i] == "C":
        cnt += 1
        ans[i] = cnt
        jdg[i] = S[i]
    else:
        jdg = S[i]
        ans[i] = cnt

for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r-1]-ans[l-1])

Fixed submission:
N ,Q = map(int, input().split())
S = list(input())
ans = [0]*N
jdg = S[0]
cnt = 0
for i in range(1,N):
    if jdg == "A" and S[i] == "C":
        cnt += 1
        ans[i] = cnt
        jdg = S[i]
    else:
        jdg = S[i]
        ans[i] = cnt

for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r-1]-ans[l-1])
Buggy python submission (verdict: Runtime Error):
n, a, b, c = map(int,input().split())
l = [int(input() for i in range(n))]

inf = 10**9

def dfs(cut, a, b, c):
    if cur == n:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else inf#-30は最初に選んだもの
    ret0 = dfs(cur + 1, a, b, c)#何も使わない
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10#Aに使うために合成するとして
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10#Bに使うために合成するとして
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10#Cに使うために合成するとして
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))

Fixed submission:
n, A, B, C = map(int,input().split())
l = [int(input()) for i in range(n)]

inf = 10**9

def dfs(cur, a, b, c):
    if cur == n:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else inf#-30は最初に選んだもの
    ret0 = dfs(cur + 1, a, b, c)#何も使わない
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10#Aに使うために合成するとして
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10#Bに使うために合成するとして
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10#Cに使うために合成するとして
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))
Buggy python submission (verdict: Runtime Error):
N = int(input())

A = [0] * (N + 1)
B = [0] * (N + 1)
C = [0] * (N + 1)

for i in range(1, N + 1):
    A[i], B[i], C[i] = map(int, input().split())

dp = [[0] * 3 for _ in range(N + 1)]#N+1
for i in range(1, N + 1):
    dp[i][0] = A[i] + max(dp[i-1][1], dp[i-1][2])#dp[i][0]=i日目でaを選んだ時の最大値＝i-1日目でbかcを選んだ時の最大値+ai
    dp[i][1] = B[i] + max(dp[i-1][2], dp[i-1][0])
    dp[i][2] = C[i] + max(dp[i-1][0], dp[i-1][1])

print(max(dp[N]))#Nの時の最大

Fixed submission:
#　最小値を求めるDP　
#　Atcoder DP まとめコンテスト「A.Frog」　https://atcoder.jp/contests/dp/tasks/dp_a

N = int(input())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0]) #　1、２の初期値を設定

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(2, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
N, K  = map(int, input().split())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(1, N):
    for k in range(1, K+1):
        if i-k <0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k])) 

print(dp[N - 1])

Fixed submission:
#　最小値を求めるDP　
#　Atcoder DP まとめコンテスト「A.Frog」　https://atcoder.jp/contests/dp/tasks/dp_a

N = int(input())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0]) #　1、２の初期値を設定

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(2, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
h = [int(x) for x in input().split()]

inf = float("inf")
dp = [inf] * N

dp[0] = 0
dp[1] = h[1] - h[0]
for i in range(2 , N):
    dp[i] = min(abs(h[i] - h[i - 2]) + dp[i - 2], abs(h[i - 1] - h[i]) + dp[i - 1])
#print(dp)
print(dp[N])

Fixed submission:
#　最小値を求めるDP　
#　Atcoder DP まとめコンテスト「A.Frog」　https://atcoder.jp/contests/dp/tasks/dp_a

N = int(input())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0]) #　1、２の初期値を設定

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(2, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K  = map(int, input().split())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(1, N):
    for k in range(1, K+1):
        if i-k <0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k])) 

print(dp[N - 1])

Fixed submission:
N, K  = map(int, input().split())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(1, N):
    for k in range(1, K+1):
        if i-k <0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k])) 

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

w = [0] * (N + 1)
v = [0] * (N + 1)

for i in range(1, N + 1):
    w[i], v[i] = map(int, input().split())
    
MAX_W = 1000000
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for weight in range(1, W + 1):
        if weight - w[i] >= 0:#入れられる可能性があるかどうか
            dp[i][weight] = max(dp[i][weight], dp[i - 1][weight-w[i]] + v[i])#ある場合は、直前まででLimitがweight-w[i]の最大値と比較
#dp[i][weight] = i-1番目までの品から重さがweight以下になるように選んだ時の価値の最大値
        dp[i][weight] = max(dp[i-1][weight], dp[i][weight])

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())

w = [0] * (N + 1)
v = [0] * (N + 1)

for i in range(1, N + 1):
    w[i], v[i] = map(int, input().split())
    
MAX_W = 1000000
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for weight in range(1, W + 1):
        if weight - w[i] >= 0:#入れられる可能性があるかどうか
            dp[i][weight] = max(dp[i][weight], dp[i - 1][weight-w[i]] + v[i])#ある場合は、直前まででLimitがweight-w[i]の最大値と比較
#dp[i][weight] = i-1番目までの品から重さがweight以下になるように選んだ時の価値の最大値
        dp[i][weight] = max(dp[i-1][weight], dp[i][weight])

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
def lcs(S,T):
    m = len(S)
    n = len(T)
    dp = [[0]*(n+1) for x in range(m+1)]
    
#計算量はO(MN)、DP表の作成
    for i in range(m):
        for j in range(n):
            if S[i] == T[j]:#同じやったときは+1延ばし斜めに移動
                dp[i+1][j+1] = dp[i][j] + 1
            else:#違うかったら、最長は上と左の大きいほうをもってくる
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
# if I want to know the length of the Lcs, return dp[m][n]
#文字列の復元（複数の場合は、そのうちの一つ）
    ans = ''
    while m!=0 and n!=0:#どっちも0になるまで、後ろから復元
        if dp[m][n] == dp[m-1][n]:#dp表を上に動かす
            m-=1
        elif dp[m][n] == dp[m][n-1]:#dp表を左に動かす
            n-=1
        else:#斜めの移動(S[i]==T[j])のときだけ、LCS伸びているので延ばす
            m-=1
            n-=1
            ans=S[m]+ans#これはT[n]でもいい
    return ans
#----------------------------------------------------------------
S = input()
T = input()
print(lcs(S,T))

Fixed submission:
def lcs(S,T):
    m = len(S)
    n = len(T)
    dp = [[0]*(n+1) for x in range(m+1)]
    
#計算量はO(MN)、DP表の作成
    for i in range(m):
        for j in range(n):
            if S[i] == T[j]:#同じやったときは+1延ばし斜めに移動
                dp[i+1][j+1] = dp[i][j] + 1
            else:#違うかったら、最長は上と左の大きいほうをもってくる
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
# if I want to know the length of the Lcs, return dp[m][n]
#文字列の復元（複数の場合は、そのうちの一つ）
    ans = ''
    while m!=0 and n!=0:#どっちも0になるまで、後ろから復元
        if dp[m][n] == dp[m-1][n]:#dp表を上に動かす
            m-=1
        elif dp[m][n] == dp[m][n-1]:#dp表を左に動かす
            n-=1
        else:#斜めの移動(S[i]==T[j])のときだけ、LCS伸びているので延ばす
            m-=1
            n-=1
            ans=S[m]+ans#これはT[n]でもいい
    return ans
#----------------------------------------------------------------
S = input()
T = input()
print(lcs(S,T))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def f(x):#dpは
    if dp[x]!=-1:
        return dp[x]#すでに値が決まっていたらそれをかえす
    ans=0
    for e in d[x]:#すべての枝について
        ans=max(ans,1+f(e))
    dp[x]=ans
    return ans

n,m = list(map(int, input().split()))
d = {}
dp = [[-1] for i in range(n+1)]#初期値を全て-1に設定
    
for _ in range(m):
    a,b = list(map(int, input().split()))
    d[a].append(b)#有向グラフ
    
ans=0
for i in range(1,n+1):
    ans=max(ans,f(i))
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def f(x):#dpは
    if dp[x]!=-1:
        return dp[x]#すでに値が決まっていたらそれをかえす
    ans=0
    for e in d[x]:#すべての枝について
        ans=max(ans,1+f(e))
    dp[x]=ans
    return ans

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

d={}
dp=[-1]
for i in range(1,n+1):
    d[i]=[]#dは初期値を[]
    dp.append(-1)#dpは初期値-1

for _ in range(m):
    a,b = map(int, input().split())
    d[a].append(b)#有向グラフをdictで
    
ans=0
for i in range(1,n+1):
    ans=max(ans,f(i))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A = [0]
dp = [[0] * (N+1) for _ in range(N+1)]

#半開区間で考える⇒[i,j)での最適解
for w in range(1,N+1):#区間の残り数
    for l in range(N):# 左端
        r = l + w#右端
        if r > N:
            continue
        elif (N-k) % 2 == 0:#太郎
            #print(i,x)
            dp[l][x] = max(dp[l+1][x] + A[l], dp[l][r-1] + A[r-1])
        elif (N-k) % 2 == 1:#次郎
            #print(i,x)
            dp[l][x] = min(dp[l+1][x] - A[l], dp[l][r-1] - A[r-1])
            
print(dp)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A = A
dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N+1):
    dp[i][i] = 0

for k in range(1,N+1):#区間の残り数
    for i in range(N):#左端
        x = i+k#右端
        if x > N:
            continue
        elif (N-k) % 2 == 0:#太郎
            #print(i,x)
            dp[i][x] = max(dp[i+1][x] + A[i], dp[i][x-1] + A[x-1])
        elif (N-k) % 2 == 1:#次郎
            #print(i,x)
            dp[i][x] = min(dp[i+1][x] - A[i], dp[i][x-1] - A[x-1])
            
print(dp[0][N])
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N=1:
  print("Hello World")
else:
  a=int(input())
  b=int(input())
  print(a+b)

Fixed submission:
N=int(input())
if N==1:
  print("Hello World")
else:
  a=int(input())
  b=int(input())
  print(a+b)
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split())
if a*b % 2 =1:
  print("Odd")
else:
  print("Even")

Fixed submission:
a, b = map(int,input().split())
if a*b % 2 == 1:
  print("Odd")
else:
  print("Even")

Buggy python submission (verdict: Runtime Error):
a,b = int(input())
if a*b % 2 = 1:
  print("Odd")
else:
  print("Even")



Fixed submission:
a, b = map(int,input().split())
if a*b % 2 == 1:
  print("Odd")
else:
  print("Even")
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(n.count("1"))

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
n = int(input())
print(n , count("1"))

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
a, b, c,= map(int, input().split())
n = 0
if a = 1:
  n = n + 1
elif b = 1:
  n = n + 1
elif c = 1:
  n = n + 1
print(n)

  

Fixed submission:
print(input().count("1"))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(input()) for i in range(N)]

ans = set()
     
for x in L:
    if L.count(x) % 2 == 1:
        ans.add(x)

print(len(ans))

Fixed submission:
import collections

N = int(input())
L = [int(input()) for i in range(N)]

M = collections.Counter(L)
C = M.most_common()
cnt = 0

for x in C:
    if x[1] % 2 == 1:
        cnt += 1
        
print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [0] * (100000+1)
for i in range(N):
    a = int(input())
    L[a] = L[a]+1
cnt = 0
for x in L:
    if x %2 == 1:
        cnt += 1
print(cnt)

Fixed submission:
import collections

N = int(input())
L = [int(input()) for i in range(N)]

M = collections.Counter(L)
C = M.most_common()
cnt = 0

for x in C:
    if x[1] % 2 == 1:
        cnt += 1
        
print(cnt)
Buggy python submission (verdict: Runtime Error):
N, P = map(int,input().split())
A = list(map(int,input().split()))
even = 0
odd = 0

for i in A:
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
#print(even,odd)

import math
def Perm(n, r):
    return math.factorial(n)//math.factorial(n-r)
def comb(n, r):
    return Perm(n, r)//math.factorial(r)

#print("0,0 = ", comb(0,0))

if P == 0:
    ans = 0
    for x in range(odd+2):
        #print(odd, x)
        if x % 2 == 0:
            ans += comb(odd,x)
    ans *= 2**even
    print(ans)
else:
    ans = 0
    for x in range(odd+1):
        if x % 2 == 1:
            if odd != 0:
                ans += comb(odd,x)
    ans *= 2**even
    print(ans)

Fixed submission:
N, P = map(int,input().split())
A = list(map(int,input().split()))
even = 0
odd = 0

for i in A:
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
#print(even,odd)

import math
def Perm(n, r):
    return math.factorial(n)//math.factorial(n-r)
def comb(n, r):
    return Perm(n, r)//math.factorial(r)

#print("0,0 = ", comb(0,0))

if P == 0:
    ans = 0
    for x in range(odd+1):
        #print(odd, x)
        if x % 2 == 0:
            ans += comb(odd,x)
    ans *= 2**even
    print(ans)
else:
    ans = 0
    for x in range(odd+1):
        if x % 2 == 1:
            if odd != 0:
                ans += comb(odd,x)
    ans *= 2**even
    print(ans)