Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=math.gcd(i,math.gcd(j,k)) 
print(ans)           



Fixed submission:
import math

ans = 0
K = int(input())
dp = [[1] * 220 for i in range(220)] 
for i in range(1,K+1):
    for j in range(1,K+1):
        dp[i][j] = math.gcd(i,j)
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a = dp[i][j]
            ans += dp[a][k]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
rs = [s=="R" for s in S]
gs = [s=="G" for s in S]
bs = [s=="B" for s in S]

ind_r = [i for i,s in enumerate(rs) if s == 1]
ind_g = [i for i,s in enumerate(gs) if s == 1]
ind_b = [i for i,s in enumerate(bs) if s == 1]

ans = 0
ng = sum(gs)
for i in ind_r:
    for j in ind_b:
        # print(i,j)
        kM = max(i,j) + abs(i-j)
        km = min(i,j) - abs(i-j)
        ans += ng
        if (max(i,j) - min(i,j))%2==0:
            # print("aaa",(max(i,j)+min(i,j))//2)
            ans -= gs[(max(i,j)+min(i,j))//2]
        if kM < n:
            ans -= gs[kM]
        if 0 <= km:
            ans -= gs[km]
print(ans)

Fixed submission:
N = int(input())
S = input()

from collections import defaultdict
d = defaultdict(list)

for i,s in enumerate(S):
    d[s].append(i)

Bs = [0] * 8000
cnt_b = len(d["B"])

for i in  d["B"]:
    Bs[i] += 1

ans = 0
for i_r in d["R"]:
    for i_g in d["G"]:
        ls = []
        mx = max(i_r,i_g)
        mn = min(i_r,i_g)
        if (mx-mn) % 2 == 0:
            ls.append((mx+mn)//2)    
        ls.append(mx + (mx-mn))
        if  mn - (mx-mn) >= 0: 
            ls.append(mn-(mx-mn)) 
        cnt = 0
        for l in ls:
            cnt += Bs[l]
        # print(i_r,i_g,ls)
        ans += cnt_b - cnt
print(ans)

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

from collections import defaultdict
d = defaultdict(list)

for i,s in enumerate(S):
    d[s].append(i)

Bs = [0] * 8000
cnt_b = len(d["B"])

for i in  d["B"]:
    Bs[i] += 1

ans = 0
for i_r in d["R"]:
    for i_g in d["G"]:
        ls = []
        mx = max(i_r,i_g)
        mn = min(i_r,i_g)
        if (mx-mn) % 2 == 0:
            ls.append((mx+mn)//2)    
        ls.append(mx + (mx-mn))
        if  mn - (mx-mn) >= 0: 
            ls.append(mn-(mx-mn)) 
        cnt = 0
        for l in ls:
            cnt += Bs[l]
        # print(i_r,i_g,ls)
        ans += cnt_b - cnt
print(ans)

Fixed submission:
N = int(input())
S = input()

from collections import defaultdict
d = defaultdict(list)

for i,s in enumerate(S):
    d[s].append(i)

Bs = [0] * 8000
cnt_b = len(d["B"])

for i in  d["B"]:
    Bs[i] += 1

ans = 0
for i_r in d["R"]:
    for i_g in d["G"]:
        ls = []
        mx = max(i_r,i_g)
        mn = min(i_r,i_g)
        if (mx-mn) % 2 == 0:
            ls.append((mx+mn)//2)    
        ls.append(mx + (mx-mn))
        if  mn - (mx-mn) >= 0: 
            ls.append(mn-(mx-mn)) 
        cnt = 0
        for l in ls:
            cnt += Bs[l]
        # print(i_r,i_g,ls)
        ans += cnt_b - cnt
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=math.gcd(i,math.gcd(j,k)) 
print(ans)           



Fixed submission:
N,K = map(int, input().split())
mod = 10**9+7
ans = 0
dp = [0] * (K+10)

for i in range(K,0,-1):
    x = K//i
    a = pow(x, N, mod)
    cnt = 2
    while i*cnt <= K:
        a -= dp[i*cnt]
        cnt += 1
    a %= mod
    dp[i] = a
    ans += a*i
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C  = map(int, input().split())
ps = sorted(list(map(int, input().split())),reverse=True)
qs = sorted(list(map(int, input().split())),reverse=True)
# qs = list(map(int, input().split()))
rs = sorted(list(map(int, input().split())),reverse=True)

# cnt_x = 0
# cnt_y = 0
ps = ps[:X]
qs = qs[:Y]
cnt_c = 0
ans = sum(ps)+sum(qs)
while cnt_c < C:
    p = ps.pop()
    q = qs.pop()
    r = rs[cnt_c]
    if p - r >= 0 and q - r >= 0:
        break
    elif r - p > r - q: #pのほうが差分が大きい
        qs.append(q)
        ans -= p
        ans += r
    else:
        ps.append(p)
        ans -= q
        ans += r
    cnt_c += 1
print(ans)





Fixed submission:
X,Y,A,B,C  = map(int, input().split())
ps = sorted(list(map(int, input().split())),reverse=True)
qs = sorted(list(map(int, input().split())),reverse=True)
rs = sorted(list(map(int, input().split())),reverse=True)

ps = ps[:X]
qs = qs[:Y]
cnt_c = 0
ans = sum(ps)+sum(qs)
INF = 10**10
while cnt_c < C:
    if len(ps) != 0:
        p = ps.pop()
    else:
        p = INF
    if len(qs) != 0:
        q = qs.pop()
    else:
        q = INF
    r = rs[cnt_c]
    if p - r >= 0 and q - r >= 0:
        break
    elif r - p > r - q: #pのほうが差分が大きい
        qs.append(q)
        ans -= p
        ans += r
    else:
        ps.append(p)
        ans -= q
        ans += r
    cnt_c += 1
print(ans)



"""
2 2 2 2 4
2 4
5 1
10 10 10 10 10
"""
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int, input().split())
fields =  [list(input()) for i in range(H)]
# print(fields)

from collections import deque
cnts = [[1000] * W for i in range(H)]
q = deque()
q.append((0,0))
cnts[0][0] = 0
str_s = "."
mv = [(1,0),(0,1)]
while len(q) > 0:
    h,w = q.popleft()
    # mark = fields[h][w]
    for dh, dw in mv:
        if h + dh < H and w + dw < W:
            # print("upd",h,w,h+dh,w+dw,H,W)
            if fields[h][w] == fields[h+dh][w+dw]:
                upd = cnts[h][w] 
            else:
                if fields[h][w] == ".":
                    upd = cnts[h][w] + 1
                else:
                    upd = cnts[h][w]
            cnts[h+dh][w+dw] = min(cnts[h+dh][w+dw],upd)
            q.append((h+dh,w+dw))

# print(cnts)

ans = cnts[H-1][W-1]
if fields[0][0] == "#":ans += 1
print(ans)



Fixed submission:
H,W = map(int, input().split())
fields =  [list(input()) for i in range(H)]
# print(fields)

from collections import deque
cnts = [[1000] * W for i in range(H)]
q = deque()
q.append((0,0))
cnts[0][0] = 0
str_s = "."
mv = [(1,0),(0,1)]
while len(q) > 0:
    h,w = q.popleft()
    # mark = fields[h][w]
    for dh, dw in mv:
        if h + dh < H and w + dw < W:
            # print("upd",h,w,h+dh,w+dw,H,W)
            if fields[h][w] == fields[h+dh][w+dw]:
                upd = cnts[h][w] 
            else:
                if fields[h][w] == ".":
                    upd = cnts[h][w] + 1
                else:
                    upd = cnts[h][w]
            if cnts[h+dh][w+dw] > upd:
                cnts[h+dh][w+dw] = min(cnts[h+dh][w+dw],upd)
                q.append((h+dh,w+dw))

# print(cnts)

ans = cnts[H-1][W-1]
if fields[0][0] == "#":ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
As = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(As[K-1])

Fixed submission:
As = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(As[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
from copy import copy
from collections import defaultdict
N,P = map(int, input().split())
S = input()
d = [0] * 10000
prev = [0] * 10000
key_prev = set([0])

for i,s in enumerate(S):
    tmp = [0] * 10000
    key_tmp = set([0])
    amari = int(s)%P
    tmp[amari] += 1
    key_tmp.add(amari)
    
    for k in key_prev:
        tmp[(k*10+amari)%P] += prev[k]
        key_tmp.add((k*10+amari)%P)
    
    for k in key_tmp:
        d[k] += tmp[k]

    prev = copy(tmp)
    key_prev = copy(key_tmp)
print(d[0])

Fixed submission:
from collections import defaultdict
N,P = map(int, input().split())
S = list(input()[::-1])
ans = 0
if P == 2:
    for i,s in enumerate(S):    
        if int(s) in [2,4,6,8,0]:
            ans += N - i
elif P == 5:
    for i,s in enumerate(S):    
        if int(s) in [0,5]:
            ans += N - i
else:
    d = defaultdict(int)
    cnt = 0
    d[0] = 1
    for i,s in enumerate(S):
        cnt = (cnt + pow(10,i,P)*int(s))%P
        d[cnt] += 1
    for k in d.keys():
        if d[k] > 1:
            ans += d[k]*(d[k]-1)//2 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import copy
from collections import defaultdict
N,P = map(int, input().split())

S = input()
d = defaultdict(int) #全余り
prev = defaultdict(int) #以前の余り
for i,s in enumerate(S):
    tmp = defaultdict(int) #追加するときの余り
    amari = int(s)%P

    tmp[amari] += 1
    for k in prev.keys():
        tmp[(k*10+amari)%P] += prev[k]

    for k in tmp.keys():
        d[k] += tmp[k]

    prev = copy(tmp)
print(d[0])

Fixed submission:
from collections import defaultdict
N,P = map(int, input().split())
S = list(input()[::-1])
ans = 0
if P == 2:
    for i,s in enumerate(S):    
        if int(s) in [2,4,6,8,0]:
            ans += N - i
elif P == 5:
    for i,s in enumerate(S):    
        if int(s) in [0,5]:
            ans += N - i
else:
    d = defaultdict(int)
    cnt = 0
    d[0] = 1
    for i,s in enumerate(S):
        cnt = (cnt + pow(10,i,P)*int(s))%P
        d[cnt] += 1
    for k in d.keys():
        if d[k] > 1:
            ans += d[k]*(d[k]-1)//2 
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N,M = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
S = [1]+[0]*(N-1)
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if d[s] > 0 and S[s] != c:
        print(-1)
        exit()
    S[s] = c
    d[s] += 1
if S[0] == 0:
    print(-1)
    exit()
if len(S) == 1:
    print("".join([str(s) for s in S]))
else:
    if d[s] == 0:
        x = [1]+[0]*(N-1)
        ans = "".join([str(_) for _ in x])
        print(ans)
    else:
        print("".join([str(s) for s in S]))


Fixed submission:
#!/usr/bin/env python3

N,M = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
S = [1]+[0]*(N-1)
flg = True
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if d[s] > 0 and S[s] != c:
        flg = False
    S[s] = c
    d[s] += 1

if M == 0 and N == 1:
    print(0)
    exit()
if not flg:
    print(-1)
    exit()
if S[0] == 0:
    if len(S) == 1:
        print(*S)
    else:
        print(-1)
    exit()
print("".join([str(s) for s in S]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
q = int(input())


class BIT:
    def __init__(self, n):
        """
        初期化
        Input:　
            n: 配列の大きさ
        """
        self.n = n
        self.bit = [0] * (n+10)

    def add(self, x, w):
        """
        更新クエリ(add)
        Input:
            x: インデックス
            w: 加える値
        Note:
            self.bitが更新される
        """        
        while x <= self.n:
            self.bit[x] += w
            x += x&-x
    
    def sum(self, x):
        """
        部分和算出クエリ
        Input:
            x: インデックス
        Return:
            [1,a]の部分和
        """
        cnt = 0
        while x > 0:
            cnt += self.bit[x]
            # 次の最下位桁はどこか
            x -= x&-x
        return cnt   
    
    def psum(self, a, b):
        """
        区間[a,b)(0-indexed)における和
        Input
            a,b: 半開区間
        Return
            [a,b)の和
        """
        return self.sum(b-1) - self.sum(a-1)


def str2num(s):
    return ord(s)-ord("a")

bits = [BIT(n) for i in range(26)]
# 入力
ans = []
for i, s in enumerate(S):
    ind = str2num(s)
    bits[ind].add(i+1, 1)

S = list(S)
for _ in range(q):
    x,a,b = input().split()
    if x == "1":
        i = int(a)
        # 更新処理
        ind_before = str2num(S[i-1])
        ind = str2num(b)
        bits[ind_before].add(i,-1)
        bits[ind].add(i, 1)
        S[i-1] = b
    else:
        l = int(a)
        r = int(b)
        cnt = 0
        for bit in bits:
            if bit.psum(l,r+1) > 0:
                cnt += 1
        ans.append(cnt)
print(*ans)

        


Fixed submission:
n = int(input())
S = input()
q = int(input())


class BIT:
    def __init__(self, n):
        """
        初期化
        Input:　
            n: 配列の大きさ
        """
        self.n = n
        self.bit = [0] * (n+10)

    def add(self, x, w):
        """
        更新クエリ(add)
        Input:
            x: インデックス
            w: 加える値
        Note:
            self.bitが更新される
        """        
        while x <= self.n:
            self.bit[x] += w
            x += x&-x
    
    def sum(self, x):
        """
        部分和算出クエリ
        Input:
            x: インデックス
        Return:
            [1,a]の部分和
        """
        cnt = 0
        while x > 0:
            cnt += self.bit[x]
            # 次の最下位桁はどこか
            x -= x&-x
        return cnt   
    
    def psum(self, a, b):
        """
        区間[a,b)(0-indexed)における和
        Input
            a,b: 半開区間
        Return
            [a,b)の和
        """
        return self.sum(b-1) - self.sum(a-1)


def str2num(s):
    return ord(s)-ord("a")

bits = [BIT(n) for i in range(26)]
# 入力
ans = []
for i, s in enumerate(S):
    ind = str2num(s)
    bits[ind].add(i+1, 1)

S = list(S)
for _ in range(q):
    x,a,b = input().split()
    if x == "1":
        i = int(a)
        # 更新処理
        ind_before = str2num(S[i-1])
        ind = str2num(b)
        bits[ind_before].add(i,-1)
        bits[ind].add(i, 1)
        S[i-1] = b
    else:
        l = int(a)
        r = int(b)
        cnt = 0
        for bit in bits:
            if bit.psum(l,r+1) > 0:
                cnt += 1
        ans.append(cnt)
print(*ans)
Buggy python submission (verdict: Runtime Error):
red blue
5 5
blue

Fixed submission:
S,T = input().split()
a,b = map(int, input().split())
U = input()
if U == S:
    print(a-1,b)
else:
    print(a,b-1)
Buggy python submission (verdict: Time Limit Exceeded):
H, N  = map(int, input().split())
# hitpoint H
# waza N
As = [] # damage
Bs = [] # MP comsumptions
for i in range(N):
    a,b = map(int, input().split())
    As.append(a)
    Bs.append(b)

"""
dp[i][j] = i番目までの魔法を見たとき、ダメージがちょうどjになる最小値
"""
INF = 10**10
M = 21000
dp = [[INF]*M for i in range(N+1)]
dp[0][0] = 0
for i,(a,b) in enumerate(zip(As,Bs)):
    dp[i+1][:] = dp[i][:]
    for j in range(H):        
        dp[i+1][j+a] = min(dp[i][j+a], dp[i+1][j]+b)
        # print(i,j,"ab",a,b,"dp",dp[i][j],dp[i][j+1],dp[i][j]+b)
print(min(dp[N][H:]))


Fixed submission:
H, N  = map(int, input().split())
# hitpoint H
# waza N
As = [] # damage
Bs = [] # MP comsumptions
for i in range(N):
    a,b = map(int, input().split())
    As.append(a)
    Bs.append(b)

"""
dp[i][j] = i番目までの魔法を見たとき、ダメージがちょうどjになる最小値
"""
INF = 10**10
M = 21000
dp = [[INF]*M for i in range(N+1)]
dp[0][0] = 0
for i,(a,b) in enumerate(zip(As,Bs)):
    dp[i+1][:] = dp[i][:]
    for j in range(H):        
        dp[i+1][j+a] = min(dp[i][j+a], dp[i+1][j]+b)
        # print(i,j,"ab",a,b,"dp",dp[i][j],dp[i][j+1],dp[i][j]+b)
print(min(dp[N][H:]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

INF = 1<<20

dp = [[INF] * 55 for i in range(1<<n)]
dp[0][0] = 0

for b in range(1<<n):
    # 使ったカードの枚数
    bitcnt = bin(b).count("1")
    cur = bitcnt 
    rest = [] 
    for i in range(n):
        # i番目のbitが立っているかの判定
        if not (b & (1 << i)):
            rest.append((i,cur))
            cur += 1
    # A,Bの制約から、sは55まででOK
    for s in range(51):
        if dp[b][s] >= INF:
            continue
        # 残ったカードで更新
        for i,cur in rest:
            if abs(bitcnt - i) % 2 == 0:
                num = As[i]
            else:
                num = Bs[i]
            if num >= s:
                d = abs(bitcnt - cur) 
                dp[b|(1<<i)][num] = min(dp[b|(1<<i)][num], dp[b][s] + d)
            

ans = min(dp[(1<<n)-1])
print(ans if ans != INF else -1)    
        
    


Fixed submission:
from itertools import combinations
n = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

even = []   #偶数番目で表になる
odd = []    #奇数番目で表になる
for i,(a,b) in enumerate(zip(As,Bs)):
    if i%2 == 0:
        even.append(a)
        odd.append(b)
    else:
        even.append(b)
        odd.append(a)



def check(n, even, odd):
    prev = -10**10
    ps = []
    for i in range(n):
        if i%2 == 0:
            if prev > even[i//2][0]:
                return False,-1
            else:
                ps.append(even[i//2][1])
            prev = even[i//2][0]
        else:
            if prev > odd[i//2][0]:
                return  False, -1
            else:
                ps.append(odd[i//2][1])
            prev = odd[i//2][0]
    return True, ps
    


def inversion(a):
    n = len(a)
    cnt = 0
    for i in range(n):
        for j in range(i+1,n):
            if a[i] > a[j]:
                cnt +=1
    return cnt
 
#偶数としてpickupするやつ
INF = 10**10
ans = 10**10
for l in combinations(range(n), (n-1)//2+1):
    cnt = 0
    even_selected = [(even[i],i) for i in range(n) if i in l]
    odd_selected = [(odd[i],i) for i in range(n) if i not in l]
    # こいつらを昇順に並べられるか
    even_selected.sort()
    odd_selected.sort()
    is_possible, a = check(n, even_selected, odd_selected)
    # 並び順が正しければ
    if is_possible:
        cnt = inversion(a)
        ans = min(cnt, ans)
        
if ans == INF:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,V,P = map(int, input().split())
As = list(map(int, input().split()))
As.sort(reverse=True)
# print(As)
"""
M人がV問のスコアを1挙げられる
N問のうち降順に並べたP問が採用される

6 1 2 2
2 1 1 3 0 2
方針
最小の数(-1)にVを足す
上からP-1番目までの数にMを足す
P番目の数がVを超えているかどうか判定
最小の数からindex-1
"""


x = N - (P-1)
y = max(0, V - P - 1) #除外対象
# print(P-1,y)
if y == 0:
    As = As[P-1:]
else:
    As = As[P-1:-y]
# 同じは弾く
As = [a for a in As if a > As[y]]
# print(As)
mx = max(As)
cnt = 0
for a in As:
    if a + M >= mx:cnt+=1
print(P-1+cnt)

Fixed submission:
n,m,v,p = map(int, input().split())
As = list(map(int, input().split()))
As.sort(reverse=True)
# print(As)
def f(x):
    # 判定基準
    if x < p:
        return True
    if As[x]+m < As[p-1]:
        return False
    cnt0 = (n-x)*m
    cnt1 = (p-1)*m
    cnt2 = 0
    for i in range(p-1, x):
        cnt2 += As[x]+m-As[i]
    return cnt0 + cnt1 + cnt2 >= m*v    


# 二部探索でOK/NG求める
ok = 0
ng = n
while ng - ok > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
X = ["{:03d}".format(i) for i in range(1000)]
# print(X)
ans = 0
for x in X:
    now = 0
    for s in S:
        if s == x[now]:
            now += 1
        if now == 3:
            ans += 1
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
#0なし
numlist = [""]
dp = [False] * 1000
for s in S:
    tmp = []
    for n in numlist:
        if len(n+s) == 3:
            dp[int(n+s)] = True
        if len(n+s) < 3:
            tmp.append(n+s)
    numlist.extend(tmp)
    numlist = list(set(numlist))
print(sum(dp))
Buggy python submission (verdict: Runtime Error):
N = int(input())
As = list(map(int, input().split()))
dp = [0] * 100000
mod = 10**9 + 7
ans = 1
dp[0] = 3
for a in As:
    a += 1
    ans *= dp[a-1]-dp[a]
    ans %= mod
    dp[a] += 1
print(ans%mod)

Fixed submission:
N = int(input())
As = list(map(int, input().split()))
dp = [0] * 1000000
mod = 10**9 + 7
ans = 1
dp[0] = 3
for a in As:
    a += 1
    ans *= dp[a-1]-dp[a]
    ans %= mod
    dp[a] += 1
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())
edges = [[] for i in range(N)]
e_list = []

for i in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    e_list.append((a,b))
    edges[a].append((b,i))
    edges[b].append((a,i))

ans = [0] * (N-1)

def dfs(v, p=-1, c=-1): #親p(はじめはいないので-1), 子がv, 親の色も渡す必要あり
    # 子が次の子孫をグラフから探す
    global ans
    next_v = edges[v]
    cnt = 1 # num of colors
    for u,i in next_v:
        # 子孫の中には親もいて、それは除外
        if u == p: continue
        # 子供に対しては自分が親となり、同様のことをする
        if cnt == c:
            cnt += 1
        ans[i] = cnt      
        cnt += 1
        dfs(u, v, ans[i])


dfs(0)
print(max(ans))
for a in ans:
    print(a)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
N = int(input())
edges = [[] for i in range(N)]
e_list = []

for i in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    e_list.append((a,b))
    edges[a].append((b,i))
    edges[b].append((a,i))

ans = [0] * (N-1)

def dfs(v, p=-1, c=-1): #親p(はじめはいないので-1), 子がv, 親の色も渡す必要あり
    # 子が次の子孫をグラフから探す
    global ans
    next_v = edges[v]
    cnt = 1 # num of colors
    for u,i in next_v:
        # 子孫の中には親もいて、それは除外
        if u == p: continue
        # 子供に対しては自分が親となり、同様のことをする
        if cnt == c:
            cnt += 1
        ans[i] = cnt      
        cnt += 1
        dfs(u, v, ans[i])


dfs(0)
print(max(ans))
for a in ans:
    print(a)

Buggy python submission (verdict: Runtime Error):
N = int(input())
edges = [[] for i in range(N)]
e_list = []

for i in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    e_list.append((a,b))
    edges[a].append((b,i))
    edges[b].append((a,i))

ans = [0] * (N-1)

def dfs(v, p=-1, c=-1): #親p(はじめはいないので-1), 子がv, 親の色も渡す必要あり
    # 子が次の子孫をグラフから探す
    global ans
    next_v = edges[v]
    cnt = 1 # num of colors
    for u,i in next_v:
        # 子孫の中には親もいて、それは除外
        if u == p: continue
        # 子供に対しては自分が親となり、同様のことをする
        if cnt == c:
            cnt += 1
        ans[i] = cnt      
        cnt += 1
        dfs(u, v, ans[i])

dfs(0)
for a in ans:
    print(a)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
N = int(input())
edges = [[] for i in range(N)]
e_list = []

for i in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    e_list.append((a,b))
    edges[a].append((b,i))
    edges[b].append((a,i))

ans = [0] * (N-1)

def dfs(v, p=-1, c=-1): #親p(はじめはいないので-1), 子がv, 親の色も渡す必要あり
    # 子が次の子孫をグラフから探す
    global ans
    next_v = edges[v]
    cnt = 1 # num of colors
    for u,i in next_v:
        # 子孫の中には親もいて、それは除外
        if u == p: continue
        # 子供に対しては自分が親となり、同様のことをする
        if cnt == c:
            cnt += 1
        ans[i] = cnt      
        cnt += 1
        dfs(u, v, ans[i])


dfs(0)
print(max(ans))
for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
a,b,V = map(int, input().split())
x = V/(a*a)

def f(theta):
    if np.tan(theta) < (2*x)/a:
        l = x + a*np.tan(theta)/2
    else:
        l = (2*a*x*np.tan(theta))**0.5
    return l >= b


eps = 10**-12
def  binarySearch(l,r):
    while r - l > eps:
        mid = (l+r)/2
        if f(mid):
            r = mid
        else:
            l = mid
    return r

print(binarySearch(-1*np.pi/180,(np.pi/2-eps))*180/np.pi)


Fixed submission:
import numpy as np
a,b,V = map(int, input().split())
x = V/(a*a)
if b >= 2*x:
    tan = b**2/(2*a*x)
else:
    tan = 2*(b-x)/a
ans = np.arctan(tan)
print(ans*180/np.pi)