Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())

aa=list(map(int,input().split()))

fumi = set([0])
start = None
end = None
aab = [0]
for i in range(2*10**5):
    next = aa[aab[-1]] - 1
    if next in fumi:
        if start is None:
            start = i
            fumi = set()
        else:
            end = i
            break
    aab.append(next)
    fumi.add(next)

random_first = len(aab) - 2*(end - start)
#print(aab, start, end, aab[start+1:end+1], aab[:random_first])

first = aab[:random_first]
one_cicle = aab[start+1:end+1]
if k <= len(first):
    print(first[k]+1)
else:
    k = k-len(first)
    print(one_cicle[k%len(one_cicle)]+1)

Fixed submission:
n,k=map(int,input().split())

aa=list(map(int,input().split()))

fumi = set([0])
start = None
end = None
aab = [0]
for i in range(10**18):
    next = aa[aab[-1]] - 1
    if next in fumi:
        if start is None:
            start = i
            fumi = set()
        else:
            end = i
            break

    aab.append(next)
    fumi.add(next)
    if i+1 == k:
        print(next+1)
        exit(0)

random_first = len(aab) - 2*(end - start)
#print(aab, start, end, aab[start+1:end+1], aab[:random_first])

first = aab[:random_first]
one_cicle = aab[start+1:end+1]
if k <= len(first):
    print(first[k]+1)
else:
    k = k-len(first)
    print(one_cicle[k%len(one_cicle)]+1)

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

aa=list(map(int,input().split()))

fumi = set([0])
start = None
end = None
aab = [0]
for i in range(1*10**5):
    next = aa[aab[-1]] - 1
    if next in fumi:
        if start is None:
            start = i
            fumi = set()
        else:
            end = i
            break
    aab.append(next)
    fumi.add(next)

random_first = len(aab) - 2*(end - start)
#print(aab, start, end, aab[start+1:end+1], aab[:random_first])

first = aab[:random_first]
one_cicle = aab[start+1:end+1]
if k <= len(first):
    print(first[k]+1)
else:
    k = k-len(first)
    print(one_cicle[k%len(one_cicle)]+1)

Fixed submission:
n,k=map(int,input().split())

aa=list(map(int,input().split()))

fumi = set([0])
start = None
end = None
aab = [0]
for i in range(10**18):
    next = aa[aab[-1]] - 1
    if next in fumi:
        if start is None:
            start = i
            fumi = set()
        else:
            end = i
            break

    aab.append(next)
    fumi.add(next)
    if i+1 == k:
        print(next+1)
        exit(0)

random_first = len(aab) - 2*(end - start)
#print(aab, start, end, aab[start+1:end+1], aab[:random_first])

first = aab[:random_first]
one_cicle = aab[start+1:end+1]
if k <= len(first):
    print(first[k]+1)
else:
    k = k-len(first)
    print(one_cicle[k%len(one_cicle)]+1)
Buggy python submission (verdict: Runtime Error):

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


s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n
#for s1 in s:
#    print(s1)
iidp = [list(map(int,input().split())) for q in range(Q)]

al = 0
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)

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

"""
# このアプローチはメモリーエラー
s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n
#for s1 in s:
#    print(s1)
iidp = [list(map(int,input().split())) for q in range(Q)]

al = 0
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)
"""

iidp = [list(map(int,input().split())) for q in range(Q)]
import itertools
al = 0
for s1 in itertools.combinations_with_replacement(list(range(1,M+1)), N):
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)

Buggy python submission (verdict: Runtime Error):

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


s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n

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

al = []
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al.append(a)

print(max(al))

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

"""
# このアプローチはメモリーエラー
s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n
#for s1 in s:
#    print(s1)
iidp = [list(map(int,input().split())) for q in range(Q)]

al = 0
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)
"""

iidp = [list(map(int,input().split())) for q in range(Q)]
import itertools
al = 0
for s1 in itertools.combinations_with_replacement(list(range(1,M+1)), N):
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)
Buggy python submission (verdict: Runtime Error):
A,B,N=map(int,input().split())
import math
def f(x):
    return math.floor(A*x/B) - A*math.floor(x/B)

ans = []
for i in list(reversed(range(1, N//B+1)))[:100]:
    ans.append(f(B*i-1))
ans.append(f(N))
ans.append(f(1))
#print(f(N))
print(max(ans))

Fixed submission:

A,B,N=map(int,input().split())
import math
def f(x):
    return math.floor(A*x/B) - A*math.floor(x/B)


print(f(min(B-1,N)))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,N=map(int,input().split())
import math
def f(x):
    return math.floor(A*x/B) - A*math.floor(x/B)

ans = []
for i in range(1, N//B+1):
    ans.append(f(B*i-1))
ans.append(f(N))
ans.append(f(1))
#print(f(N))
print(max(ans))

Fixed submission:

A,B,N=map(int,input().split())
import math
def f(x):
    return math.floor(A*x/B) - A*math.floor(x/B)


print(f(min(B-1,N)))
Buggy python submission (verdict: Time Limit Exceeded):
k, n = map(int,input().split())
xs = list(map(int,input().split()))
xs = xs + [x+k for x in xs]

ans = float('inf')
for i in range(n):
    a = xs[i:i+n]
    delta = a[-1] - a[0]
    ans = min(delta, ans)

print(ans)

Fixed submission:
k, n = map(int,input().split())
xs = list(map(int,input().split()))
xs = xs + [x+k for x in xs]

ans = float('inf')
for i in range(n):
    delta = xs[i+n-1] - xs[i]
    ans = min(delta, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())

print( (A*B)//math.gcd(A, B))

Fixed submission:
import math

def computeGCD(x, y):
    if x > y:
        small = y
    else:
        small = x
    for i in range(1, small+1):
        if((x % i == 0) and (y % i == 0)):
            gcd = i
    return gcd
A, B = map(int, input().split())

print( (A*B)//computeGCD(A, B))
Buggy python submission (verdict: Runtime Error):
N=int(input())
xs=map(int,input().split())

cur=1
cnt=0
for x in xs:
    if x == cur:
        cnt += 1
        cur += 1

if cnt == 0:
    print(-1)
else:

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

cur=1
cnt=0
for x in xs:
    if x == cur:
        cnt += 1
        cur += 1

if cnt == 0:
    print(-1)
else:
    print(N-cnt)
Buggy python submission (verdict: Runtime Error):
import fractions

a,b,c,d=map(int,input().split())

gcd = int(fractions.gcd(c,d))

cc = (c//gcd * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)
~

Fixed submission:
import math

a,b,c,d=map(int,input().split())

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

gcd_ = int(gcd(c,d))

cc = (c//gcd_ * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)

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

a,b,c,d=map(int,input().split())

gcd = int(math.gcd(c,d))

cc = (c//gcd * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)

Fixed submission:
import math

a,b,c,d=map(int,input().split())

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

gcd_ = int(gcd(c,d))

cc = (c//gcd_ * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)
Buggy python submission (verdict: Runtime Error):
c = 0
b = 0
for an in range(n):
    c+=1
    b+=ls[an]
    if b>x:
        break
print(c)

Fixed submission:
n,x=map(int,input().split())
ls=list(map(int,input().split()))
c = 1
b = 0
for an in range(n):
    b+=ls[an]
    if b>x:
        break
    c+=1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())

A, B, C, D, E = [int(input()) for i in range(5)]
Xs = [N, 0, 0, 0, 0, 0]
Fs = [A, B, C, D, E]
Fmin = min(Fs)
c = 0
while True:
    #print(Xs)
    nXs = copy.copy(Xs)
    for i in range(len(Fs)):
        if Xs[i] - Fs[i] > 0:
            nXs[i] -= Fs[i]
            nXs[i+1] += Fs[i]
        else:
            nXs[i] -= Xs[i]
            nXs[i+1] += Xs[i]
        #print(nXs)
    Xs = nXs
    c+=1
    if max(Xs[1:5]) == Fmin:
        c+=Xs[0]//Fmin
        Xs[0]%=Fmin
    if sum(Xs[0:5]) == 0:
        break

print(c)

Fixed submission:
N = int(input())
min_ = min([int(input()) for i in range(5)])

suf = 1 if N%min_ != 0 else 0
print(N//min_+4+suf)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())

A, B, C, D, E = [int(input()) for i in range(5)]
Xs = [N, 0, 0, 0, 0, 0]
Fs = [A, B, C, D, E]
Fmin = min(Fs)
c = 0
while True:
    #print(Xs)
    nXs = copy.copy(Xs)
    for i in range(len(Fs)):
        if Xs[i] - Fs[i] > 0:
            nXs[i] -= Fs[i]
            nXs[i+1] += Fs[i]
        else:
            nXs[i] -= Xs[i]
            nXs[i+1] += Xs[i]
        #print(nXs)
    Xs = nXs
    c+=1
    if Xs[1:5] == [Fmin, Fmin, Fmin, Fmin]:
        c+=Xs[0]//Fmin
        Xs[0]%=Fmin
    if sum(Xs[0:5]) == 0:
        break

print(c)

Fixed submission:
N = int(input())
min_ = min([int(input()) for i in range(5)])

suf = 1 if N%min_ != 0 else 0
print(N//min_+4+suf)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
So = input()
import re
S = So.replace('AC', '11')
S = re.sub('[A-Z]', '0', S)
Si = list(map(int, S))

for q in range(Q):
    s, e = map(int,input().split())
    si = Si[s-1:e]
    so = So[s-1:e]
    if So[s-1] == 'C':
        si.pop(0)
    if So[e-1] == 'A':
        si.pop()
    #print(si)
    print(sum(si)//2)

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):
s=input()
orig = len(s)
while True:
    s = list(s)
    for i in range(1, len(s)):
        if s[i] == '0' and s[i-1] == '1':
            s[i] = 'x'
            s[i-1] = 'x'
        elif s[i-1] == '0' and s[i] == '1':
            s[i] = 'x'
            s[i-1] = 'x'
    s = ''.join(s)
    if s == s.replace('x', ''):
        break
    s=s.replace('x', '')
print(orig-len(s))

Fixed submission:
s=input()
orig = len(s)
ones = sum([1 for x in s if x == '1'])
zeros = sum([1 for x in s if x == '0'])
print(2*min(ones, zeros))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
# https://img.atcoder.jp/agc028/editorial.pdf
N, M = map(int,input().split())
S = input()
T = input()

L = int((N*M)/gcd(N, M))

A = [None for i in range(L)]
for n in range(N):
  index =  L*n//N 
  if A[index] is None:
    A[index] = S[n]
  else:
    print(-1)
    exit()

for m in range(M):
  index =  L*m//M
  if A[index] is None or A[index] == T[m]:
    A[index] = T[m]
  else:
    print(-1)
    exit()

print(len(A))

Fixed submission:
from fractions import gcd
# https://img.atcoder.jp/agc028/editorial.pdf
N, M = map(int,input().split())
S = input()
T = input()

L = int((N*M)/gcd(N, M))

gcded = gcd(N,M)
n = N//gcded
m = M//gcded
for i in range(gcded):
  if S[i*n] != T[i*m]:
    print(-1)
    exit()

print(L)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
def lcm(a,b): return abs(a * b)/gcd(a,b) if a and b else 0

n = input()

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

mlcm = 1
for x in set(xs):
  mlcm = lcm(mlcm, x)

mlcm -= 1
mlcm = int(mlcm)
print(sum([ mlcm%x for x in xs]))

Fixed submission:
n = input()
xs = [int(x)-1 for x in input().split()]
print(sum(xs))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
def lcm(a,b): return abs(a * b)/gcd(a,b) if a and b else 0

n = input()

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

from functools import reduce

mlcm = int(reduce(lcm, xs))

mlcm -= 1
print(sum([ mlcm%x for x in xs]))

Fixed submission:
n = input()
xs = [int(x)-1 for x in input().split()]
print(sum(xs))
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    tmp = 1
    for i in a[:k]:
        tmp *= i

    for i in range(k, n):
        cost = tmp * a[i] // a[i-k]
        print('Yes'  if cost > tmp else 'No')
        tmp = cost

if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    for i in range(k, n):
        print('Yes'  if a[i] > a[i-k] else 'No')

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    tmp = 1
    for i in a[:k]:
        tmp *= i

    for i in range(k, n):
        cost = tmp * a[i] // a[i-k]
        print('Yes'  if cost > tmp else 'No')
        tmp = cost

if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    for i in range(k, n):
        print('Yes'  if a[i] > a[i-k] else 'No')

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = 1
for i in map(int, input().split()):
  a *= i

print(-1 if a > 10**18 else a)


Fixed submission:
n = int(input())
ans = 1
a = sorted(map(int, input().split()))
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    break
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,k = map(int, input().split())
t = min(k,a)
k -= min(k,a)
if k:
  k -= b
if k > 0:
  t -= min(k)
print(t)

Fixed submission:
a,b,c,k = map(int, input().split())
t = min(k,a)
k -= min(k,a)
if k:
  k -= b
if k > 0:
  t -= k
print(t)
Buggy python submission (verdict: Runtime Error):
from heapq import heappop, heappush
x,y,a,b,c = map(int, input().split())

aa = sorted(map(int, input().split()), reverse=True)
bb = sorted(map(int, input().split()), reverse=True)
cc = sorted(map(int, input().split()), reverse=True)
heap = []
used = {}
for i in range(min(c,x)):
    heappush(heap, [-cc[i], 2, i])
for i in range(x):
    heappush(heap, [-aa[i], 0, i])

ans = 0
for i in range(x):
    value, color, pos = heappop(heap)
    ans -= value
    if color == 2:
        used.add(pos)

i = 0
heap = []
while len(heap) < y and i < c:
    if i not in used:
        heappush(heap, -cc[i])
    i += 1
for i in range(y):
    heappush(heap, -bb[i])

for i in range(y):
    value = heappop(heap)
    ans -= value

print(ans)


Fixed submission:
from heapq import heappop, heappush
x,y,a,b,c = map(int, input().split())

aa = sorted(map(int, input().split()), reverse=True)
bb = sorted(map(int, input().split()), reverse=True)
cc = sorted(map(int, input().split()), reverse=True)
dd = []
for i in aa[:x]:
    heappush(dd,i)
for i in bb[:y]:
    heappush(dd, i)

for i in range(c):
    heappush(dd, cc[i])
    heappop(dd)

print(sum(dd))
Buggy python submission (verdict: Time Limit Exceeded):
nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    zero = dp[i][0] + cc
    one = dp[i][1] + 10 - cc
    dp[i+1][0] = min(zero, one)
    dp[i+1][1] = min(zero + 1, one - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)
 

Fixed submission:
nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    zero = dp[i][0] + cc
    one = dp[i][1] + 10 - cc
    dp[i+1][0] = min(zero, one)
    dp[i+1][1] = min(zero + 1, one - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)

Buggy python submission (verdict: Time Limit Exceeded):
nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    dp[i+1][0] = min(dp[i][0] + cc, dp[i][1] + 10 - cc)
    dp[i+1][1] = min(dp[i][0] + cc + 1, dp[i][1] + 10 - cc - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)
 

Fixed submission:
nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    zero = dp[i][0] + cc
    one = dp[i][1] + 10 - cc
    dp[i+1][0] = min(zero, one)
    dp[i+1][1] = min(zero + 1, one - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)
Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int, input().split())

inf = float('INF')
dp = [inf for i in range(h+1)]
dp[0] = 0
for i in range(n):
    a,b = map(int, input().split())
    for j in range(h+1):
        # print(j+a)
        if j + a <= h and dp[j+a] > dp[j] + b:
            dp[j+a] = dp[j] + b
        elif j + a > h and dp[h] > dp[j] + b:
            dp[h] = dp[j] + b

print(dp[h])
# print(dp)

Fixed submission:
from math import ceil
h,n = map(int,input().split())

inf = float('INF')
dp = [inf for i in range(h+1)]
dp[0] = 0
for _ in range(n):
    a,b = map(int,input().split())
    for i in range(h+1):
        idx = i-a if i >= a else 0
        if i >= a and dp[i] > dp[idx] + b:
            dp[i] = dp[i-a] + b
        elif i <= a and b < dp[i]:
            dp[i] = b
print(dp[h])
# print(dp)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ss = input()

queue = []
for i in range(n-2):
    queue.append(('', i))

ans = 0
nn = n-3
memo = set()
while queue:
    s, pos = queue.pop()
    # print((s,pos))
    for i in range(pos, n):
        t = s + ss[i]
        if len(t) == n - nn:
            memo.add(t)
        else:
            queue.append((t,i+1))
print(len(memo))
# print(memo)


Fixed submission:
from collections import Counter
from bisect import bisect_right

n = int(input())
s = input()
ndict = {str(i):[] for i in range(10)}
for i,c in enumerate(s):
    ndict[c].append(i)

ans = 0
for i in range(1000):
    PIN = str(i).zfill(3)
    idx = -1
    cc = ''
    for c in PIN:
        if ndict[c] == []:
            break
        tmp = bisect_right(ndict[c], idx)
        if tmp >= len(ndict[c]):
            break
        idx = ndict[c][tmp]
        cc = c
    else:        
        ans += 1
print(ans)

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

queue = []
for i in range(n-2):
    queue.append(('', i))

ans = 0
nn = n-3
memo = set()
while queue:
    s, pos = queue.pop()
    for i in range(n-2):
        if pos + i >= n:
            continue
        t = s + ss[pos+i]
        if len(t) == n - nn:
            memo.add(t)
        else:
            queue.append((t,pos+i+1))
print(len(memo))
# print(memo)


Fixed submission:
from collections import Counter
from bisect import bisect_right

n = int(input())
s = input()
ndict = {str(i):[] for i in range(10)}
for i,c in enumerate(s):
    ndict[c].append(i)

ans = 0
for i in range(1000):
    PIN = str(i).zfill(3)
    idx = -1
    cc = ''
    for c in PIN:
        if ndict[c] == []:
            break
        tmp = bisect_right(ndict[c], idx)
        if tmp >= len(ndict[c]):
            break
        idx = ndict[c][tmp]
        cc = c
    else:        
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

def resolve():
    n, t = map(int, input().split())
    foods = []
    limit = 0
    tt = []
    for i in range(n):
        a, b = map(int, input().split())
        foods.append((a,b))
        limit += a
        tt.append(a)
    c = max(tt) * 2
    foods.sort(key=lambda x:(x[0], -x[1]))
    limit = min(limit * 2, t * 2)
    time = [0 for _ in range(limit+c)]
    used = [0] * (limit + c)
    used[0] = 1

    for a,b in foods:
        for i in range(limit+c)[::-1]:
            if used[i] and i+a*2 < limit + c and time[i+a*2] < time[i] + b:
                time[i+a*2] = time[i] + b
                if i+a*2 < limit:
                    used[i+a*2] = 1

    print(max(time))

if __name__ == "__main__":
    resolve()


Fixed submission:

def resolve():
    n, t = map(int, input().split())
    foods = []
    limit = 0
    tt = []
    for i in range(n):
        a, b = map(int, input().split())
        foods.append((a,b))
        limit += a
        tt.append(a)
    c = max(tt) * 2
    foods.sort(key=lambda x:(x[0], -x[1]))
    limit = min(limit * 2, t * 2)
    time = [0 for _ in range(limit+c)]
    used = [0] * (limit + c)
    used[0] = 1

    for a,b in foods:
        for i in range(limit+c)[::-1]:
            if used[i] and i+a*2 < limit + c and time[i+a*2] < time[i] + b:
                time[i+a*2] = time[i] + b
                if i+a*2 < limit:
                    used[i+a*2] = 1

    print(max(time))

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
n = int(input())
for  i in range(1, 10):
	if n % i == 0 and (n // i) < 10:
    	print('Yes')
        break
else:
	print('No')

Fixed submission:
n = int(input())
for i in range(1, 10):
    if n % i == 0 and (n // i) < 10:
        print('Yes')
        break
else:
    print('No')