alexjercan/bugnet huggingface dataset:
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
S = tuple(map(int, input()))

ans = 0

for i in range(10):
    if i in S[: N - 2]:
        i_index = S.index(i)
        for j in range(10):
            if j in S[i_index + 1 : N - 1]:
                j_index = i_index + S[i_index + 1 : N - 1].index(j) + 1
                for k in range(10):
                    if k in S[j_index + 1 :]:
                        ans += 1
print(ans)


Error: TLE

Fixed submission:

N = int(input())
S = input()

ans = 0

for i in range(1000):
    t = str(i).zfill(3)
    t_index = 0
    for s_index in range(N):
        if S[s_index] == t[t_index]:
            t_index += 1
            if t_index == 3:
                break
    if t_index == 3:
        ans += 1
print(ans)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
s = input()

dp1 = [[0 for i in range(10)] for _ in range(n + 1)]
dp2 = [[0 for i in range(100)] for _ in range(n + 1)]
dp3 = [[0 for i in range(1000)] for _ in range(n + 1)]

for i in range(n):
    dp1[i + 1][int(s[i])] = 1
    for j in range(10):
        if dp1[i][j]:
            dp2[i + 1][j * 10 + int(s[i])] = 1
            dp1[i + 1][j] = 1
    for j in range(100):
        if dp2[i][j]:
            dp3[i + 1][j * 10 + int(s[i])] = 1
            dp2[i + 1][j] = 1
    for j in range(1000):
        if dp3[i][j]:
            dp3[i + 1][j] = 1

print(sum(dp3[n]))


Error: TLE

Fixed submission:

import itertools

n = int(input())
lis = tuple(input())

ans = tuple(itertools.combinations(lis, 3))

result = []
for line in ans:
    if line not in result:
        result.append(line)
print(len(result))
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

import itertools

n = int(input())
s = list(input())

ans = 0


for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = 0
            flag2 = 0

            for l in range(n):
                if flag1 == 0 and s[l] == str(i):
                    flag1 = 1
                    continue

                if flag1 == 1 and flag2 == 0 and s[l] == str(j):
                    flag2 = 1
                    continue

                if flag1 == 1 and flag2 == 1 and s[l] == str(k):
                    ans += 1
                    break

print(ans)


Error: TLE

Fixed submission:

import itertools

n = int(input())
s = list(input())

p = list(itertools.combinations(s, 3))
p = set(p)

print(len(p))
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
S = input()

ans = 0
l1 = []
for i in range(N):
    l2 = []
    if S[i] in l1:
        continue
    else:
        l1.append(S[i])
    for j in range(i + 1, N):
        if S[j] in l2:
            continue
        else:
            l2.append(S[j])
        s = S[j + 1 :]
        ans += len(set(s))

print(ans)


Error: TLE

Fixed submission:

N = int(input())
S = input()

s = []
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            c = S[i] + S[j] + S[k]
            if c in s:
                continue
            else:
                s.append(c)

print(len(s))
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
S = input()
ans = 0

for i in range(10):
    ind_i = S.find(str(i))
    if ind_i != -1:
        S2 = S[ind_i + 1 :]
        for j in range(10):
            ind_j = S2.find(str(j))
            if ind_j != -1:
                S3 = S2[ind_j + 1 :]
                for k in range(10):
                    cnt_k = S3.count(str(k))
                    if cnt_k > 0:
                        ans += 1


print(ans)


Error: TLE

Fixed submission:

N = int(input())
S = input()
ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            hit = 0
            for c in S:
                c_ = int(c)
                if hit == 0 and c_ == i:
                    hit += 1
                elif hit == 1 and c_ == j:
                    hit += 1
                elif hit == 2 and c_ == k:
                    ans += 1
                    break
print(ans)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
s = input()
lst = ["{:03}".format(i) for i in range(1000)]
count = 0
for num in lst:
    pos = 0
    np = num[pos]
    for tmp in s:
        if np == tmp:
            if pos == 2:
                count += 1
                break
            pos += 1
            np = num[pos]
print(count)


Error: TLE

Fixed submission:

n = int(input())
s = input()
lst = [str(a) + str(b) + str(c) for a in range(10) for b in range(10) for c in range(10)]

count = 0
for num in lst:
    pos = 0
    for tmp in s:
        if num[pos] == tmp:
            pos += 1
            if pos == 3:
                count += 1
                break
print(count)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

# 000~999で決め打ちして数える
# TLEになるんだけどこれそんなに重いか？？？？？

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

for i in range(0, 1000):
    t = format(i, "0>3")
    idx = 0
    for c in s:
        if c == t[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)


Error: TLE

Fixed submission:

# 000~999で決め打ちして数える
n = int(input())
s = input()
ans = 0

for i in range(0, 1000):
    t = format(i, "0>3")
    idx = 0
    for c in s:
        if c == t[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    n = int(input())
    T = tuple(map(int, input()))
    ans = 0
    for i in range(0, 1000):
        a = i // 100
        b = (i // 10) % 10
        c = i % 10
        flag1 = False
        flag2 = False
        flag3 = False
        for t in T:
            if flag2:
                if t == c:
                    flag3 = True
                    break
            if flag1:
                if t == b:
                    flag2 = True
                    continue
            if t == a:
                flag1 = True

        if flag3:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

n = int(input())
T = tuple(map(int, input()))
ans = 0
for i in range(0, 1000):
    a = i // 100
    b = (i // 10) % 10
    c = i % 10
    flag1 = False
    flag2 = False
    flag3 = False
    for t in T:
        if flag2:
            if t == c:
                flag3 = True
                break
        if flag1:
            if t == b:
                flag2 = True
                continue
        if t == a:
            flag1 = True

    if flag3:
        ans += 1
print(ans)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
s = input()

t = [set() for _ in range(n)]
t[-1] = {int(s[-1])}

for i in range(1, n):
    base = t[n - i].copy()
    base.add(int(s[n - i - 1]))
    t[n - i - 1] = base

ans = 0
for a in range(10):
    ai = 0

    if a not in t[ai]:
        continue

    while ai < n:
        if s[ai] == str(a):
            break
        else:
            ai += 1
    if ai >= n - 2:
        continue
    for b in range(10):
        bi = ai + 1

        if b not in t[bi]:
            continue

        while bi < n:
            if s[bi] == str(b):
                break
            else:
                bi += 1
        if bi >= n - 1:
            continue
        for c in range(10):
            ci = bi + 1

            if c not in t[ci]:
                continue

            while ci < n:
                if s[ci] == str(c):
                    break
                else:
                    ci += 1
            if ci == n:
                continue
            else:
                ans += 1

print(ans)
exit(0)


x = int(input())
dp = [False for _ in range(x + 1)]
dp[0] = True
for item in [100, 101, 102, 103, 104, 105]:
    for i in range(x + 1):
        if i - item >= 0:
            if dp[i - item]:
                dp[i] = True

print(1 if dp[x] else 0)
exit(0)


Error: TLE

Fixed submission:

n = int(input())
s = input()

ans = 0
for a in range(10):
    ai = 0
    while ai < n:
        if s[ai] == str(a):
            break
        else:
            ai += 1
    if ai == n:
        continue
    for b in range(10):
        bi = ai + 1
        while bi < n:
            if s[bi] == str(b):
                break
            else:
                bi += 1
        if bi == n:
            continue
        for c in range(10):
            ci = bi + 1
            while ci < n:
                if s[ci] == str(c):
                    break
                else:
                    ci += 1
            if ci == n:
                continue
            else:
                ans += 1

print(ans)
exit(0)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
s = map(int, input())

dp = tuple([0] * 1000 for _ in range(4))
dp[0][0] = 1
# dp[x][int(str)]:=x文字のstrは構成可能か？0/1

for x in s:
    for incomplete_key in range(100):
        dp[3][incomplete_key * 10 + x] |= dp[2][incomplete_key]
    for incomplete_key in range(10):
        dp[2][incomplete_key * 10 + x] |= dp[1][incomplete_key]
    dp[1][x] = 1

print(sum(dp[3]))

# dp


Error: TLE

Fixed submission:

n = int(input())
s = map(int, input())

dp = tuple([0] * 1000 for _ in range(4))
dp[0][0] = 1
# dp[x][int(str)]:=x文字のstrは構成可能か？0/1

for x in s:
    for k in range(2, -1, -1):
        for incomplete_key in range(100):
            dp[k + 1][incomplete_key * 10 + x] |= dp[k][incomplete_key]

print(sum(dp[3]))

# dp
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
S = input()

ans = set()
for i in range(10):
    i_index = S.find(str(i))
    if i_index == -1:
        continue
    for j in range(10):
        j_index = S.find(str(j), i_index + 1)
        if j_index == -1:
            continue
        for k in range(10):
            k_index = S.find(str(k), j_index + 1)
            if k_index == -1:
                continue
            ans.add("{}{}{}".format(i, j, k))

print(len(ans))


Error: TLE

Fixed submission:

N = int(input())
S = input()

ans = set()
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            ans.add(S[i] + S[j] + S[k])

print(len(ans))
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

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

for x in range(10):
    if s.find(str(x)) > -1:
        tmp = s[s.find(str(x)) + 1 :]
        for y in range(10):
            if tmp.find(str(y)) > -1:
                tmp2 = tmp[tmp.find(str(y)) + 1 :]
                for z in range(10):
                    if tmp2.find(str(z)) > -1:
                        ans += 1

print(ans)


Error: TLE

Fixed submission:

name = set()
n = int(input())
s = input()

for x in range(n - 2):
    for y in range(x + 1, n - 1):
        for z in range(y + 1, n):
            name.add(int(s[x] + s[y] + s[z]))

print(len(name))
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
S = input()

count = 0
for i in range(1000):
    password = "{:03}".format(i)
    s = S
    for j in range(3):
        index = s.find(password[j])
        if index == -1:
            break
        s = s[index + 1 :]
    else:
        count += 1

print(count)


Error: TLE

Fixed submission:

from collections import Counter
from itertools import combinations

N = int(input())
S = input()

s = []
counter = Counter()
for c in S:
    if counter[c] > 3:
        continue
    s.append(c)

print(len(set(combinations(s, r=3))))
Problem p02844 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = S.find(str(i))
            if fi < 0:
                continue
            fj = S[fi + 1 :].find(str(j))
            if fj < 0:
                continue
            fk = S[fi + fj + 2 :].find(str(k))
            if fk < 0:
                continue
            ans += 1

print(ans)


Error: IndexError: string index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02844/Python/s291909677.py", line 10, in <module>
    fk = S.find(S[k])
IndexError: string index out of range


Fixed submission:

N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = S.find(S[i])
            fj = S.find(S[j])
            fk = S.find(S[k])
            if fi >= 0 and fj >= 0 and fk >= 0 and fi < fj and fj < fk:
                ans += 1

print(ans)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    n = int(input())
    s = str(input())

    res = 0
    for i in range(1000):
        t = str(i).zfill(3)
        pos = 0
        for j in s:
            if t[pos] == j:
                pos += 1
            if pos == 3:
                res += 1
                break
    print(res)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

n = int(input())
s = str(input())

res = 0
for i in range(1000):
    t = str(i).zfill(3)
    pos = 0
    for j in s:
        if t[pos] == j:
            pos += 1
        if pos == 3:
            res += 1
            break

print(res)
Problem p02844 (Python) — buggy submission, verdict: Time Limit Exceeded

import collections
import copy

N = int(input().split()[0])
S = input()

counter = collections.Counter(S)
total = 0
done_list = []

for i, ch in enumerate(S[::-1]):  # 3 * 10 ** 4
    if ch in done_list:
        counter[ch] = counter[ch] - 1
        if counter[ch] < 1:
            del counter[ch]
        continue
    sub_done_list = []
    counter[ch] = counter[ch] - 1
    if counter[ch] < 1:
        del counter[ch]
    sub_counter = copy.copy(counter)

    for ch_2 in S[N - (i + 1) - 1 :: -1]:  # 3 * 10 ** 4
        if ch_2 in sub_done_list:
            sub_counter[ch_2] = sub_counter[ch_2] - 1
            if sub_counter[ch_2] < 1:
                del sub_counter[ch_2]
            continue
        sub_done_list.append(ch_2)
        sub_counter[ch_2] = sub_counter[ch_2] - 1
        if sub_counter[ch_2] < 1:
            del sub_counter[ch_2]
        total += len(sub_counter.keys())

    done_list.append(ch)

ans = total

print(ans)


Error: TLE

Fixed submission:

#!/usr/bin/env python3
import itertools

N = int(input().split()[0])
S = input()

index_list = [i for i in range(N)]
p_list = []

for pattern in itertools.combinations(index_list, 3):
    a, b, c = list(sorted(list(pattern)))

    s = S[a] + S[b] + S[c]
    p_list.append(s)

ans = len(set(p_list))

print(ans)
Problem p02845 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
Alist = list(map(int, input().split()))
nums = [0, 0, 0]
ans = 1
for i in range(N):
    try:
        A = Alist[i]
        ans = (ans * nums.count(A)) % (10**9 + 7)
        nums[nums.index(A)] += 1
    except:
        print(0)
        break
else:
    print(ans)


Error: 0

Fixed submission:

N = int(input())
Alist = list(map(int, input().split()))
abc = [0, 0, 0]
ans = 1
for i in range(N):
    A = Alist[i]
    ans = (ans * abc.count(A)) % (10**9 + 7)
    abc[abc.index(A)] += 1

print(ans)
Problem p02845 (Python) — buggy submission, verdict: Runtime Error

import sys

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    # caps[caps.index(a)] += 1
    for i in range(3):
        if caps[i] == a:
            caps[i] += 1
            break
    ans %= mod
print(ans)


Error: 0

Fixed submission:

import sys

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    caps[caps.index(a)] += 1
    ans %= mod
print(ans)
Problem p02845 (Python) — buggy submission, verdict: Runtime Error

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

ans = 1
cnt = [0, 0, 0]
for i in a:
    ans *= cnt.count(i)
    for j in range(3):
        if cnt[j] == i:
            cnt[j] += 1
            break
    ans %= mod
print(ans)


Error: 0

Fixed submission:

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

ans = 1
cnt = [0, 0, 0]
for i in a:
    ans *= cnt.count(i)
    cnt[cnt.index(i)] += 1
    ans %= mod
print(ans)
Problem p02845 (Python) — buggy submission, verdict: Runtime Error

MOD = 1000000007

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

vec = [0, 0, 0]
num = 1

for a in A:
    idx = [i for i, x in enumerate(vec) if x == a]
    if len(idx) == 0:
        print(0)
        exit()
    num = (num * len(idx)) % MOD
    vec[idx[0]] += 1

print(num)


Error: 0

Fixed submission:

MOD = 1000000007

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

vec = [0, 0, 0]
num = 1

for a in A:
    idx = [i for i, x in enumerate(vec) if x == a]
    num = (num * len(idx)) % MOD
    vec[idx[0]] += 1

print(num)
Problem p02845 (Python) — buggy submission, verdict: Runtime Error

# なんか雑に書いたらサンプル3通ったしこれでよさそう
# なんかしらんけど2ケースでWAなる
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 1
d = [0] * (n + 10)
d[0] = 3
for i in range(n):
    ans *= d[a[i]]
    d[a[i]] -= 1
    d[a[i] + 1] += 1
    ans %= mod
print(ans)


Error: 0

Fixed submission:

# なぜか途中からREなる...
n = int(input())
s = list(map(int, input().split()))
color = 0  # appeared_zero (0~2)
ans = 1
MOD = 1000000007
cur = [-1, -1, -1]
for c in s:
    if c == 0:
        cur[color] = 0
        color += 1
        ans %= MOD
    else:
        x = cur.count(c - 1)
        ans *= x
        ans %= MOD
        if c - 1 in cur:
            idx = cur.index(c - 1)
            cur[idx] += 1
        else:
            print("????????????")
            exit()
ans *= 3 if color == 0 else 3 if color == 1 else 6
ans %= MOD
print(ans)
Problem p02845 (Python) — buggy submission, verdict: Runtime Error

N = int(input())

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

hats = [0, 0, 0]


ans = 1

for i in range(N):
    same_color = num_list[i]
    if same_color not in hats:
        print(0)
        break
    cand_num = hats.count(same_color)
    ans *= cand_num
    ans = ans % 1000000007
    hats[hats.index(same_color)] += 1
else:
    print(ans)


Error: 0

Fixed submission:

N = int(input())

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

hats = [0, 0, 0]


ans = 1

for i in range(N):
    same_color = num_list[i]
    cand_num = hats.count(same_color)
    ans *= cand_num
    ans = ans % 1000000007
    hats[hats.index(same_color)] += 1

print(ans)
Problem p02845 (Python) — buggy submission, verdict: Runtime Error

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

rgb = [0, 0, 0]
ans = 1
for a in A:
    if a not in rgb:
        print(0)
        break
    ans = (ans * rgb.count(a)) % 1000000007
    idx = rgb.index(a)
    rgb[idx] += 1
else:
    print(ans)


Error: 0

Fixed submission:

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

rgb = [0, 0, 0]
ans = 1
for a in A:
    ans = (ans * rgb.count(a)) % 1000000007
    idx = rgb.index(a)
    rgb[idx] += 1

print(ans)
Problem p02846 (Python) — buggy submission, verdict: Runtime Error

import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if (A1 - B1) * T1 + (A2 - B2) * T2 == 0:
    print("infinity")
else:
    D, D1 = (A1 - B1) * T1 + (A2 - B2) * T2, (A1 - B1) * T1
    if (D1 > 0) == (D > 0):
        print(0)
    else:
        if D1 % D == 0:
            print(2 * math.floor(-D1 / D))
        else:
            print(2 * math.floor(-D1 / D) + 1)


Error: 0

Fixed submission:

import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if (A1 - B1) * T1 + (A2 - B2) * T2 == 0:
    print("infinity")
else:
    D1, D2 = (A1 - B1) * T1, (A2 - B2) * T2
    if (D1 > 0) == (D1 + D2 > 0):
        print(0)
    else:
        print(1 + 2 * math.floor(abs(D1) / (abs(D1 + D2) - 1)) + (D1 % D2 == 0))
Problem p02847 (Python) — buggy submission, verdict: Runtime Error

W = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
print(len(W) - W.index(S))


Error: 0

Fixed submission:

W = ["SUM", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
print(len(W) - W.index(S))
Problem p02848 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
S = input()
ans = ""
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(len(S)):
    if a.index(S[i]) + N > 25:
        ans += a[a.index(S[i]) + N - 26]
    else:
        ans += a[a.index(S[i]) + N]

print(ans)


Error: IndexError: string index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s484935538.py", line 10, in <module>
    ans += a[a.index(S[i]) + N]
IndexError: string index out of range


Fixed submission:

N = int(input())
S = input()
ans = ""
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(len(S)):
    if a.index(S[i]) + N > 26:
        ans += a[a.index(S[i]) + N - 26]
    else:
        ans += a[a.index(S[i]) + N]

print(ans)
Problem p02848 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
s = input()

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ans = ""
for i in s:
    ans += a[(int(a.index(i)) + n) % 26]
print(ans)


Error: TypeError: string indices must be integers
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s045183440.py", line 7, in <module>
    ans[i] = a.index(a.index(s[i]) + n)
TypeError: string indices must be integers


Fixed submission:

n = int(input())
s = input()

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" * 2
ans = ""
for i in s:
    ans[i] = a.index(a.index(s[i]) + n)
print(ans)
Problem p02848 (Python) — buggy submission, verdict: Runtime Error

from string import ascii_uppercase as ascii


def main(n: int, s: str):
    ans = ""
    for _s in s:
        ans += ascii[(ascii.index(_s) + n) % 26]

    print(ans)


if __name__ == "__main__":
    n = int(input())
    s = input()

    main(n, s)


Error: AttributeError: 'builtin_function_or_method' object has no attribute 'index'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s884988719.py", line 13, in <module>
    main(n, s)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s884988719.py", line 4, in main
    ans += ascii[(ascii.index(_s) + n) % 26]
AttributeError: 'builtin_function_or_method' object has no attribute 'index'


Fixed submission:

def main(n: int, s: str):
    ans = ""
    for _s in s:
        ans += ascii[(ascii.index(_s) + n) % 26]

    print(ans)


if __name__ == "__main__":
    n = int(input())
    s = input()

    main(n, s)
Problem p02850 (Python) — buggy submission, verdict: Runtime Error

import sys

sys.setrecursionlimit(10**7)

n = int(input())
ki = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ki[a].append([b, i])
ans = [-1] * (n - 1)


# print(ki)


def d(index, color):
    cnt = 1
    for (t, jid) in ki[index]:
        if cnt == color:
            cnt += 1
        ans[jid] = cnt
        d(t, cnt)
        cnt += 1


d(0, 0)
print(max(ans))
for i in ans:
    print(i)


Error: 0

Fixed submission:

n = int(input())
ki = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ki[a].append([b, i])
ans = [-1] * (n - 1)


# print(ki)


def d(index, color):
    cnt = 1
    for (t, jid) in ki[index]:
        if cnt == color:
            cnt += 1
        ans[jid] = cnt
        d(t, cnt)
        cnt += 1


d(0, 0)
print(max(ans))
for i in ans:
    print(i)