Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
sys.setrecursionlimit(10**8)
(n,m),*xy = [list(map(int,r.split())) for r in open(0)]
g = [[] for _ in range(n)]
dp = [0 for _ in range(n)]

for i in xy:
    x,y = i[0],i[1]
    x -= 1
    y -= 1
    g[y].append(x)

def rec(node):
    if dp[node] > 0:
        return dp[node]
    
    if not g[node]:
        dp[node] = 0
        return 0

    for child in g[node]:
        dp[node] = max(dp[node], rec(child) + 1)

    return dp[node]

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


Fixed submission:
import sys
sys.setrecursionlimit(10**8)
(n,m),*xy = [list(map(int,r.split())) for r in open(0)]
g = [[] for _ in range(n)]
dp = [0 for _ in range(n)]

for i in xy:
    x,y = i[0],i[1]
    x -= 1
    y -= 1
    g[y].append(x)

def rec(node):
    if dp[node] > 0:
        return dp[node]
    
    if not g[node]:
        dp[node] = 0
        return 0

    for child in g[node]:
        dp[node] = max(dp[node], rec(child) + 1)

    return dp[node]

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

Buggy python submission (verdict: Runtime Error):
(n,m),*xy = [list(map(int,r.split())) for r in open(0)]
g = [[] for _ in range(n)]
dp = [0 for _ in range(n)]

for i in xy:
    x,y = i[0],i[1]
    x -= 1
    y -= 1
    g[y].append(x)

def rec(node):
    if dp[node] > 0:
        return dp[node]
    
    if not g[node]:
        dp[node] = 0
        return 0

    for child in g[node]:
        dp[node] = max(dp[node], rec(child) + 1)

    return dp[node]

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


Fixed submission:
import sys
sys.setrecursionlimit(10**8)
(n,m),*xy = [list(map(int,r.split())) for r in open(0)]
g = [[] for _ in range(n)]
dp = [0 for _ in range(n)]

for i in xy:
    x,y = i[0],i[1]
    x -= 1
    y -= 1
    g[y].append(x)

def rec(node):
    if dp[node] > 0:
        return dp[node]
    
    if not g[node]:
        dp[node] = 0
        return 0

    for child in g[node]:
        dp[node] = max(dp[node], rec(child) + 1)

    return dp[node]

ans = 0
for i in range(n):
    ans = max(ans, rec(i))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
z = [list(map(int,input().split())) for _ in range(n)]

def set_height(i,x,y):
	ans = z[i][2] + abs(z[i][0] - x) + abs(z[i][1] - y)
	return ans


answer = 0
for j in range(0,101):
	for k in range(0,101):
		answer=set_height(0,j,k)
		flag = 1
		for l in range(1,n):
			if answer!= set_height(l,j,k):
				flag = 0
				break
		if flag == 1 && answer <= 10**9:
			test = map(str,(j,k,answer))
			print(" ".join(test))


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


def set_height(i,x,y):
	ans = z[i][2] + abs(z[i][0] - x) + abs(z[i][1] - y)
	return ans


answer = 0
for j in range(0,101):
	for k in range(0,101):
		flag = 1
		for l in range(0,n):
			if z[l][2] != 0:
				answer = set_height(l,j,k)
				break

		for l in range(0,n):
			if z[l][2] == 0:
				if answer > set_height(l,j,k):	
					flag = 0
					break
			else:
				if answer != set_height(l,j,k):
					flag = 0
					break
		if flag == 1 and answer > 0 :
			test = map(str,(j,k,answer))
			print(" ".join(test))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
k = m//n
while k > 0:
	if m%k == 0:
		print(k)	
		break
	k -= 1 


Fixed submission:
n,m = map(int,input().split())
k = m//n
ans = 1
i = 1
while i**2 <= m:
	if m%i==0:
		j = m//i
		if j <= k:
			print(j);exit()
		if i <= k:
			ans = max(ans,i)
	i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ans = 1
for i in range(1,m):
	if m%i == 0 and m/i >= n:
		ans = i
	if m/i < n:
		break 
print(ans)


Fixed submission:
n,m = map(int,input().split())
k = m//n
ans = 1
i = 1
while i**2 <= m:
	if m%i==0:
		j = m//i
		if j <= k:
			print(j);exit()
		if i <= k:
			ans = max(ans,i)
	i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())
n = len(s)

a = []
for i in range(n):
    for j in range(i,n):
        a.append(s[i:j+1])
b = sorted(set(a))
print(b[k-1])


Fixed submission:
s = input()
k = int(input())
n = len(s)

a = []
for i in range(n):
    for j in range(i+1,n+1):
        if j - i > k:break
        a.append(s[i:j])
b = sorted(set(a))
print(b[k-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
sn = list(input() for i in range(n))
m = int(input())
mn = list(input() for i in range(m))

for i in range(len(sn)):
  ss.append(sn.count(sn[i])-mn.count(sn[i]))

print (max(ss),0)

Fixed submission:
n = int(input())
sn = list(input() for i in range(n))
m = int(input())
mn = list(input() for i in range(m))
ss = []
for i in range(len(sn)):
  ss.append(sn.count(sn[i])-mn.count(sn[i]))
print (max(max(ss),0))
Buggy python submission (verdict: Runtime Error):
print(len(set[(int(input()) for i in range(int(input()))])))

Fixed submission:
print(input().replace('2017','2018'))

Buggy python submission (verdict: Runtime Error):
print(len(set(int(input()) for i in range(int(input())))))

Fixed submission:
print(input().replace('2017','2018'))
Buggy python submission (verdict: Runtime Error):
n,Y = map(int,input().split())
y2 = Y // 1000
for a in range(n+1):
    y = y2
    rest = y - a * 10
    if rest < 0:break
    for b in range(n+1-a):
        rest -b * 5 < 0: break
        if n - a - b == rest - b * 5:
            print(a,b,n-a-b);exit()
print(-1,-1,-1)


Fixed submission:
n,Y = map(int,input().split())
y2 = Y // 1000
for a in range(n+1):
    y = y2
    rest = y - a * 10
    if rest < 0:break
    for b in range(n+1-a):
        if rest -b * 5 < 0: break
        if n - a - b == rest - b * 5:
            print(a,b,n-a-b);exit()
print(-1,-1,-1)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
ansum = 0
def stat(array,par):
    return bisect.bisect_right(array,par)

for A in a:
    index = stat(b,A)
    for B in b[index:]:
        indexC = stat(c,B)
        ansum += max(0,n-indexC)
print(ansum)


Fixed submission:
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
d = [-1] * n
ansum = 0
def stat(array,par):
    return bisect.bisect(array,par)

for i in range(n):
    indexC = stat(c,b[i])
    d[i] = max(0,n-indexC) 
for i in range(n-1):
    d[n-i-2] += d[n-i-1]
for A in a:
    index = stat(b,A)
    if index < n:
        ansum += d[index]
print(ansum)
Buggy python submission (verdict: Runtime Error):
n = int(input())
*a, = map(int,input().split())
c = [0 for _ in range(10**5+1)]
for A in a:
    c[A] += 1
ans = 0
l = len(c)
for i in range(l):
    z = c[i]

    if 0 <= i - 1 <l:
        z += c[i-1]

    if 0 <= i+1 <l:
        z += c[i+1]

    ans = max(ans, z)
print(ans)


Fixed submission:
MOD = 10**9+7
n = int(input())
s = input()
p = input()
ans = 0
f = 0
i = 0
while i < n:
    if i > n:break
    if s[i] == p[i]:
        if i == 0:
            ans = 3
        else:
            if f == 1:
                ans *= 1
            else:
                ans *= 2
        f = 0
    else:
        if i == 0:
            ans = 6
        else:
            if f == 1:
                ans *= 3
            else:
                ans *= 2
        f = 1
        i += 1
    i += 1
    ans %= MOD
print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
O = input()
E = input()
s = ''
for i in range(len(O)):
  s+=O[i]
  s+=E[i]
print(s)

Fixed submission:
a,b,c = map(int,input().split())
print('YES' if b-a == c-b else 'NO')
Buggy python submission (verdict: Runtime Error):
O = input()
E = input()
s = ''
for i in range(len(O)):
  s+=O[i]
  s+=E[i]
print(s)

Fixed submission:
O = input()
E = input()
s = ''
for i in range(len(E)):
  s+=O[i]
  s+=E[i]
if (len(O) != len(E)):
  s+=O[-1]
print(s)
Buggy python submission (verdict: Runtime Error):
i = list(map(int, input().split()))
if i[0] == 7:
  if i[1] == 5 and i[2] ==5:
    print('YES')
  else:
    print('NO')
elif i[0] == 5:
  if (i[1] == 7 and i[2] == 5) or (i[2] == 7 and i[1] == 5):
    print('YES')
  else:
    print('NO')
else:
  print('NO')

Fixed submission:
i = list(map(int, input().split()))
if i[0] == 7:
  if i[1] == 5 and i[2] ==5:
    print('YES')
  else:
    print('NO')
elif i[0] == 5:
  if (i[1] == 7 and i[2] == 5) or (i[2] == 7 and i[1] == 5):
    print('YES')
  else:
    print('NO')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import math


temp = 0
K = int(input())
sum = 0
for A in range(1,K+1):
    for B in range(1,K+1):
        for C in range(1,K+1):
            if ((A == B) and (A == C)):
                sum = sum + A
            elif((B == C) and ( A != C)):
                temp = math.gcd(A,B)
                sum = sum + (3 * math.gcd(temp,C))
            elif(((A == B) and (A != C)) or ((A == C) and (A != B))):
                sum = sum + 0
            else:
                temp = math.gcd(A,B)
                sum = sum + math.gcd(temp,C)
print(sum)



Fixed submission:
import math


temp = 0
K = int(input())
sum = 0
for A in range(1,K+1):
    for B in range(1,K+1):
        temp = math.gcd(A,B)
        for C in range(1,K+1):
            sum = sum + math.gcd(temp,C)
print(sum)

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

def gcd(A,B,C):
    output = 1
    mini = min(A,B,C)
    for i in range(mini + 1,1,-1):
        if ((A%i == 0) and (B%i == 0) and (C%i == 0)):
            output = i
            break
    return output

K = int(input())
sum = 0
for A in range(1,K+1):
    for B in range(1,K+1):
        for C in range(1,K+1):
            if ((A == B) and (A == C)):
                sum = sum + A
            elif((B == C) and ( A != C)):
                sum = sum + (3 * gcd(A,B,C))
            elif(((A == B) and (A != C)) or ((A == C) and (A != B))):
                sum = sum + 0
            else:
                sum = sum + gcd(A,B,C)
print(sum)



Fixed submission:
import math


temp = 0
K = int(input())
sum = 0
for A in range(1,K+1):
    for B in range(1,K+1):
        temp = math.gcd(A,B)
        for C in range(1,K+1):
            sum = sum + math.gcd(temp,C)
print(sum)
Buggy python submission (verdict: Runtime Error):
a = input()
first = True
A = ""
B = ""
for i in range(len(a)):
    if a[i] != " " and first:
        A = A + a[i]
    else:
        first = False
        B = B + a[i]
A = int(A)
B = int(B)
count = 0
if B > A:
    while B > 0:
        B = B - A
        count = count + 1
print(count)


Fixed submission:
S = input()
R = input()
count = 0
for i in range(3):
  if S[i] == R[i]:
    count = count + 1
print(count)

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
A = int(a)
B = int(b)
count = 0
while B > 0:
    B = B - A
    count = count + 1
print(count)


Fixed submission:
S = input()
R = input()
count = 0
for i in range(3):
  if S[i] == R[i]:
    count = count + 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = tuple(map(int, input().split()))
ans = 1
for a in A:
    ans *=a
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
A = tuple(map(int, input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
for a in A:
    ans *=a
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int ,input().split())
A = tuple(map(int, input().split()))
seen = [-1]*n
tmp = 0
count = 0

while True:
    tmp = A[tmp]-1
    count +=1
    if seen[tmp] != -1:
        seennum = seen.count(1)

        tm = tmp
        se = [-1]*n
        roopmem = []
        while True:

            if se[tm] != -1:
                roop = se.count(1)
                break
            else:
                roopmem.append(tm)
                se[tm] = 1
                tm = A[tm] - 1

        break
    else:
        seen[tmp] = 1

if k<=n:
    no = 0
    for i in range(k):
        no = A[no]-1
    print(no+1)
else:
    tmp = k-seennum
    tmp %= roop
    print(roopmem[tmp-1]+1)


Fixed submission:
s = input()
t = input()
for i in range(len(s)):
    if s[i] != t[i]:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
from collections import deque
import copy
def lis(A: list):
    L = [A[0]]
    for a in A[1:]:
        if a > L[-1]:
            # Lの末尾よりaが大きければ増加部分列を延長できる
            L.append(a)
        else:
            # そうでなければ、「aより小さい最大要素の次」をaにする
            # 該当位置は、二分探索で特定できる
            L[bisect_left(L, a)] = a
    return len(L)
n = int(input())
a = tuple(map(int, input().split()))
G = [[] for _ in range(n+1)]
for i in range(n-1):
    u,v = map(int, input().split())
    G[u].append(v)
    G[v].append(u)

letu = [[] for _ in range(n+1)]
letu[1].append(1)
que = deque([1])

while que:
    q = que.popleft()

    for nq in G[q]:
        let = copy.deepcopy(letu[q])
        if letu[nq] != []: #seen配列としても使う。seenないと閉路でWA
            continue
        let = let + [nq]
        letu[nq] = let
        que.append(nq)
for j in range(1,n+1):
    tmp = [a[aa-1] for aa in letu[j]]
    print(lis(tmp))


Fixed submission:
k = int(input())
a,b = map(int, input().split())
for i in range(a,b+1):
    if i%k == 0:
        print('OK')
        exit()
print('NG')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = tuple(input())
ans = 0
anset = set()
for i in range(n):
    a = S[i]
    for j in range(i):
        b = S[j]
        if a == b:
            continue
        else:
            for d in ['R','G','B']:
                if d ==a or d == b:
                    continue
                else:
                    c = d
            ans += S.count(c)
            if (2*j-i)<0 :
                pass
            elif S[2*j-i] == c :
                ans -=1
            if (2 * i - j) >= n:
                pass
            elif S[2*i-j] ==c:
                ans -=1
            if (i+j)%2 == 0:
                if S[(i+j)//2] == c:
                    ans -=1
ans /=3
print(int(ans))

Fixed submission:
n = int(input())
S = tuple(input())
ans = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
for i in range(n):
    a = S[i]
    for j in range(i):
        b = S[j]
        if a == b:
            continue
        else:
            for d in ['R','G','B']:
                if d ==a or d == b:
                    continue
                else:
                    c = d
            if c == 'R':
                ans+=R
            elif c =='G':
                ans+=G
            else:
                ans+=B
            if (2*j-i)<0 :
                pass
            elif S[2*j-i] == c :
                ans -=1
            if (2 * i - j) >= n:
                pass
            elif S[2*i-j] ==c:
                ans -=1
            if (i+j)%2 == 0:
                if S[(i+j)//2] == c:
                    ans -=1
ans /=3
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    xxx = input()
    if len(xxx) == 1:
        s = s[::-1]
    else:
        T,F,C=xxx.split()
        F = int(F)
        T = int(T)
        if T == 1:
            s = s[::-1]
        else:
            if F == 1:
                s = C+s
            else:
                s = s+C
print(s)


Fixed submission:
s = input()
q = int(input())
adv = ''
bac = ''
Flag = True
for i in range(q):
    xxx = input()
    if len(xxx) == 1:
        if Flag == True:
            Flag = False
        else:
            Flag = True
    else:#T=2
        T,F,C=xxx.split()
        F = int(F)
        if F == 1:
            if Flag == True:
                adv +=C
            else:
                bac +=C
        else:#F=2
            if Flag == True:
                bac +=C
            else:
                adv +=C
if Flag == True:
    s = adv[::-1] + s + bac
    print(s)
else:
    s = bac[::-1] + s[::-1] + adv
    print(s)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline())
p =list(map(int, sys.stdin.readline().split()))
cnt = 0
for i in range(n):
    if min(p[:i+1]) == p[i]:
        cnt+=1
print(cnt)

Fixed submission:
n,m = map(int, input().split())
if n==m:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N  = int(input())
testimony = [[]for i in range(N)]
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1,state])#3次元配列の作り方
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if(i>>j)&1 == 1:
            for x,y in testimony[j]:#3次元リストからx,yを取り出す書きかた　覚える
                if (i>>x)&1 != y: #正直といっているがそうではない　と　嘘つきといっているがそうではない　の二つ同時
                    flag =1
                    break
    if flag == 0:
        honest = max(honest, bin(i)[2:].count('1'))# bin()で二進数に変換　最初の二文字は0bで取り除く count('1')で数える
print(honest)


Fixed submission:
a = list(map(int, input().split()))
if sum(a) > 21:
    print('bust')
else:
    print('win')
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
print(math.ceil((b - 1) / (a - 1)))


Fixed submission:
s = input()
t = input()
cnt = 0
for i in range(3):
    if s[i] == t[i]:
        cnt +=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
print(math.ceil((b - 1) / (a - 1)))


Fixed submission:
s = input()
t = input()
cnt = 0
for i in range(3):
    if s[i] == t[i]:
        cnt +=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
import math
a,b =map(int, input().split())
print(math.ceil((b-1)/(a-1)))


Fixed submission:
s = input()
t = input()
cnt = 0
for i in range(3):
    if s[i] == t[i]:
        cnt +=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(300000) #上限上げないと引っかかる
n,q = map(int, sys.stdin.readline().rstrip().split())
sco = [0]*(n+1)
G =[[] for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int, sys.stdin.readline().rstrip().split())
    G[a].append(b)
    G[b].append(a)

for j in range(q):
    p,x = map(int, sys.stdin.readline().rstrip().split())
    sco[p]+=x


#本体
seen = [False for _ in range(n+1)]
def dfs(G,V,score):
    global sco
    sco[V] +=score

    seen[V] = True
    for next_V in G[V]:
        if (seen[next_V]):
            continue
        dfs(G, next_V,sco[V])

#入力受け取り
#例
dfs(G,1,0)
print(*sco[1:])
#単にdfs(G,0)だと、木構造でないとき(頂点1つでない時)不正解


Fixed submission:
a = int(input())
s = input()
print(s if a>=3200 else 'red')

Buggy python submission (verdict: Runtime Error):
a,s = map(int, open(0).read().split())
print(s if a>=3200 else 'red')

Fixed submission:
a = int(input())
s = input()
print(s if a>=3200 else 'red')
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(300000) #上限上げないと引っかかる
N = int(input())
tree = [[] for _ in range(N)]
for e in sys.stdin.read().rstrip():
    x,y,dist = e.split()
    x = int(x);y=int(y);dist= int(dist)
    x -=1
    y -=1
    if dist%2 == 0:
        tree[x].append(y)
        tree[y].append(x)#偶数の場合のみ処理




color = [-1]*N
#本体
def dfs(G,V,cur):
    color[V] = cur
    for next_V in G[V]:
        if (color[next_V] != -1):
            continue#これ入れないとスタックオーバーフロー　すでに行ったところはもう調べない
        dfs(G,next_V, cur)
    return True

for i in range(N):
    dfs(tree, 0, 0)
for j in range(N):
    print(color[j])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
G = [[] for _ in range(n+1)]
for i in range(n-1):
    v,w,dist = map(int, input().split())
    G[v].append((w,dist))
    G[w].append((v,dist))
color = [-1]*(n+1)


def dfs(a, col):
    tmp = -1
    if color[a] == -1:
        color[a] = col

    for next_V,dis in G[a]:
        if color[next_V] == -1:
            tmp = col
            if dis%2 !=0:
                tmp = 1-col
            dfs(next_V, tmp)
dfs(1,0)
[print(color[i]) for i in range(1,n+1)]
Buggy python submission (verdict: Time Limit Exceeded):
max_V = 100010
N,W = map(int, input().split())
lis = [[float('inf')] *(max_V) for _ in range(N+1)]
lis[0][0] = 0 #初期条件の入力が必要　Edu_Dでは初期化とともに初期条件入力済んでいたがこれは違う
item = []
for i in range(N):
    w,v = map(int, input().split())
    item.append((w,v))
for i in range(1,N+1):
    for j in range(max_V):
        lis[i][j] = min(lis[i-1][j], (lis[i-1][j-item[i-1][1]] + item[i-1][0]))
ans = 0
for i in range(N+1):
    for j in range(max_V):
        if lis[i][j] <= W:
            ans = max(j, ans)
print(ans)


Fixed submission:
max_V = 100010
N,W = map(int, input().split())
lis = [[float('inf')] *(max_V) for _ in range(N+1)]
lis[0][0] = 0 #初期条件の入力が必要　Edu_Dでは初期化とともに初期条件入力済んでいたがこれは違う
item = []
for i in range(N):
    w,v = map(int, input().split())
    item.append((w,v))
for i in range(1,N+1):
    for j in range(max_V):
        lis[i][j] = min(lis[i-1][j], (lis[i-1][j-item[i-1][1]] + item[i-1][0]))
ans = 0
for i in range(N+1):
    for j in range(max_V):
        if lis[i][j] <= W:
            ans = max(j, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
def dfs(s):
    if int(s)>n:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for i in '753':
        res += dfs(s+i)
dfs('0')


Fixed submission:
n = int(input())
def dfs(s):
    if int(s)>n:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for i in '753':
        res += dfs(s+i)
    return res
print(dfs('0'))

Buggy python submission (verdict: Runtime Error):
n = int(input())
def dfs(s):
    if int(s)>n:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for i in '753':
        res += dfs(s+i)
dfs(0)


Fixed submission:
n = int(input())
def dfs(s):
    if int(s)>n:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for i in '753':
        res += dfs(s+i)
    return res
print(dfs('0'))
Buggy python submission (verdict: Runtime Error):
from collections import deque
h,w = map(int, input().split())
G = [['#']*(w+2)]
white = 0
for i in range(h):
    G.append(['#']+list(input()) + ['#'])
    white += G[i+1].count('.')
G.append(['#']*(w+2))

G[1][1] = 1
que = deque([[1,1]])
while que:
    y,x = que.popleft()
    d = G[y][x]
    for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
        ny = y+dy
        nx = x+dx
        if G[ny][nx] == '.':
            G[ny][nx] = d+1
            que.append((ny,nx))
ans = white-G[h][w]
print(ans)


Fixed submission:
from collections import deque
h,w = map(int, input().split())
G = [['#']*(w+2)]
white = 0
for i in range(h):
    G.append(['#']+list(input()) + ['#'])
    white += G[i+1].count('.')
G.append(['#']*(w+2))

G[1][1] = 1
que = deque([[1,1]])
while que:
    y,x = que.popleft()
    d = G[y][x]
    for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
        ny = y+dy
        nx = x+dx
        if G[ny][nx] == '.':
            G[ny][nx] = d+1
            que.append((ny,nx))
if G[h][w] == '.':
    print('-1')
else:
    ans = white - G[h][w]
    print(ans)