Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, X = map(int, input().split())
prices = []
effects = []
for i in range(N):
    c, *a = map(int, input().split())
    prices.append(c)
    effects.append(list(a))

prices = np.array(prices)
effects = np.array(effects)


ans = float("inf")

pats = []
for i in range(2 ** N):
    pat = bin(i).replace("0b", "")
    pat += "0" * (N - len(pat))
    pat = list(map(int, list(pat)))
    pats.append(pat)
    
pats = np.array(pats)
total_price = np.dot(pats, prices)
total_effects = np.dot(pats, effects)
cond = ((total_effects >= X).sum(axis=1) == M)


ans = int(total_price[cond == 1].min())
print(ans)

Fixed submission:
import numpy as np
N, M, X = map(int, input().split())
prices = []
effects = []
for i in range(N):
    c, *a = map(int, input().split())
    prices.append(c)
    effects.append(list(a))
 
prices = np.array(prices)
effects = np.array(effects)
 
 
ans = float("inf")
 
pats = []
for i in range(2 ** N):
    pat = bin(i).replace("0b", "")
    pat = "0" * (N - len(pat)) + pat
    pat = list(map(int, list(pat)))
    pats.append(pat)
    
pats = np.array(pats)
total_price = np.dot(pats, prices)
total_effects = np.dot(pats, effects)
cond = ((total_effects >= X).sum(axis=1) == M)
 
final = total_price[cond == 1]
if len(final) > 0:
    ans = int(final.min())
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
X = int(input())

root = int(X**(1/5))

if root**5 < X:
    rest = X - root**5
    another = -int(rest**(1/5))
else:
    rest = root**5 - X
    another = int(rest**(1/5))

while root**5 - another**5 != X:
    another_plus = another + 1
    another_minus = another - 1
    if root**5 - another_plus**5 == X:
        another = another_plus
        break
    if root**5 - another_minus**5 == X:
        another = another_minus
        break


print(root, another)


Fixed submission:
s = input()

print("ABC" if s == "ARC" else "ARC")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
H = list(map(int, input().split))
AB = [list(map(int, input().split)) for _ in range(M)]

neighbor_max_heights = [0] * N

for i in range(M):
    a, b = AB[i]
    neighbor_max_heights[b-1] = max(neighbor_max_heights[b-1], H[a-1])
    neighbor_max_heights[a-1] = max(neighbor_max_heights[a-1], H[b-1])

ans = 0
for j in range(N):
    if H[j-1] > neighbor_max_heights[j-1]:
        ans += 1
print(ans)

Fixed submission:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]


low_set = set()
appear_set = set()

for i in range(M):
    a, b = AB[i]
    if H[a-1] > H[b-1]:
        low_set.add(b)
    elif H[a-1] < H[b-1]:
        low_set.add(a)
    else:
        low_set.add(a)
        low_set.add(b)

ans_set = set(range(1, N+1)) - low_set
print(len(ans_set))
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

root = int(X**(1/5))

A_cands = [root-1, root, root+1]
B_cands = []
for c in A_cands:
    if c**5 < X:
        rest = X - c**5
        another = -int(rest**(1/5))
        B_cands.append(another)
    else:
        rest = c**5 - X
        another = int(rest**(1/5))
        B_cands.append(another)

tmp = 1

for i in range(3):
    if A_cands[i]**5 - B_cands[i]**5 == X:
        print(A_cands[i], B_cands[i])
        import sys
        sys.exit()


while (A_cands[0]**5 - B_cands[0]**5 != X) and (A_cands[1]**5 - B_cands[1]**5 != X) and (A_cands[2]**5 - B_cands[2]**5 != X):
    for i,b_cand in enumerate(B_cands):
        another_plus = b_cand + 1
        another_minus = b_cand - 1
        if A_cands[i]**5 - another_plus**5 == X:
            B_cands[i] = another_plus
            ans_idx = i
            break
        if A_cands[i]**5 - another_minus**5 == X:
            B_cands[i] = another_minus
            ans_idx = i
            break
    tmp += 1

print(A_cands[ans_idx], B_cands[ans_idx])


Fixed submission:
X = int(input())

import sys

for a in range(-118, 120):
    for b in range(-119, 119):
        if a**5 - b**5 == X:
            print(a, b)
            sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

root = int(X**(1/5))

if root**5 < X:
    rest = X - root**5
    another = -int(rest**(1/5))
else:
    rest = root**5 - X
    another = int(rest**(1/5))

tmp = 1
while root**5 - another**5 != X:
    another_plus = another + tmp
    another_minus = another - tmp
    if root**5 - another_plus**5 == X:
        another = another_plus
        break
    if root**5 - another_minus**5 == X:
        another = another_minus
        break
    tmp += 1


print(root, another)


Fixed submission:
X = int(input())

import sys

for a in range(-118, 120):
    for b in range(-119, 119):
        if a**5 - b**5 == X:
            print(a, b)
            sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

root = int(X**(1/5))

if root**5 < X:
    rest = X - root**5
    another = -int(rest**(1/5))
else:
    rest = root**5 - X
    another = int(rest**(1/5))

while root**5 - another**5 != X:
    another_plus = another + 1
    another_minus = another - 1
    if root**5 - another_plus**5 == X:
        another = another_plus
        break
    if root**5 - another_minus**5 == X:
        another = another_minus
        break


print(root, another)


Fixed submission:
X = int(input())

import sys

for a in range(-118, 120):
    for b in range(-119, 119):
        if a**5 - b**5 == X:
            print(a, b)
            sys.exit()
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

d = dict(collections.Counter([i + A[i-1] for i in range(1, N+1)]))
ans = sum([d.get(i - A[i-1], 0) for i in range(1, N+1)])

print(ans)


Fixed submission:
from collections import Counter

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

d = dict(Counter([i + A[i-1] for i in range(1, N+1)]))
ans = sum([d.get(i - A[i-1], 0) for i in range(1, N+1)])

print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import combinations_with_replacement
import numpy as np

N, M, Q = map(int, input().split())

G = [list(map(int, input().split())) for _ in range(Q)]

ans = 0

# 可能な数列Aの全探索、そのままやとめちゃ多いからなんか工夫する？
# そもそもAの全探索方がいまいちわからん...

A = np.array(list(combinations_with_replacement(range(1, M + 1), N)))
scores = np.zeros(len(A))
for g in G:
    a, b, c, d = g
    cond = A[:, b - 1] - A[:, a - 1] == c
    scores += d * cond
print(scores.max())

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

for i in range(A, B+1):
    if i % K == 0:
        print("OK")
        import sys
        sys.exit()
print("NG")
Buggy python submission (verdict: Runtime Error):
from itertools import combinations_with_replacement
import numpy as np

N, M, Q = map(int, input().split())

G = [list(map(int, input().split())) for _ in range(Q)]

ans = 0

# 可能な数列Aの全探索、そのままやとめちゃ多いからなんか工夫する？
# そもそもAの全探索方がいまいちわからん...

A = np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N)))
scores = np.zeros(len(A))
for g in G:
    a, b, c, d = g
    cond = A[:, b - 1] - A[:, a - 1] == c
    scores += d * cond

print(scores.max())

Fixed submission:
from itertools import combinations_with_replacement
import numpy as np

N, M, Q = map(int, input().split())

G = [list(map(int, input().split())) for _ in range(Q)]

ans = 0

# 可能な数列Aの全探索、そのままやとめちゃ多いからなんか工夫する？
# そもそもAの全探索方がいまいちわからん...

A = np.array(list(combinations_with_replacement(range(1, M + 1), N)))
scores = np.zeros(len(A), dtype=np.int32)
for g in G:
    a, b, c, d = g
    cond = A[:, b - 1] - A[:, a - 1] == c
    scores += d * cond

print(scores.max())
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

days = sum(A)

if days <= N:
    print(N-days)
else:
    print(-1)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
 
days = sum(A)
 
if days <= N:
    print(N-days)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

ans = 0
Ns = range(N+1)
MOD = 10**9 + 7

for i in range(K, N+2): #k-->N+1
    tmp = sum(Ns[-i:]) - sum(Ns[:i]) + 1
    ans += tmp
    ans %= MOD

print(ans)

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

ans = 0
Ns = list(range(N+1))
cumsum = [0]
for i in range(N+1):
    cumsum.append(cumsum[i] + Ns[i])

MOD = 10**9 + 7

for i in range(K, N+2): #k-->N+1
    tmp = cumsum[-1] - cumsum[-i-1] - cumsum[i] + cumsum[0] + 1
    ans += tmp
    ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())


import math
from functools import reduce

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

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(a, b, c)

print(ans)

Fixed submission:
K = int(input())


import math
from functools import reduce

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

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(a, b, c)

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


print(combinations_count(N, 2) + combinations_count(M, 2))

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

import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans = 0

if N >= 2:
    ans += combinations_count(N, 2)

if M >= 2:
    ans += combinations_count(M, 2)

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

words = []
words.append(S)
words.append(S[:(N-1)//2])
words.append(S[(N+3)//2 - 1:])

ans = all([word == word[::-1] for word in words])

print("Yes" if ans else "No")

Fixed submission:
import sys
S = input()
N = len(S)

if S == S[::-1]:
    if S[0:(N-1)//2] == S[0:(N-1)//2][::-1]:
        if S[((N+3)//2)-1:N] == S[((N+3)//2)-1:N][::-1]:
            print("Yes")
            sys.exit()


print("No")

Buggy python submission (verdict: Runtime Error):
import sys
S = input()
N = len(S)

if S == S[::-1]:
    if S[0:(N-1)/2] == S[0:(N-1)/2][::-1]:
        if S[((N+3)/2)-1:N] == S[((N+3)/2)-1:N][::-1]:
            print("Yes")
            sys.exit()


print("No")

Fixed submission:
import sys
S = input()
N = len(S)

if S == S[::-1]:
    if S[0:(N-1)//2] == S[0:(N-1)//2][::-1]:
        if S[((N+3)//2)-1:N] == S[((N+3)//2)-1:N][::-1]:
            print("Yes")
            sys.exit()


print("No")
Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())

reverse = False
cnt = 0
for i in range(Q):
    inp = input().split()
    if len(inp) == 1:
        cnt += 1
        reverse = (cnt % 2 != 0)
        #S = S[::-1]
    else:
        f, c = inp[1:]
        if int(f) == 1:
            if reverse:
                S = S + c
            else:
                S = c + S
        else:
            if reverse:
                S = c + S
            else:
                S = S + c
print(S[::-1] if reverse else S)

Fixed submission:
S = input()
if "A" not in S or "B" not in S:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
for i in range(Q):
    inp = input().split()
    if len(inp) == 1:
        S = S[::-1]
    else:
        f, c = inp[1:]
        if int(f) == 1:
            S = c + S
        else:
            S = S + c
print(S)

Fixed submission:
S = input()
if "A" not in S or "B" not in S:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

MOD = 10 ** 9 + 7

total = 2 ** n - 1
ans = total - combinations_count(n, a) - combinations_count(n, b)
print(ans % MOD)



Fixed submission:
from functools import reduce

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

MOD = 10 ** 9 + 7

def f(A):
    num = reduce(lambda x, y: x * y % MOD, range(N, N - A, -1))
    den = reduce(lambda x, y: x * y % MOD, range(1, A + 1))
    return num * pow(den, MOD - 2, MOD) % MOD

answer = pow(2, N, MOD) - 1 - f(A) - f(B)
answer %= MOD
print(answer)

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

import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

MDO = 10 ** 9 + 7

total = 2 ** n - 1
ans = total - combinations_count(n, a) - combinations_count(n, b)
print(ans % MOD)



Fixed submission:
from functools import reduce

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

MOD = 10 ** 9 + 7

def f(A):
    num = reduce(lambda x, y: x * y % MOD, range(N, N - A, -1))
    den = reduce(lambda x, y: x * y % MOD, range(1, A + 1))
    return num * pow(den, MOD - 2, MOD) % MOD

answer = pow(2, N, MOD) - 1 - f(A) - f(B)
answer %= MOD
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

a = [0] * (len(S) + 1)
S = "*" + S + "*"
for i in range(len(a)):
    left_str = S[:i+1]
    right_str = S[i+1:]

    left_cnt = len(left_str) - len(left_str.rstrip("<"))
    right_cnt = len(right_str) - len(right_str.lstrip(">"))

    a[i] = max(left_cnt, right_cnt)

print(sum(a))

Fixed submission:
S = input()

left_count = [0] * (len(S) + 1)
right_count = [0] * (len(S) + 1)

S = "*" + S + "*"
cur_left_count = 0
cur_right_count = 0
for i in range(len(left_count)):
    if S[i] == "<":
        cur_left_count += 1
    else:
        cur_left_count = 0

    if S[-i-1] == ">":
        cur_right_count += 1
    else:
        cur_right_count = 0
    
    left_count[i] = cur_left_count
    right_count[-i-1] = cur_right_count

a =  [max(l, r) for l, r in zip(left_count, right_count)]

print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

a = [0] * (len(S) + 1)
S = "*" + S + "*"
for i in range(len(a)):
    left_str = S[:i+1]
    right_str = S[i+1:]

    left_cnt = len(left_str) - len(left_str.rstrip("<"))
    right_cnt = len(right_str) - len(right_str.lstrip(">"))

    a[i] = max(left_cnt, right_cnt)

print(sum(a))

Fixed submission:
S = input()

left_count = [0] * (len(S) + 1)
right_count = [0] * (len(S) + 1)

S = "*" + S + "*"
cur_left_count = 0
cur_right_count = 0
for i in range(len(left_count)):
    if S[i] == "<":
        cur_left_count += 1
    else:
        cur_left_count = 0

    if S[-i-1] == ">":
        cur_right_count += 1
    else:
        cur_right_count = 0
    
    left_count[i] = cur_left_count
    right_count[-i-1] = cur_right_count

a =  [max(l, r) for l, r in zip(left_count, right_count)]

print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
l1, r1 = map(int, input().split())
num = list(range(1, n+1))
ans = set(num[l1-1:r1])
for i in range(2, m+1):
    l, r = map(int, input().split())
    can_pass = set(num[l-1:r1])
    ans = ans & can_pass
    if len(ans) == 0:
        break
print(len(ans))

Fixed submission:
n, m = map(int, input().split())
l, r = map(int, input().split())
for i in range(m-1):
    l_c, r_c = map(int, input().split()) 
    l = max(l, l_c)
    r = min(r, r_c)
print(max(r-l+1, 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  i in range(2, m+1):
    l, r = map(int, input().split())
    can_pass = set(range(l, r+1))
    ans = ans.intersection(can_pass)
    if len(ans) == 0:
        break
print(len(ans))

Fixed submission:
n, m = map(int, input().split())
l, r = map(int, input().split())
for i in range(m-1):
    l_c, r_c = map(int, input().split()) 
    l = max(l, l_c)
    r = min(r, r_c)
print(max(r-l+1, 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  i in range(2, m+1):
    l, r = map(int, input().split())
    can_pass = set(range(l, r+1))
    ans = ans.intersection(can_pass)

print(len(ans))

Fixed submission:
n, m = map(int, input().split())
l, r = map(int, input().split())
for i in range(m-1):
    l_c, r_c = map(int, input().split()) 
    l = max(l, l_c)
    r = min(r, r_c)
print(max(r-l+1, 0))
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = input()
TD = [input().split() for _ in range(Q)]

def check(x):
    #Q回の呪文後の位置をチェック
    #1 <= x <= N
    for t, d in TD:
        if s[x] == t:
            if d == 'L':
                x -= 1
            else:
                x += 1
        else:
            continue

        if x == 0:
            return -1
        if x == N + 1:
            return 1
    return 0

ok = 0
ng = N + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if check(mid) == -1:
        ok = mid
    else:
        ng = mid
l = ok


ok = N + 1
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if check(mid) == 1:
        ok = mid
    else:
        ng = mid

r = ng

print(r - l)

Fixed submission:
N, Q = map(int, input().split())
s = '.' + input() + '.'
TD = [input().split() for _ in range(Q)]

def check(x):
    #Q回の呪文後の位置をチェック
    #1 <= x <= N
    for t, d in TD:
        if s[x] == t:
            if d == 'L':
                x -= 1
            else:
                x += 1
        if x == 0:
            return -1
        if x == N + 1:
            return 1
    return 0

ok = 0
ng = N + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if check(mid) == -1:
        ok = mid
    else:
        ng = mid
l = ok


ok = N + 1
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if check(mid) == 1:
        ok = mid
    else:
        ng = mid

r = ng

print(r - l)
Buggy python submission (verdict: Time Limit Exceeded):
import re
N, Q = map(int, input().split())
S = input()
 
def AC_counter(l, r):
    tmp = S[l-1:r]
    match = re.findall('AC', tmp)
    print(len(match))
 
for _ in range(Q):
    l, r = map(int, input().split())
    AC_counter(l, r)

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

t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

def AC_counter(l, r):
    tmp = S[l-1:r]
    print(tmp.count('AC'))

for _ in range(Q):
    l, r = map(int, input().split())
    AC_counter(l, r)


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

t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])
Buggy python submission (verdict: Runtime Error):
n, m, c = map(int, input().split())
b = input().split()
a = [input().split() for input() in range(n)]

cnt = 0
for an in a:
    dot = 0
    for i, j in zip(an, b):
        dot += i*j
    dot += c
    cnt += (dot>0).astype(int)
    
print(cnt)

Fixed submission:
n, m, c = map(int, input().split())
b = [int(x) for x in input().split()]
a = []
for i in range(n):
    a.append([int(x) for x in input().split()])
cnt = 0
for an in a:
    dot = 0
    for i, j in zip(an, b):
        dot += i*j
    dot += c
    cnt += int(dot>0)
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
m = min(a, b)
cnt = 0
for i in range(m, 0, -1):
	if (a % i == 0) and (b % i == 0):
      cnt += 1
      if cnt == k:
        print(i)
        

Fixed submission:
a, b, k = map(int, input().split())
m = min(a, b)
cnt = 0
for i in range(m, 0 ,-1):
    if (a % i == 0) and (b % i == 0):
        cnt += 1
        if cnt == k:
            print(i)
            exit()
Buggy python submission (verdict: Runtime Error):
S = input()
stack = []
cnt = 0

for s in S:
    if s == S[0]:
        stack.append(s)
    elif s != stack[-1]:
        stack.pop()
        cnt += 2
    else:
        stack.append(s)
        
print(cnt)
         

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

one = s.count('1')
zero = s.count('0')

print(2*min(one, zero))

Buggy python submission (verdict: Runtime Error):
S = input()
stack = []
cnt = 0

for s in S:
    if s == S[0]:
        stack.append(s)
    elif s == '0' and s != stack[-1]:
        stack.pop()
        cnt += 2
    elif s == '1' and s != stack[-1]:
        stack.pop()
        cnt += 2
    else:
        stack.append(s)
        
print(cnt)
         

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

one = s.count('1')
zero = s.count('0')

print(2*min(one, zero))

Buggy python submission (verdict: Runtime Error):
S = input()
stack = []
cnt = 0

for s in S:
    if s == S[0]:
        stack.append(s)
    elif s == '0' and s != stack[-1]:
        stack.pop()
        cnt += 2
    elif s == '1' and s != stack[-1]:
        stack.pop()
        cnt += 2
    else:
        stack.sppend(s)
        
print(cnt)
         

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

one = s.count('1')
zero = s.count('0')

print(2*min(one, zero))
Buggy python submission (verdict: Runtime Error):
a, b= input().split()
print(a+b) if b%a==0 else print(b-a)

Fixed submission:
a, b= map(int, input().split())
print(a+b) if b%a==0 else print(b-a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int, input().split()))
Lmax = L.max()
L.remove(Lmax)
print('Yes' if Lmax < L.sum() else 'No')

Fixed submission:
n = int(input())
L = list(map(int, input().split()))
Lmax = max(L)
L.remove(Lmax)
print('Yes' if Lmax < sum(L) else 'No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0

def dfs(s):
    if int(s) > N:
        return

    if s.count('7') and s.count('5') and s.count('3'):
        cnt += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('')

print(ans)

Fixed submission:
N = int(input())
ans = 0

def dfs(i):
    global ans
    if int(i) > N:
        return
    if all(i.count(c) for c in '753'):
        ans += 1
    dfs(i + '3')
    dfs(i + '5')
    dfs(i + '7')
    
dfs('0')

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ms = []
#m_id = []
for i in range(M):
    pi, mi = map(int, input().split())
    ms.append([pi, mi, i])
    #m_id.append(i)
    
ms = sorted(sorted(ms, key=lambda x: x[1]), key=lambda y: y[0])
#m_id = sorted(sorted(m_id, key=lambda x: ms[x][1]), key=lambda y: ms[y][0])

ans_list = []
cnt = 0
for j in range(M):
    if j == 0 or ms[j][0] == ms[j - 1][0]:
        cnt += 1
    else:
        cnt = 1
    num = str(ms[j][0]).zfill(6) + str(cnt).zfill(6)
    ans_list.append(num)
    
id_order = [i[2] for i in ms]
ans_list = sorted(ans_list, key=lambda z: id_order[ans_list.index(z)])

for ans in ans_list:
    print(ans)

Fixed submission:
N, M = map(int, input().split())
A = [''] * M
P = [[] for _ in range(N)]
for i in range(M):
    pi, yi = map(int, input().split())
    P[pi-1].append((yi, i))

for j, pref in enumerate(P):
    pref = sorted(pref, key=lambda x: x[0])
    for k, (yi, i) in enumerate(pref):
        A[i] += str(j+1).zfill(6) + str(k+1).zfill(6)
        
for a in A:
    print(a)
Buggy python submission (verdict: Runtime Error):
N = input()
 
if int(N) <= int(N[0] * 3):
    print(int(N[0] * 3))
else:
    print(int((N[0] + 1) * 3))

Fixed submission:
N = input()
 
if int(N) <= int(N[0] * 3):
    print(int(N[0] * 3))
else:
    print(int(str((int(N[0]) + 1)) * 3))

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

if int(N) < int(N[0] * 3):
    print(int(N[0] * 3))
else:
    print(int((N[0] + 1) * 3))

Fixed submission:
N = input()
 
if int(N) <= int(N[0] * 3):
    print(int(N[0] * 3))
else:
    print(int(str((int(N[0]) + 1)) * 3))