Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import factorial
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  if i>1:
    count+=factorial(i)/factorial(2)/factorial(i-2)
print(int(count))

Fixed submission:
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  count+=i*(i-1)/2
print(int(count))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
l=[]
count=0
for i in range(n):
  b=list(input())
  b.sort()
  l.append(b)
for i in range(n):
  for j in range(i+1,n):
    if l[i]==l[j]:
      count+=1
print(count)

Fixed submission:
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  count+=i*(i-1)/2
print(int(count))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
l=[]
count=0
for i in range(n):
  b=input()
  l.append(Counter(b))
for i in range(n):
  for j in range(i+1,n):
    if l[i]==l[j]:
      count+=1
print(count)

Fixed submission:
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  count+=i*(i-1)/2
print(int(count))
Buggy python submission (verdict: Runtime Error):
MI = lambda :(map(int,input().split()))
x = II()
if x>1799:
	print(1)
elif x>1599:
	print(2)
elif x>1399:
	print(3)
elif x>1199:
	print(4)
elif x>999:
	print(5)
elif x>799:
	print(6)
elif x>599:
	print(7)
else:
	print(8)

Fixed submission:
MI = lambda :(map(int,input().split()))
x = int(input())
if x>1799:
	print(1)
elif x>1599:
	print(2)
elif x>1399:
	print(3)
elif x>1199:
	print(4)
elif x>999:
	print(5)
elif x>799:
	print(6)
elif x>599:
	print(7)
else:
	print(8)
Buggy python submission (verdict: Runtime Error):
import sys
import math
from bisect import bisect_left
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
def bs(a,n,x): 
    i = bisect_left(a, x) 
    if i<n and a[i] == x:
    	return i
    elif i:
    	return (i-1) 
    else: 
        return -1
n,m,k = MI()
a = LI()
b = LI()
for i in range(1,n):
	a[i]+=a[i-1]
for i in range(1,m):
	b[i]+=b[i-1]
ans = max(bs(a,n,k),bs(b,m,k))+1
for i in range(n):
	if k<a[i]:
		break
	else:
		temp = i+1+bs(b,m,k-a[i])+1
		ans = max(ans,temp)
for j in range(m):
	if k<b[i]:
		break
	else:
		temp = i+1+bs(a,n,k-b[i])+1
		ans = max(ans,temp)
print(ans)



Fixed submission:
import sys
import math
from bisect import bisect_left
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
def bs(a,n,x): 
    i = bisect_left(a, x) 
    if i<n and a[i] == x:
    	return i
    elif i:
    	return (i-1) 
    else: 
        return -1
n,m,k = MI()
a = LI()
b = LI()
for i in range(1,n):
	a[i]+=a[i-1]
for i in range(1,m):
	b[i]+=b[i-1]
ans = max(bs(a,n,k),bs(b,m,k))+1
for i in range(n):
	if k<a[i]:
		break
	else:
		temp = i+1+bs(b,m,k-a[i])+1
		ans = max(ans,temp)
for i in range(m):
	if k<b[i]:
		break
	else:
		temp = i+1+bs(a,n,k-b[i])+1
		ans = max(ans,temp)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
import math
from bisect import bisect_left
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
def bs(a,n,x): 
    i = bisect_left(a, x) 
    if i<n and a[i] == x:
    	return i
    elif i:
    	return (i-1) 
    else: 
        return -1
n,m,k = MI()
a = LI()
b = LI()
for i in range(1,n):
	a[i]+=a[i-1]
for i in range(1,m):
	b[i]+=b[i-1]
ans = max(bs(a,n,k),bs(b,m,k))+1
for i in range(n):
	if k<a[i]:
		break
	else:
		temp = i+1+bs(b,m,k-a[i])+1
		ans = max(ans,temp)
for j in range(m):
	if k<b[i]:
		break
	else:
		temp = i+1+bs(a,n,k-b[i])+1
print(ans)



Fixed submission:
import sys
import math
from bisect import bisect_left
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
def bs(a,n,x): 
    i = bisect_left(a, x) 
    if i<n and a[i] == x:
    	return i
    elif i:
    	return (i-1) 
    else: 
        return -1
n,m,k = MI()
a = LI()
b = LI()
for i in range(1,n):
	a[i]+=a[i-1]
for i in range(1,m):
	b[i]+=b[i-1]
ans = max(bs(a,n,k),bs(b,m,k))+1
for i in range(n):
	if k<a[i]:
		break
	else:
		temp = i+1+bs(b,m,k-a[i])+1
		ans = max(ans,temp)
for i in range(m):
	if k<b[i]:
		break
	else:
		temp = i+1+bs(a,n,k-b[i])+1
		ans = max(ans,temp)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
s = SI()
if s.isLower():
	print("a")
else:
	print("A")

Fixed submission:
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
s = SI()
if s.islower():
	print("a")
else:
	print("A")
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
a1 = math.round(a/0.08)
b1 = math.round(b/0.1)
c = min(a1,b1)
while True:
	if math.floor(c*0.08) == a and math.floor(c*0.1) == b:
		print(c)
		break
	elif math.floor(c*0.08) != a and math.floor(c*0.1) != b:
		print(-1)
		break
	else:
		c+=1


Fixed submission:
import math
a,b = map(int,input().split())
a1 = round(a/0.08)
b1 = round(b/0.1)
c = min(a1,b1)
while True:
	if math.floor(c*0.08) == a and math.floor(c*0.1) == b:
		print(c)
		break
	elif math.floor(c*0.08) > a and math.floor(c*0.1) > b:
		print(-1)
		break
	else:
		c+=1
Buggy python submission (verdict: Time Limit Exceeded):
II = lambda: int(input())
SI = lambda: input()
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
n,k = MI()
a = LI()
d = [-1]*n
d[0] = 0
for i in range(n):
	for j in range(i,min(i+k+1,n)):
		if d[j] == -1:
			d[j] = d[i]+abs(a[i]-a[j])
		else:
			d[j] = min(d[j],d[i]+abs(a[i]-a[j]))
print(d[-1])

Fixed submission:
II = lambda: int(input())
SI = lambda: input()
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
n,k = MI()
a = LI()
d = [-1]*n
d[0] = 0
for i in range(n):
	for j in range(i,min(i+k+1,n)):
		if d[j] == -1:
			d[j] = d[i]+abs(a[i]-a[j])
		else:
			d[j] = min(d[j],d[i]+abs(a[i]-a[j]))
print(d[-1])
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
    
al = [1]
num2ind = {1:0}
for i in range(N):
    ne = A[al[-1]-1]
    if ne in al:
        tar = num2ind[ne]
        break
    al.append(ne)
    num2ind[ne] = i+1
    
ne = i+1
if K<=len(al):
    print(al[K])
else:
    K-=tar
    K%=(ne-tar)
    print(al[tar+K])


Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
    
al = [1]
num2ind = {1:0}
for i in range(K):
    ne = A[al[-1]-1]
    al.append(ne)
    if ne in num2ind:
        tar = num2ind[ne]
        break
    num2ind[ne] = i+1
    
ne = i+1
if K<=len(al):
    print(al[K])
else:
    K-=tar
    K%=(ne-tar)
    print(al[tar+K])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

cnt = 0
for org in range(N-1):
    for i in range(org+A[org],N):
        if A[org]+A[i]==i-org:
            cnt+=1
print(cnt)

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

L = {}
R_val = []
for i in range(N):
    if i+A[i] not in L:
        L[i+A[i]] = 0
    L[i+A[i]]+=1
    R_val.append(i-A[i])
    
ans = 0
for one in R_val:
    if one in L:
        ans+=L[one]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import time

N = int(input())
S = input()
start = time.time()
kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)
a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = 0
for one in kv[a1]:
    for t in kv[a2]:
        tmp = len(kv[a3])
        if 2*t-one in kv[a3]:
            tmp-=1
        if 2*one-t in kv[a3]:
            tmp-=1
        if (t+one)/2 in kv[a3]:
            tmp-=1
        ans+=tmp
print(ans)

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

kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)

a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = a[0][0]*a[1][0]*a[2][0]
set_a3 = set(kv[a3])
for one in kv[a1]:
    for t in kv[a2]:
        ans-=3-len(set([2*t-one,2*one-t,(t+one)/2])-set_a3)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)
a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = 0

for one in kv[a2]:
    for t in kv[a3]:
        tmp = len(kv[a1])
        if 2*t-one in kv[a1]:
            tmp-=1
        if 2*one-t in kv[a1]:
            tmp-=1
        if (t+one)/2 in kv[a1]:
            tmp-=1
        ans+=tmp
print(ans)

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

kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)

a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = a[0][0]*a[1][0]*a[2][0]
set_a3 = set(kv[a3])
for one in kv[a1]:
    for t in kv[a2]:
        ans-=3-len(set([2*t-one,2*one-t,(t+one)/2])-set_a3)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)

ans = 0
for one in kv['R']:
    for t in kv['G']:
        tmp = len(kv['B'])
        if 2*t-one in kv['B']:
            tmp-=1
        if 2*one-t in kv['B']:
            tmp-=1
        if (t+one)/2 in kv['B']:
            tmp-=1
        ans+=tmp
print(ans)

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

kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)

a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = a[0][0]*a[1][0]*a[2][0]
set_a3 = set(kv[a3])
for one in kv[a1]:
    for t in kv[a2]:
        ans-=3-len(set([2*t-one,2*one-t,(t+one)/2])-set_a3)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors
ans = make_divisors(N-1)
del ans[0]
cand = make_divisors(N)
del cand[0]
for one in cand:
    n = N
    while True:
        if n%one==0:
            n = N//one
        else:
            if n%one==1:
                ans.append(one)
            break
print(len(ans))

Fixed submission:
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors
ans = make_divisors(N-1)
del ans[0]
cand = make_divisors(N)
del cand[0]
for one in cand:
    n = N
    while True:
        if n%one==0:
            n = n//one
        else:
            if n%one==1:
                ans.append(one)
            break

print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ind2clus = {}
clus2ind = {}
for i in range(N):
    if A[i] not in clus2ind:
        clus2ind[A[i]]=[]
    clus2ind[A[i]].append(i)
    ind2clus[i] = A[i]
for i in range(N):
    ans = 0
    for one in clus2ind:
        if one!=ind2clus[i]:
            num = len(clus2ind[one])
        else:
            num = len(clus2ind[one])-1
        ans+=num*(num-1)//2
    print(ans)
         

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ind2clus = {}
clus2ind = {}
for i in range(N):
    if A[i] not in clus2ind:
        clus2ind[A[i]]=[]
    clus2ind[A[i]].append(i)
    ind2clus[i] = A[i]
ma = 0
for one in clus2ind:
    num = len(clus2ind[one])
    ma+=num*(num-1)//2
    
    
for i in range(N):
    num = len(clus2ind[ind2clus[i]])
    print(ma-num*(num-1)//2+(num-1)*(num-2)//2)
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))

p = {}
flag=True
for _ in range(M):
    s,c = list(map(int, input().split()))
    if s in p and p[s]!=c:
        flag=False
    p[s] = c

if flag and p[1]!=0:
    ans = ''
    for i in range(1, N+1):
        if i in p:
            ans+=str(p[i])
        else:
            ans+='0'
    print(int(ans))
else:
    print(-1)

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

p = {}
flag=True
for _ in range(M):
    s,c = list(map(int, input().split()))
    if s in p and p[s]!=c:
        flag=False
    p[s] = c

if 1 in p:
    if N!=1 and p[1]==0:
        flag=False
        
if flag:
    ans = ''
    for i in range(1, N+1):
        if i in p:
            ans+=str(p[i])
        elif N!=1 and i==1:
            ans+='1'
        else:
            ans+='0'
    print(int(ans))
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()
a = [0]*N

score = {'r':P,'s':R,'p':S}
T2 = ''
for i in range(N):
    if i+K<=N-1:
        if a[i]==0 and T[i]==T[i+K]:
            a[i+K]=1
    if a[i]==0:
        T2+=T[i]
ans = 0
for one in T2:
    ans+=score[one]
print(ans)

Fixed submission:
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()
a = [0]*N

score = {'r':P,'s':R,'p':S}
ans = 0
for i in range(N):
    if i+K<=N-1:
        if a[i]==0 and T[i]==T[i+K]:
            a[i+K]=1
    if a[i]==0:
        ans+=score[T[i]]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
dp = [0]*100000
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(200, N+1):
    if dp[i-100]==1 or dp[i-101]==1 or dp[i-102]==1 or dp[i-103]==1 or dp[i-104]==1  or dp[i-105]==1:
        dp[i]=1
print(dp[N])

Fixed submission:
N = int(input())
dp = [0]*(100000+1)
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(200, N+1):
    if dp[i-100]==1 or dp[i-101]==1 or dp[i-102]==1 or dp[i-103]==1 or dp[i-104]==1  or dp[i-105]==1:
        dp[i]=1
print(dp[N])
Buggy python submission (verdict: Runtime Error):
import math

a, b, x = list(map(int, input().split()))
if x==a*b:
    print(0)
elif x>a**2*b/2:
    print(90-math.atan(a/(2*b-2*x/a**2))*180/math.pi)
else:
    print(90-math.atan(2*x/a/b**2)*180/math.pi)

Fixed submission:
import math

a, b, x = list(map(int, input().split()))
if x==a**2*b:
    print(0)
elif x>a**2*b/2:
    print(90-math.atan(a/(2*b-2*x/a**2))*180/math.pi)
else:
    print(90-math.atan(2*x/a/b**2)*180/math.pi)

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

a, b, x = list(map(int, input().split()))
if x>a**2*b/2:
    print(90-math.atan(a/(2*b-2*x/a**2))*180/math.pi)
else:
    print(90-math.atan(2*x/a/b**2)*180/math.pi)
        

Fixed submission:
import math

a, b, x = list(map(int, input().split()))
if x==a**2*b:
    print(0)
elif x>a**2*b/2:
    print(90-math.atan(a/(2*b-2*x/a**2))*180/math.pi)
else:
    print(90-math.atan(2*x/a/b**2)*180/math.pi)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

while M>0:
    max_A = max(A)
    ind = A.index(max_A)
    A[ind] = A[ind]//2
    M = M-1
print(sum(A))

Fixed submission:
import heapq
N, M = list(map(int, input().split()))
A = [-a for a in list(map(int, input().split()))]
heapq.heapify(A)

while M>0:
    max_a = heapq.heappop(A)
    heapq.heappush(A,-int(-max_a/2))
    M = M-1
print(-sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(1, N//2+1):
    for j in range(N-2*i+1):
        #j~j+i, k~k+i(k>=j+i)
        one = S[j:j+i]
        if one in S[j+i:]:
            ans = i
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
 
def z_algo(s):
    s_length = len(s)
    l, r = 0, 1
    Z = [0]*s_length
    Z[0] = s_length
    for i in range(1, s_length):
        if r<i:
            l, r = i, i
            while r<s_length and s[r]==s[r-l]:
                r += 1
            Z[i] = r-i
            r -= 1
        else:
            k = i-l
            if i+Z[k]-1<r:
                Z[i] = Z[k]
            else:
                l = i
                while r<s_length and s[r]==s[r-l]:
                    r += 1
                Z[i] = r-i
                r -= 1
    return Z

ans = 0
for i in range(N):
    z = z_algo(S[i:])
    for j in range(i, N):
        ans = max(ans, min(j-i, z[j-i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a_list = []
max_v = -1
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]==max_v:
        max_ind.append(i)
del a_list[max_ind[-1]]
sec = max(a_list)
for i in range(N):
    if i in max_ind:
        print(sec)
    else:
        print(max_v)
        

Fixed submission:
N = int(input())
a_list = []
max_v = -1
sec = -1
tmp = 0
drop = False
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        tmp = max_v
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]<max_v:
        if a_list[-1]>sec:
            drop = True
            sec = a_list[-1]
    else:
        max_ind.append(i)
if len(max_ind)>1:
    for i in range(N):
        print(max_v)
elif drop:
    for i in range(N):
        if i in max_ind:
            print(sec)
        else:
            print(max_v)
else:
    for i in range(N):
        if i in max_ind:
            print(tmp)
        else:
            print(max_v)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
A = list(map(int, input().split()))

L = [0]*(N+1)
R = [0]*(N+1)

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

M = []
for i in range(N-1):
    M.append(math.gcd(L[i],R[i+1]))
    
print(max(M))

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

L = [0]*(N+1)
R = [0]*(N+1)

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

print(max(M))
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N

# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    dp[i] = res
    return res

ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+100)

N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N
 
# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    dp[i] = res
    return res
 
ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N

# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    return res

ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+100)

N, M = list(map(int, input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x, y = list(map(int, input().split()))
    G[x-1].append(y-1)
    
dp = [-1]*N
 
# node iを起点とした時の有効パスの最大値
def rec(i):
    if dp[i] != -1:
        return dp[i]
    res = 0
    for v in G[i]:
        res = max(res, rec(v)+1)
    dp[i] = res
    return res
 
ans = 0
for i in range(N):
    ans = max(ans, rec(i))
    
print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7

H, W = list(map(int, input().split()))
a = [input() for _ in range(H)]

dp = [[-1]*W for _ in range(H)]
def rec(h, w):
    if dp[h][w]!=-1:
        return dp[h][w]
    else:
        dp[h][w] = 0
        if h<H-1:
            if a[h+1][w]!='#':
                dp[h][w] = rec(h+1, w)%MOD
        if w<W-1:
            if a[h][w+1]!='#':
                dp[h][w] += rec(h, w+1)%MOD
        if h==H-1 and w==W-1:
            dp[h][w] = 1
        return dp[h][w]%MOD

print(rec(0,0))

Fixed submission:
import sys
sys.setrecursionlimit(10**5+100)
MOD = 10**9+7

H, W = list(map(int, input().split()))
a = [input() for _ in range(H)]

dp = [[-1]*W for _ in range(H)]
def rec(h, w):
    if dp[h][w]!=-1:
        return dp[h][w]
    else:
        dp[h][w] = 0
        if h<H-1:
            if a[h+1][w]!='#':
                dp[h][w] = rec(h+1, w)%MOD
        if w<W-1:
            if a[h][w+1]!='#':
                dp[h][w] += rec(h, w+1)%MOD
        if h==H-1 and w==W-1:
            dp[h][w] = 1
        return dp[h][w]%MOD

print(rec(0,0))
Buggy python submission (verdict: Time Limit Exceeded):
INF = 1e10

H, W = list(map(int, input().split()))
c = []
cnt = 0
for y in range(H):
    c.append(input())
    for s in c[-1]:
        if s=='.':
            cnt+=1
    
def search(syx, gyx):
    sy,sx = syx
    gy,gx = gyx
    visited = [[INF]*W for _ in range(H)]
    q = [[sy,sx]]
    visited[sy][sx]=0
    while visited[gy][gx]==INF:
        tmp_q = []
        for one in q:
            cy,cx = one
            for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                ny, nx = cy+dy, cx+dx
                if 0 <= nx < W and 0 <= ny < H and c[ny][nx] == '.' and visited[ny][nx]> visited[cy][cx]+1:
                    visited[ny][nx] = visited[cy][cx]+1
                    tmp_q.append([ny,nx])
        q = tmp_q
    return visited[gy][gx]

print(cnt-search([0,0],[H-1,W-1])-1)

Fixed submission:
INF = 1e10

H, W = list(map(int, input().split()))
c = []
cnt = 0
for y in range(H):
    c.append(input())
    for s in c[-1]:
        if s=='.':
            cnt+=1
    
def search(syx, gyx):
    sy,sx = syx
    gy,gx = gyx
    visited = [[INF]*W for _ in range(H)]
    q = [[sy,sx]]
    visited[sy][sx]=0
    while len(q)>0:
        tmp_q = []
        for one in q:
            cy,cx = one
            for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                ny, nx = cy+dy, cx+dx
                if 0 <= nx < W and 0 <= ny < H and c[ny][nx] == '.' and visited[ny][nx]> visited[cy][cx]+1:
                    visited[ny][nx] = visited[cy][cx]+1
                    tmp_q.append([ny,nx])
        q = tmp_q
        if visited[gy][gx]!=INF:
            break
    return visited[gy][gx]

ans = search([0,0],[H-1,W-1])
if ans==INF:
    print(-1)
else:
    print(cnt-ans-1)