Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
    print(k)
cnt = 9
while q:
    x = q.pop(0)
    y = int(str(x)[-1])
    if y != 0:
        cnt += 1
        if cnt == k:
            print(10 * x + y - 1)
            exit()
        q.append(10 * x + y - 1)
    cnt += 1
    if cnt == k:
        print(10 * x + y)
        exit()
    q.append(10 * x + y)
    if y != 9:
        cnt += 1
        if cnt == k:
            print(10 * x + y + 1)
            exit()
        q.append(10 * x + y + 1)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
runrun = [i + 1 for i in range(9)]
ans = runrun
for n in range(11):
    check = runrun
    runrun = []
    for x in check:
        if x > 3234566667:
            break
        y = x % 10
        if y > 0:
            runrun.append(x * 10 + y - 1)
        runrun.append(x * 10 + y)
        if y < 9:
            runrun.append(x * 10 + y + 1)
    ans += runrun
print(ans[k - 1])
Buggy python submission (verdict: Runtime Error):
for i in range(c):
    # print(p[x - 1 - cnt_p], q[y - 1 - cnt_q], cnt_q, cnt_p, cumsum_q, cumsum_p)
    if x - 1 - cnt_p < 0 and y - 1 - cnt_q < 0:
        break
    if x - 1 - cnt_p < 0:
        if r[i] >= q[y - 1 - cnt_q]:
            cumsum_q[y - 1] += r[i] - q[y - 1 - cnt_q]
            cnt_q += 1
        else:
            break
    if y - 1 - cnt_q < 0:
        if r[i] >= q[y - 1 - cnt_q]:
            cumsum_q[y - 1] += r[i] - q[y - 1 - cnt_q]
            cnt_q += 1
        else:
            break
    if p[x - 1 - cnt_p] > q[y - 1 - cnt_q]:
        if r[i] >= q[y - 1 - cnt_q]:
            cumsum_q[y - 1] += r[i] - q[y - 1 - cnt_q]
            cnt_q += 1
        else:
            break
    else:
        if r[i] >= p[x - 1 - cnt_p]:
            cumsum_p[x - 1] += r[i] - p[x - 1 - cnt_p]
            cnt_p += 1
        else:
            break
print(cumsum_p[x - 1] + cumsum_q[y - 1])


Fixed submission:
import sys
input = sys.stdin.readline

x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = list(map(int, input().split()))

C = p[:x] + q[:y] + r
C.sort(reverse=True)

print(sum(C[:x + y]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter, defaultdict
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


n, *a = map(int, read().split())
counter = list(Counter(a).items())
cnt = defaultdict(int)
memo = defaultdict(int)
for k, v in counter:
    if v > 1:
        cnt[k] = cmb(v, 2)
    else:
        cnt[k] = 0
    if v > 2:
        memo[k] = cmb(v - 1, 2)
    else:
        memo[k] = 0
for aa in a:
    print(sum(cnt.values()) - cnt[aa] + memo[aa])


Fixed submission:
import sys
import collections
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
count = collections.Counter(a)
sm = {}
sm2 = {}
for key, value in count.items():
    sm[key] = value * (value - 1) // 2
    sm2[key] = (value - 1) * (value - 2) // 2
total = sum(sm.values())

for num in a:
    print(total - sm[num] + sm2[num])

Buggy python submission (verdict: Runtime Error):
import sys
import collections
import bisect
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
ab = sorted(a)
memo = collections.Counter(ab)
memo_key = list(memo.keys())
memo_v = list(memo.values())
len_v = len(memo_v)
max = max(memo_v)
cnt = [0] * max
cnt_sum = 0
ans_memo = [0] * len_v
for i in range(1, max):
    cnt[i] = cnt[i - 1] + i
for i in range(len_v):
    cnt_sum += cnt[memo_v[i] - 1]
for i in range(len_v):
    ans_memo[i] = cnt[memo_v[i] - 2] + cnt_sum - cnt[memo_v[i] - 1]
for i in range(n):
    ans = ans_memo[bisect.bisect_left(memo_key, a[i])]
    print(ans)


Fixed submission:
import sys
import collections
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
count = collections.Counter(a)
sm = {}
sm2 = {}
for key, value in count.items():
    sm[key] = value * (value - 1) // 2
    sm2[key] = (value - 1) * (value - 2) // 2
total = sum(sm.values())

for num in a:
    print(total - sm[num] + sm2[num])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
flag = True
for i in range(q):
    qfc = input()
    if qfc[0] == '1':
        if flag:
            flag = False
        else:
            flag = True
    else:
        if qfc[2] == '1':
            if flag:
                s = qfc[4] + s
            else:
                s += qfc[4]
        else:
            if flag:
                s += qfc[4]
            else:
                s = qfc[4] + s
if flag:
    print(s)
else:
    print(s[::-1])


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
flag = True
p = ''
m = ''
for i in range(q):
    qfc = input()
    if qfc[0] == '1':
        if flag:
            flag = False
        else:
            flag = True
    else:
        if qfc[2] == '1':
            if flag:
                p += qfc[4]
            else:
                m += qfc[4]
        else:
            if flag:
                m += qfc[4]
            else:
                p += qfc[4]
if flag:
    print(p[::-1] + s + m)
else:
    print(m[::-1] + s[::-1] + p)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
for i in range(q):
    qfc = input()
    if qfc[0] == '1':
        s = s[::-1]
    else:
        if qfc[2] == '1':
            s = qfc[4] + s
        else:
            s += qfc[4]
print(s)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
flag = True
p = ''
m = ''
for i in range(q):
    qfc = input()
    if qfc[0] == '1':
        if flag:
            flag = False
        else:
            flag = True
    else:
        if qfc[2] == '1':
            if flag:
                p += qfc[4]
            else:
                m += qfc[4]
        else:
            if flag:
                m += qfc[4]
            else:
                p += qfc[4]
if flag:
    print(p[::-1] + s + m)
else:
    print(m[::-1] + s[::-1] + p)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = list(input())
for i in range(int(input())):
    q, l, r = input().split()
    q = int(q)
    l = int(l) - 1
    if q == 1:
        if s[l] != r:
            s[l] = r
    else:
        print(len(set(s[l:int(r)])))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from operator import or_


class SegmentTree:
    def __init__(self, orig, func, unit):
        _len = len(orig)
        self.func = func
        self.size = 1 << (_len - 1).bit_length()
        self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
        self.unit = unit

        for i in range(self.size - 1, 0, -1):
            self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])

    def update(self, i, v):
        i += self.size
        self.tree[i] = v
        while i:
            i //= 2
            self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

    def find(self, l, r):
        l += self.size
        r += self.size
        ret = self.unit
        while l < r:
            if l & 1:
                ret = self.func(ret, self.tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.func(ret, self.tree[r])
            l //= 2
            r //= 2
        return ret


n = readline()
s = readline()
q = int(readline())
li = [1 << ord(x) - 97 for x in s[:-1]]
seg = SegmentTree(li, or_, 0)
ans = []
for _ in range(q):
    f, x, y = readline().split()
    x = int(x)
    if f == '1':
        seg.update(x - 1, 1 << ord(y) - 97)
    else:
        y = int(y)
        z = seg.find(x - 1, y)
        cnt = bin(z).count('1')
        ans.append(cnt)
print(*ans)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from functools import lru_cache

n, k = map(int, read().split())


@lru_cache(None)
def check(n, k):
    a, b = divmod(n, 10)
    cnt = 0
    if k >= 1:
        cnt += check(a, k - 1) * b
        cnt += check(a - 1, k - 1) * (9 - b)
    cnt += check(a, b)
    return cnt


if n < 10:
    if k == 1:
        print(n)
    else:
        print(0)
else:
    print(check(n, k))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from functools import lru_cache

n, k = map(int, read().split())


@lru_cache()
def check(n, k):
    if n < 10:
        if k == 0:
            return 1
        if k == 1:
            return n
        return 0
    a, b = divmod(n, 10)
    cnt = 0
    if k >= 1:
        cnt += check(a, k - 1) * b
        cnt += check(a - 1, k - 1) * (9 - b)
    cnt += check(a, k)
    return cnt


print(check(n, k))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
inf = float('inf')
dp = [inf] * (h + 1)
dp[0] = 0
for i, (a, b) in enumerate(ab):
    for j in range(h):
        if j + a >= h:
            dp[-1] = min(dp[-1], dp[j] + b)
        else:
            dp[j + a] = min(dp[j + a], dp[j] + b)
print(dp[-1])


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(n)]
inf = float('inf')
dp = [inf] * (2 * 10 ** 4)
dp[0] = 0
for a, b in ab:
    for n in range(h):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

ans = min(dp[h:])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(n)]
inf = float('inf')
dp = [inf] * (2 * 10 ** 4)
dp[0] = 0
for a, b in ab:
    for n in range(h):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

ans = min(dp[h:])
print(ans)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(n)]
inf = float('inf')
dp = [inf] * (2 * 10 ** 4)
dp[0] = 0
for a, b in ab:
    for n in range(h):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

ans = min(dp[h:])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(n)]
inf = float('inf')
dp = [inf] * (h + 1)
dp[0] = 0
for i in range(n):
    for k in range(h):
        if dp[k] != inf:
            for j in range(1, h + 1):
                if ab[i][0] * j + k < h:
                    dp[j * ab[i][0] + k] = min(dp[k] + ab[i][1] * j, dp[j * ab[i][0] + k])
                else:
                    dp[-1] = min(dp[k] + ab[i][1] * j, dp[-1])
                    break
print(dp[-1])


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(n)]
inf = float('inf')
dp = [inf] * (2 * 10 ** 4)
dp[0] = 0
for a, b in ab:
    for n in range(h):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

ans = min(dp[h:])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n = int(readline())
a = list(map(int, readline().split()))
ans = 0
gcd_ans = a[0]
lcm_ans = a[0]
mod = 10 ** 9 + 7
for i in range(1, n):
    gcd_ans = gcd(lcm_ans, a[i])
    lcm_ans = lcm_ans * a[i] // gcd_ans
for i in range(n):
    ans += lcm_ans // a[i]
    ans %= mod
print(ans % mod)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
A = list(map(int, readline().split()))
mod = 10 ** 9 + 7


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X * Y // y


cnt = 0
ans = 0
LCM = 1
for i in range(n):
    Q = lcm(LCM, A[i])
    cnt *= Q // LCM
    LCM = Q
    cnt += Q // A[i]
print(cnt % mod)

Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import gcd

n = int(readline())
a = list(map(int, readline().split()))
ans = 0
gcd_ans = a[0]
lcm_ans = a[0]
mod = 10 ** 9 + 7
for i in range(1, n):
    gcd_ans = gcd(lcm_ans, a[i])
    lcm_ans = lcm_ans * a[i] // gcd_ans
for i in range(n):
    ans += lcm_ans // a[i]
    ans %= mod
print(ans % mod)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
A = list(map(int, readline().split()))
mod = 10 ** 9 + 7


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X * Y // y


cnt = 0
ans = 0
LCM = 1
for i in range(n):
    Q = lcm(LCM, A[i])
    cnt *= Q // LCM
    LCM = Q
    cnt += Q // A[i]
print(cnt % mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
A = list(map(int, readline().split()))
mod = 10 ** 9 + 7


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X * Y // y


cnt = 0
ans = 0
LCM = 1
for i in range(n):
    Q = lcm(LCM, A[i])
    cnt *= Q // LCM
    LCM = Q
    cnt += Q // A[i]
print(cnt % mod)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
A = list(map(int, readline().split()))
mod = 10 ** 9 + 7


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X * Y // y


cnt = 0
ans = 0
LCM = 1
for i in range(n):
    Q = lcm(LCM, A[i])
    cnt *= Q // LCM
    LCM = Q
    cnt += Q // A[i]
print(cnt % mod)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import gcd, floor

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
cumsum = a[0]
for i in range(1, n):
    cumsum = gcd(cumsum, a[i])
for i in range(n):
    a[i] //= cumsum
lcm_memo = a[0]
for i in range(1, n):
    lcm_memo = lcm_memo * a[i] // gcd(lcm_memo, a[i])
print(floor(m / lcm_memo) - floor(m / (lcm_memo * 2)))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
for i in range(n):
    a[i] //= 2
lcm_memo = 1
for i in range(n):
    lcm_memo *= a[i] // gcd(lcm_memo, a[i])
    if lcm_memo > m:
        print(0)
        exit()
for i in range(n):
    if (lcm_memo // a[i]) % 2 == 0:
        print(0)
        exit()
print(1 + (m - lcm_memo) // (lcm_memo * 2))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
r, s, p = map(int, readline().split())
t = input()
ans = [0, 0, 0]
for i in range(k):
    if t[i] == 'r':
        ans[0] += 1
    elif t[i] == 's':
        ans[1] += 1
    else:
        ans[2] += 1
memo = []
for i in range(k, n):
    if t[i] == t[i - k] and (i - k) not in memo:
        memo.append(i)
    elif t[i] == 'r':
        ans[0] += 1
    elif t[i] == 's':
        ans[1] += 1
    elif t[i] == 'p':
        ans[2] += 1
print(ans[0] * p + ans[1] * r + ans[2] * s)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
r, s, p = map(int, readline().split())
t = input()
ans = [0, 0, 0]
check = t[:k]
for i in range(k, n):
    if t[i] == check[i - k]:
        check += 'a'
    else:
        check += t[i]
for i in range(k):
    if t[i] == 'r':
        ans[0] += 1
    elif t[i] == 's':
        ans[1] += 1
    else:
        ans[2] += 1
for i in range(k, n):
    if check[i] != check[i - k]:
        if check[i] == 'r':
            ans[0] += 1
        elif check[i] == 's':
            ans[1] += 1
        elif check[i] == 'p':
            ans[2] += 1
print(ans[0] * p + ans[1] * r + ans[2] * s)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
cnt = 0
for i in range(1000):
    num = ''
    if i < 100:
        num += '0'
        if i < 10:
            num += '0'
    num += str(i)
    index = 0
    for ss in s:
        if ss == num[index]:
            index += 1
            if index == 3:
                cnt += 1
                break
print(cnt)


Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
s = input()
ans = 0

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for S in s:
        if S == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)

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

n = int(input())
s = input()
ans = 0

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for j in range(n):
        if s[j] == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
s = input()
ans = 0

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for S in s:
        if S == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)

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

n = int(input())
s = input()
ans = 0

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for j in range(len(s)):
        if s[j] == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
s = input()
ans = 0

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for S in s:
        if S == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
ans = 1
mod = 10 ** 9 + 7
memo = [0, 0, 0]
for check in a:
    ans *= memo.count(check)
    ans %= mod
    memo[memo.index(check)] += 1
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A - 1)
    ans %= mod
    for i in range(3):
        if rbg[i] == A - 1:
            rbg[i] = A
            break

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A - 1)
    ans %= mod
    rbg[rbg.index(A - 1)] = A

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A - 1)
    ans %= mod
    for i in range(3):
        if rbg[i] == A - 1:
            rbg[i] = A
            break

print(ans)