Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03806 (python)

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

N, Ma, Mb = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 15
dp = [[INF for j in range(401)] for i in range(401)]
dp[0][0] = 0

for a, b, c in ABC:
  for i in range(400, -1, -1):
    for j in range(400, -1, -1):
      if dp[i][j] != INF:
        dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

answer = INF
for i in range(1, 401):
  for j in range(1, 401):
    if dp[i][j] != INF and i / j == Ma / Mb:
      answer = min(answer, dp[i][j])
      
print(answer if answer != INF else -1)

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

N, Ma, Mb = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(N)]

sumA = sum([ABC[i][0] for i in range(N)])
sumB = sum([ABC[i][1] for i in range(N)])

INF = 10 ** 15
dp = [[INF for j in range(sumA + 1)] for i in range(sumB + 1)]
dp[0][0] = 0

for a, b, c in ABC:
  for i in range(sumA, -1, -1):
    for j in range(sumB, -1, -1):
      if dp[i][j] != INF:
        dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

answer = INF
for i in range(1, sumA + 1):
  for j in range(1, sumB + 1):
    if dp[i][j] != INF and i / j == Ma / Mb:
      answer = min(answer, dp[i][j])
      
print(answer if answer != INF else -1)
Problem p03834 (python)

Fixed submission:
print(" ".join(input().split(",")))

Buggy submission (verdict: Runtime Error):
print(" ".jpin(input().split(",")))
Problem p02723 (python)

Fixed submission:
s = input()
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
if s[3] == s[4] and s[5] == s[6]:
  print("Yes")
else:
  print("No")
Problem p02552 (python)

Fixed submission:
if input() == "1":
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
print(int(not(bool(x))))
Problem p03315 (python)

Fixed submission:
s = input()

ans = 0

for i in range(4):
    if s[i] == '+':
        ans += 1
    else:
        ans -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  REP(i, 4) {
    if (s[i] == '+')
      ans++;
    else
      ans--;
  }
  print(ans);
  return 0;
}
Problem p03317 (python)

Fixed submission:
import math

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

a = list(map(int, input().split()))
n -= 1
k -= 1
ans = math.ceil(n / k)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

# n, k = map(int, input().split())

a = list(map(int, input().split()))
n -= 1
k -= 1
ans = (n + k - 1) // k

print(ans)
Problem p02552 (python)

Fixed submission:
x = input()
x = int(x)
# OUTPUTS
# Print 1 if input is equal to 0
if x == 0:
    print(1)
    exit()

# Print 0 if input is equal to 1
if x == 1:
    print(0)
    exit()

Buggy submission (verdict: Runtime Error):
x = int(x)
# OUTPUTS
# Print 1 if input is equal to 0
if x == 0:
    print(1)
    exit()

# Print 0 if input is equal to 1
if x == 1:
    print(0)
    exit()

Buggy submission (verdict: Runtime Error):
import sys

# User input
var = input("Please enter an integer: ")

# Error check 1: Is the input an integer?
try:
    val = int(var)
except ValueError:
    sys.exit('Input is not an integer') 

# Convert input to integer
var = int(var)

# Error check 2: Is the input within bounds?
if var > 1 or var < 0:
    sys.exit('Input is not within accepted bounds')

# OUTPUTS 
# Print 1 if input is equal to 0 
if var == 0:
    sys.exit('1') 
    
# Print 0 if input is equal to 1
if var == 1:
    sys.exit('0')
Problem p02661 (python)

Fixed submission:
N = int(input())
A = list()
B = list()
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort(reverse=True)
if N%2 == 1:
    print(B[(N+1)//2 - 1] - A[(N+1)//2 - 1] + 1)
else:
    print((B[(N+1)//2 - 1] - A[(N+1)//2 - 1]) + (B[(N+1)//2] - A[(N+1)//2]) + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list()
for _ in range(N):
    A, B = map(int, input().split())
    L.append((A, B))
L = sorted(L, key=lambda x: x[0])

if N%2 == 1:
    W = L[N//2]
    for l in range(N//2, -1, -1):
        if W[0] <= l[1]:
            W = (l[0], W[1])
        else:
            break
    for l in range(N//2, N):
        if l[0] <= W[1]:
            W = (W[0], l[1])
    print(W[1] - W[0] + 1)
else:
    W = L[N//2 - 1]
    V = L[N//2]
    ans = max(W[1] - W[0] + 1, V[1] - V[0] + 1)
    if W[1] >= V[0]:
        print(2*ans - 1)
    else:
        print(ans + 2)
Problem p02831 (python)

Fixed submission:
import fractions
A, B = map(int, input().split())
print(A*B//fractions.gcd(A, B))

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

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
print(A*B//math.gcd(A, B))
Problem p02847 (python)

Fixed submission:
import sys
S = input()
day = ["SAT","FRI","THU","WED","TUE","MON","SUN"]
for i in range(7):
    if S==day[i]:
        print(i+1)
        sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
A, B, X = map(int, input().split())
def ne(n):
    return A*n + B*len(str(n))
if ne(10**10) <= X:
    print(10**10)
    sys.exit()
high = 10**10
low = 0
ans = (high + low) // 2
while (low < high):
    if ans == 0:
        print(0)
        sys.exit()
    if ne(ans) <= X:
        if ne(ans+1) > X:
            print(ans)
            sys.exit()
        low = ans
    else:
        high = ans
    ans = (high + low) // 2
print(ans)
Problem p02915 (python)

Fixed submission:
N = int(input())
print(N**3)

Buggy submission (verdict: Runtime Error):
N = input(int())
print(N**3)
Problem p03017 (python)

Fixed submission:
N, A, B, C, D = map(int, input().split())
N-=1
A-=1
B-=1
C-=1
D-=1
S = input()

massesExist = True
overtakeFlag = False if C > D else True
proceedableFlag = True

if max(A, B, C, D) > N:
    massesExist = False

if not overtakeFlag:
    for i in range(B, D+1):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            overtakeFlag = True

for i in range(A, max(C, D)-1):
    if S[i]=="#" and S[i+1]=="#":
        proceedableFlag = False

if overtakeFlag and proceedableFlag and massesExist:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N, A, B, C, D = map(int, input().split())
N-=1
A-=1
B-=1
C-=1
D-=1
S = input()

massesExist = True
overtakeFlag = False if C > D else True
proceedableFlag = True

if max(A, B, C, D) > N:
    massesExist = False

for i in range(B, D+1):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
        overtakeFlag = True

for i in range(A, max(C, D)-1):
    if S[i]=="#" and S[i+1]=="#":
        proceedableFlag = False

if overtakeFlag and proceedableFlag and massesExist:
    print("Yes")
else:
    print("No")
Problem p02623 (python)

Fixed submission:
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = tuple(accumulate(AB[:N])), tuple(accumulate(AB[N:]))
    candidates = []
    for cum_x, cum_y in ((cum_A, cum_B), (cum_B, cum_A)):
        for i, x_time in enumerate(cum_x, 1):
            if x_time > K:
                candidates.append(0)
                break
            y_time = K - x_time
            candidates.append(i + bisect(cum_y, y_time))
    print(max(candidates))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# D - Sum of Divisors
from numba import njit


@njit
def solve(N):
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    return res


def main():
    N = int(input())
    print(solve(N))


if __name__ == "__main__":
    main()
Problem p02624 (python)

Fixed submission:
# D - Sum of Divisors
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# D - Sum of Divisors
from numba import njit


@njit
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()
Problem p02754 (python)

Fixed submission:
# B - Count Balls
def main():
    N, A, B = map(int, input().split())
    ans = N // (A + B) * A + min(A, N % (A + B))
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# C - Tax Increase
from math import floor


def calc(a: int, b: int) -> int:
    for i in range(1, 1010):
        if floor(i * 0.08) == a and floor(i * 0.1) == b:
            return i
    return -1


def main():
    A, B = map(int, input().split())
    print(calc(A, B))


if __name__ == "__main__":
    main()
Problem p02819 (python)

Fixed submission:
# ABC149C - Next Prime
def is_prime(n: int) -> bool:
    """
    Evaluate whether a number is prime or not.

    Args:
        n: a number to evaluate

    Returns: whether n is prime or not
    """
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            return False
    return True


def main():
    N = int(input())
    if N != 2 and N % 2 == 0:
        N += 1
    while not is_prime(N):
        N += 2
    print(N)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC149C - Next Prime
def is_prime_miller_rabin(n: int) -> bool:
    """Miller–Rabin primality test in O(k log^3 n).
    https://twitter.com/kiri8128/status/1241033090773860353
    https://www.wikiwand.com/en/Miller%E2%80%93Rabin_primality_test
    """
    # cut out small primes and 87% of composite numbers.
    if n < 2:
        return False
    elif n in {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67}:
        return True
    elif (
        n % 2 == 0
        or n % 3 == 0
        or n % 5 == 0
        or n % 7 == 0
        or n % 11 == 0
        or n % 13 == 0
        or n % 17 == 0
        or n % 19 == 0
        or n % 23 == 0
        or n % 29 == 0
        or n % 31 == 0
        or n % 37 == 0
        or n % 41 == 0
        or n % 43 == 0
        or n % 47 == 0
        or n % 53 == 0
        or n % 59 == 0
        or n % 61 == 0
        or n % 67 == 0
    ):
        return False

    # find the most suitable witnesses for n
    if n < 2_047:
        witnesses = [2]
    elif n < 1_373_653:
        witnesses = [2, 3]
    elif n < 9_080_191:
        witnesses = [31, 73]
    elif n < 25_326_001:
        witnesses = [2, 3, 5]
    elif n < 3_215_031_751:
        witnesses = [2, 3, 5, 7]
    elif n < 4_759_123_141:
        witnesses = [2, 7, 61]
    elif n < 1_122_004_669_633:
        witnesses = [2, 13, 23, 1662803]
    elif n < 2_152_302_898_747:
        witnesses = [2, 3, 5, 7, 11]
    elif n < 3_474_749_660_383:
        witnesses = [2, 3, 5, 7, 11, 13]
    elif n < 341_550_071_728_321:
        witnesses = [2, 3, 5, 7, 11, 13, 17]
    elif n < 3_825_123_056_546_413_051:
        witnesses = [2, 3, 5, 7, 11, 13, 17, 19, 23]
    elif n < 318_665_857_834_031_151_167_461:
        witnesses = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    else:  # precisely, n < 3_317_044_064_679_887_385_961_981 (3.3 * 10^24)
        witnesses = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]

    d = n - 1
    d = d // (d & -d)

    for a in witnesses:
        y = pow(a, d, n)
        if y == 1:
            continue
        t = d
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1:
                return False
            t <<= 1
    return True


def main():
    N = int(input())
    if N != 2 and N % 2 == 0:
        N += 1
    while not is_prime_miller_rabin(N):
        N += 2
    print(N)


if __name__ == "__main__":
    main()
Problem p02912 (python)

Fixed submission:
# ABC141D - Powerful Discount Tickets
from heapq import heapify, heappop, heappush


def main():
    N, M, *A = map(int, open(0).read().split())
    B = [-i for i in A]
    heapify(B)
    for _ in range(M):
        x = -heappop(B) >> 1
        heappush(B, -x)
    ans = -sum(B)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC141D - Powerful Discount Tickets
from heapq import heapify, heappop, heappush


def main():
    N, M, *A = map(int, open(0).read().split())
    H = [-i for i in A]
    heapify(H)
    pop_max, push_max = lambda: -heappop(H), lambda x: heappush(-x)
    for _ in range(M):
        x = pop_max()
        push_max(x // 2)
    ans = -sum(H)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC141
def main():
    N, M, *A = map(int, open(0).read().split())
    if N == 1:
        ans = A[0] >> M
        print(ans)
        return
    A.sort(reverse=1)
    A += [0, 0]
    cur, prev = 0, 0
    for _ in range(M):
        x, y = A[cur] >> 1, A[cur + 1] >> 1
        if x > y:
            A[cur] = x
        else:
            A[cur + 1] = y
        if A[cur + 2] >= A[cur]:
            cur += 1
    ans = sum(A)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC141
def main():
    N, M, *A = map(int, open(0).read().split())
    if N == 1:
        ans = A[0] >> M
        print(ans)
        return
    A.append(0), A.sort(reverse=1)
    cur, prev = 0, 0
    for _ in range(M):
        x, y = A[cur] >> 1, A[cur + 1] >> 1
        if x > y:
            A[cur] = x
        else:
            A[cur + 1] = y
        if A[cur + 2] >= A[cur]:
            cur += 1
    ans = sum(A)
    print(ans)


if __name__ == "__main__":
    main()
Problem p02954 (python)

Fixed submission:
# ABC136D - Gathering Children
def main():
    """
    RR..LLの部分列に分解
    それぞれの部分列のRL境界に子どもが集まる
    奇数マスの子は奇数マスに、偶数マスの子は偶数マスの境界に (10^100 % 2 == 0)
    境界以外は全て0
    """
    S = input().rstrip()
    n = len(S)
    cur, P = S[0], []  # p: partial strings
    for i in S[1:]:
        if cur[-1] == "L" and i == "R":
            P += [cur]
            cur = ""
        cur += i
    P += [cur]

    ans = []
    for p in P:
        e = len(p) // 2
        o = len(p) - e
        r_cnt = p.count("R")
        l_cnt = len(p) - r_cnt
        l_pos = p.index("L")
        l, r = (e, o) if l_pos % 2 == 0 else (o, e)
        ans += [0] * (r_cnt - 1) + [l] + [r] + [0] * (l_cnt - 1)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC136D - Gathering Children
def main():
    # children gather on the border of "RL"
    S = input()
    # decompose into partial strings (RR...LL)
    P = S.replace("LR", "L R").split
    ans = []
    for p in P:
        # children on even numbers -> even, odds -> odd
        e, o = len(p) // 2, len(p) // 2 + len(p) % 2
        l, r = (e, o) if p.index("L") % 2 == 0 else (o, e)
        ans += [0] * (p.count("R") - 1) + [l] + [r] + [0] * (p.count("L") - 1)
    print(*ans)


if __name__ == "__main__":
    main()
Problem p02984 (python)

Fixed submission:
# ABC133D - Rain Flows into Dams
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    X = [0] * N
    cur = sum(A) - 2 * sum(A[1::2])
    X[0] = cur
    for i, a in enumerate(A[:-1], 1):
        X[i] = a * 2 - cur
        cur = X[i]
    print(*X)
    


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC133D - Rain Flows into Dams
def main():
    # X_0 = sum(A) - 2 * sum(A[1::2]), X_i = 2Ai - X_{i-1}
    N, *A = map(int, open(0).read().split())
    X = [0] * N
    cur = sum(A) - 2 * sum(A[1::2])
    X[0] = cur
    for i, a in enumerate(A[:-1], 1):
        X[i] = a * 2 - cur
        cur = X[i]
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()
Problem p03038 (python)

Fixed submission:
# ABC127D - Integer Cards
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted([list(map(int, input().rstrip().split())) for _ in range(m)], key=lambda x:x[1], reverse=True)
ans = 0
idx = 0
flg = False
for i, j in lst:
    for _ in range(i):
        if idx < n and num[idx] < j:
            ans += j
            idx += 1
        else:
            flg = True
            break
    if flg:
        break
if idx < n:
    ans += sum(num[idx:])
print(ans)

Buggy submission (verdict: Runtime Error):
# ABC127D - Integer Cards
n, m = list(map(int, input().rstrip().split()))
num = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
ans = 0
for i in lst:
    num += [i[1]] * i[0]
print(sum(sorted(lst, reverse=True)[:n]))
Problem p03042 (python)

Fixed submission:
# ABC126B - YYMM or MMYY
s = input()
x, y = int(s[:2]), int(s[2:])
if 1 <= x <= 12:
    if 1 <= y <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= y <= 12:
        print("YYMM")
    else:
        print("NA")

Buggy submission (verdict: Runtime Error):
# ABC126B - YYMM or MMYY
s = input()
x, y = int(s[:2]), int(s[2:])
if x = 0 or y = 0:
    print("NA")
elif 1 <= x <= 12 and 1 <= y <= 12:
    print("AMBIGUOUS")
elif 1 <= x <= 12 and y <= 31:
    print("MMYY")
elif x <= 31 and 1 <= y <= 12:
    print("YYMM")
else:
    print("NA")
Problem p03053 (python)

Fixed submission:
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "#" else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(max(D))


if __name__ == "__main__":
    main()
Problem p03209 (python)

Fixed submission:
# ABC115D - Christmas
def burger(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    if x <= 1 + B[n - 1]:
        return burger(n - 1, x - 1)
    return burger(n - 1, x - 2 - B[n - 1]) + P[n - 1] + 1


def main():
    global B, P
    N, X = tuple(map(int, input().split()))
    B, P = [1], [1]  # burger, patty
    for i in range(N):
        B += [B[i] * 2 + 3]
        P += [P[i] * 2 + 1]
    ans = burger(N, X)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC115D - Christmas
def burger(n):
    x = "P"
    for i in range(n):
        x = "B" + x + "P" + x + "B"
    return x


def main():
    N, X = tuple(map(int, input().split()))
    n_burger = burger(N)[:X]
    ans = n_burger.count("P")
    print(ans)


if __name__ == "__main__":
    main()
Problem p03221 (python)

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

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in ans:
    print(i)

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

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)

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

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)
print(*ans, sep="\n")
Problem p03634 (python)

Fixed submission:
# ABC070D - Transit Tree Path
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def dfs(v: int, p: int) -> None:
    d = dist[v]
    for u, c in G[v]:  # search vertices available from v recursively
        if u != p:  # p: parent
            dist[u] += d + c  # dist(K, v) + dist(v, u) == d + c
            dfs(u, v)


def main():
    global G, dist
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    Q, K = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(Q))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx
    for v, u, c in E:  # construct a graph
        G[v] += [(u, c)]
        G[u] += [(v, c)]
    dist = [0] * (N + 1)  # distance from vertex K
    dfs(K, -1)
    ans = [dist[x] + dist[y] for x, y in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC070D - Transit Tree Path
import sys
input = sys.stdin.readline

def dfs(v: int, p: int) -> None:
    d = dist[v]
    for u, c in G[v]:  # search vertices available from v recursively
        if u != p:  # p: parent
            dist[u] += d + c  # dist(K, v) + dist(v, u) == d + c
            dfs(u, v)


def main():
    global G, dist
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    Q, K = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(Q))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx
    for v, u, c in E:  # construct a graph
        G[v] += [(u, c)]
        G[u] += [(v, c)]
    dist = [0] * (N + 1)  # distance from vertex K
    dfs(K, -1)
    ans = [dist[x] + dist[y] for x, y in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()