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

Fixed submission:
a=int(input())
print((a//2)*((a+1)//2))

Buggy submission (verdict: Runtime Error):
print(int((int(input()/2))**2))

Buggy submission (verdict: Runtime Error):
print(int((int(input()/2))**2))

Buggy submission (verdict: Runtime Error):
a=int(input());x=n//2;print((n-x)*x)
Problem p03369 (python)

Fixed submission:
print(700+100*input().count('o'))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print([a,a-1][a>b])
Problem p03423 (python)

Fixed submission:
print(int(input())//3)

Buggy submission (verdict: Runtime Error):
ptint(int(input())//3)
Problem p03455 (python)

Fixed submission:
a,b=map(int,input().split())
if a*b%2==0:
    print ("Even")
else :
    print ("Odd")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split());print(["Even","Odd"][a*b%2]
Problem p03773 (python)

Fixed submission:
print(sum(map(int,input().split()))%24)

Buggy submission (verdict: Runtime Error):
print(eval(int,input().replace(" ","+"))%24)
Problem p03795 (python)

Fixed submission:
n=int(input());print(n*800-n//15*200)

Buggy submission (verdict: Runtime Error):
n=input();print n*800-n//15*200
Problem p04029 (python)

Fixed submission:
n=int(input());print(n*(n+1)//2)

Buggy submission (verdict: Runtime Error):
n=int(input());print(n(n+1)//2)
Problem p02642 (python)

Fixed submission:
from collections import Counter
n = int(input())
A = sorted(map(int, input().split()))

c = Counter(A)

yes_or_no = [True for i in range(A[n-1]+1)]

for a in A:
  t = a*2
  while t <= A[n-1]:
    yes_or_no[t] = False
    t += a
ans = 0
for a in A:
  if c[a] == 1 and yes_or_no[a] == True:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
A = sorted(map(int, input().split()))

c = Counter(A)

yes_or_no = [1 for i in range(A[n-1])]

for a in A:
  t = a*2
  while t <= A[n-1]:
    yes_or_no[t] = 0
    t += a
ans = 0
for a in A:
  if c[a] == 1 and yes_or_no[a] == 1:
    ans += 1
print(ans)
Problem p03196 (python)

Fixed submission:
n, p = map(int, input().split())
if n==1:
  print(p)
  exit()
elif p==1 or n>=60:
  print(1)
  exit()
for i in range(int(p**(1/n))+1, 0, -1):
  if p%(i**n)==0:
    print(i)
    exit()

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
if n==1:
  print(p)
  exit()
elif p==1 or n>=60:
  print(1)
  exit()
for i in range(int(p**(1/n))+1)[0::-1]:
  if p%(i**n)==0:
    print(i)
    exit()

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
if n==1:
  print(p)
  exit()
if p==1:
  print(1)
  exit()
for i in range(round(p**(1/n)))[0::-1]:
  if p%(i**n)==0:
    print(i)
    exit()

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
if n==1:
  print(p)
  exit()
for i in range(round(p**(1/n)))[::-1]:
  if p%(i**n)==0:
    print(i)
    exit()

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())
if n==1:
  print(p)
  exit()
for i in range(round(p**(1/n)))[0::-1]:
  if p%(i**n)==0:
    print(i)
    exit()
Problem p02642 (python)

Fixed submission:
n = int(input())

a = list(map(int, input().split()))
a.sort()

c = [0] * (10**6+1)
for i in a:
    c[i] += 1

uni = []
a = list(set(a))

for i in a:
    if c[i] == 1:
        uni.append(i)

b = [0 for _ in range(10**6+1)]

for i in a:
    for j in range(i*2, 10**6+1, i):
        b[j] = 1

cnt = 0
for i in uni:
    if b[i] == 0:
        cnt += 1

print(cnt)

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

n = int(input())

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

a.sort()
cnt = 0

for i in range(n):
    for j in range(i+1):
        if i==0 and a[i] == a[i+1]:
            cnt += 1
            break
        if a[i]%a[j]==0 and i!=j:
            cnt += 1
            break

print(n-cnt)
Problem p02690 (python)

Fixed submission:
x = int(input())

import math

for a in range(-int(math.pow(x,1./3.)),int(math.pow(x,1./3.))+1):
    for b in range(-int(math.pow(x,1./3.))+1,int(math.pow(x,1./3.))+1):
        if a!=b:
            if x/(a-b) == a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b:
                print(a,b)
                break
    else:
        continue
    break

Buggy submission (verdict: Runtime Error):
for a in range(-int(math.pow(x,1./3.)),int(math.pow(x,1./3.))+1):
    for b in range(-int(math.pow(x,1./3.))+1,int(math.pow(x,1./3.))+1):
        if a!=b:
            if x/(a-b) == a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b:
                print(a,b)
                break
    else:
        continue
    break
Problem p02700 (python)

Fixed submission:
X = list(map(int,input().split()))

A = X[0]
B = X[1]
C = X[2]
D = X[3]


n = 0
while C>0:
  C = C-B
  n += 1

m = 0
while A>0:
  A = A-D
  m += 1

if n<=m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
C = X[2]
D = X[3]


n = 0
while C>0:
  C = C-B
  n += 1

m = 0
while A>0:
  A -= D
  m += 1
print(n,m)
if n<=m:
  print("Yes")
else:
  print("No")
Problem p02713 (python)

Fixed submission:
import math
 
N=int(input())
 
A = 0
for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      A += math.gcd(math.gcd(i,j),k)

print(A)

Buggy submission (verdict: Runtime Error):
import math

N=int(input())

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A = 0
for i in N:
  for j in N:
    for k in N:
      l = gcd_list(i,j,k)
  A += l
print(A)
Problem p02732 (python)

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

from collections import Counter

cnt = Counter(a)
b = set(a)
c = 0
for i in b:
    c += cnt[i]*(cnt[i]-1)//2

for i in a:
    print(c-cnt[i]+1)

Buggy submission (verdict: Runtime Error):
from collections import Counter

cnt = Counter(a)
b = set(a)
c = 0
for i in b:
    c += cnt[i]*(cnt[i]-1)//2

for i in a:
    print(c-cnt[i]+1)
Problem p02837 (python)

Fixed submission:
import itertools

n = int(input())

l = list(itertools.product([0,1], repeat=n))[::-1]

A = {}
for i in range(n):
    ai = int(input())
    for j in range(ai):
        x, y = map(int, input().split())
        if i not in A:
            A[i] = []
        A[i].append((x, y))
    if ai == 0:
        A[i] = []


def shoujiki(i):
    check = {}
    cnt = 0
    for j in range(n):
        check[j+1] = i[j]
    for j in range(n):
        ai = len(A[j])
        if i[j] == 1:
            for k in range(ai):
                x, y = A[j][k]
                if check[x] != y:
                    return 0
    #return (check, shougen, cnt0, cnt)
    return sum(i)

mans = 0
for i in l:
    mans = max(shoujiki(i), mans)

print(mans)

Buggy submission (verdict: Runtime Error):
import itertools

n = int(input())

l = list(itertools.product([0,1], repeat=n))[::-1]

A = {}
for i in range(n):
    ai = int(input())
    for j in range(ai):
        x, y = map(int, input().split())
        if i not in A:
            A[i] = []
        A[i].append((x, y))

def shoujiki(i):
    check = {}
    cnt = 0
    for j in range(n):
        check[j+1] = i[j]
    for j in range(n):
        ai = len(A[j])
        if i[j] == 1:
            for k in range(ai):
                x, y = A[j][k]
                if check[x] == y:
                    cnt += 1
                else:
                    return 0
    return cnt

mans = 0
for i in l:
    mans = max(shoujiki(i), mans)

print(mans)
Problem p03386 (python)

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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
r = range(a,b+1)
l = list(r)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
r = range(a,b+1)
l = list(r)
ans = sorted(set(l[:k] + l[len(l)-k:]))

print(*ans, sep = "\n", end = "")

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))
ans = sorted(set(l[:k] + l[len(l)-k:]))

print(*ans, sep = "\n", end = "")

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))

ans = sorted(set(l[:k] + l[len(l)-k:]))

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))

ans = sorted(set(l[:k] + l[len(l)-k:]))

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
s = list(map(int, input().split()))
l = list(range(s[0],s[1]+1))

ans = sorted(set(l[:s[2]] + l[len(l)-s[2]:]))

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
s = list(map(int, input().split()))
l = list(range(s[0],s[1]+1))

ans = set(l[:s[2]] + l[len(l)-s[2]:])

for i in ans:
    print(i)
Problem p03448 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0

for i in range(c+1):
    for j in range(b+1):
        if (x-50*i-100*j)%500==0 and ((x-50*i-100*j)/500)<=a and ((x-50*i-100*j)/500)>=0:
            cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "A = int(input())\n",
    "B = int(input())\n",
    "C = int(input())\n",
    "X = int(input())\n",
    "res=0\n",
    "for  i in range(A + 1):\n",
    "    for j in range(B + 1):\n",
    "        for k in range(C + 1):\n",
    "            if 500*i + 100*j + 50*k == X:\n",
    "                res += 1\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a*B % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())
if (a*B)%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b = int(input())
c = a*B
if c%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
print(b)

Buggy submission (verdict: Runtime Error):
print(a)
Problem p02764 (python)

Fixed submission:
import math

n, k = map(int, input().split())
x, y, c = zip(*[map(int, input().split()) for _ in range(n)])
que = [(0, 0, 1000)]
res = 1e9
i = 0
while i < len(que):
    px, py, r = que[i]
    i += 1
    lb = [c[j] * math.hypot(max(abs(px - x[j]) - r, 0), max(abs(py - y[j]) - r, 0)) for j in range(n)]
    if res * (1 - 5e-7) > sorted(lb)[k - 1]:
        dis = [c[j] * math.hypot(px - x[j], py - y[j]) for j in range(n)]
        res = min(res, sorted(dis)[k - 1])
        for dx in (-0.5, 0.5):
            for dy in (-0.5, 0.5):
                que.append((px + dx * r, py + dy * r, r / 2))
print(res)

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())
x, y, c = zip(*[map(int, input().split()) for _ in range(n)])
que = [(0, 0, 1000)]
res = 1e9
i = 0
while i < len(que):
    px, py, r = que[i]
    i += 1
    lb = [c[j] * math.hypot(max(abs(px - x[j]) - r, 0), max(abs(py - y[j]) - r, 0)) for j in range(n)]
    if 1 - sorted(lb)[k - 1] / res > 5e-7:
        dis = [c[j] * math.hypot(px - x[j], py - y[j]) for j in range(n)]
        res = min(res, sorted(dis)[k - 1])
        for dx in (-0.5, 0.5):
            for dy in (-0.5, 0.5):
                que.append((px + dx * r, py + dy * r, r / 2))
print(res)
Problem p03447 (python)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())

print((x - a) % b)

Buggy submission (verdict: Runtime Error):
import sys


def main():
    n, m = map(int, sys.stdin.readline().split())
    g = [[] for i in range(n)]
    for i in range(m):
        l, r, d = map(int, sys.stdin.readline().split())
        g[l - 1].append((r - 1, d))
        g[r - 1].append((l - 1, -d))
    dis = [0] * n
    visited = [False] * n
    for i in range(n):
        if visited[i]:
            continue
        stack = list([i])
        visited[i] = True
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if not visited[u]:
                    dis[u] = dis[v] + d
                    stack.append(u)
                    visited[u] = True
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
    n, m = map(int, input().split())
    g = [[] for i in range(n)]
    lines = sys.stdin.read().splitlines()
    for i in range(m):
        l, r, d = map(int, lines[i].split())
        g[l - 1].append((r - 1, d))
        g[r - 1].append((l - 1, -d))
    dis = [0] * n
    visited = [False] * n
    for i in range(n):
        if visited[i]:
            continue
        stack = list([i])
        visited[i] = True
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if not visited[u]:
                    dis[u] = dis[v] + d
                    stack.append(u)
                    visited[u] = True
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()
Problem p02665 (python)

Fixed submission:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if n == 0:
    print([-1, 1][a[0] == 1])
    exit()
if a[0] > 0:
    print(-1)
    exit()
s = sum(a)
ans = 1
dp = [0] * (n + 1)
dp[0] = 1
for i in range(n):
    dp[i + 1] = min(s, 2 * dp[i])
    ans += dp[i + 1]
    dp[i + 1] -= a[i + 1]
    s -= a[i + 1]
    if dp[i] <= 0:
        print(-1)
        exit()
if dp[-1] < 0:
    print(-1)
    exit()
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if n < 30 and a[-1] > (1 << n):
    print(-1)
    exit()
for i in range(min(n, 30)):
    if a[i] > (1 << i) - 1:
        print(-1)
        exit()
s = sum(a)
ans = 1
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    dp[i] = min(s, 2 * dp[i - 1])
    ans += dp[i]
    dp[i] -= a[i]
    if dp[i] < 0:
        print(-1)
        exit()
    s -= a[i]
ans += a[-1]
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if a[-1] > (1 << n):
    print(-1)
    exit()
for i in range(min(n, 30)):
    if a[i] > (1 << i) - 1:
        print(-1)
        exit()
s = sum(a)
ans = 1
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    dp[i] = min(s, 2 * dp[i - 1])
    ans += dp[i]
    dp[i] -= a[i]
    s -= a[i]
ans += a[-1]
print(ans)
Problem p02702 (python)

Fixed submission:
#!/usr/bin/env python3
s = input()[::-1]
n = len(s)
cs = [0] * (n + 1)
ten = 1
for i in range(n):
    cs[i + 1] = int(s[i]) * ten % 2019
    ten = ten * 10 % 2019
for i in range(n):
    cs[i + 1] = (cs[i + 1] + cs[i]) % 2019
cnt = [0] * 2019
for i, x in enumerate(cs):
    cnt[x] += 1
ans = sum(x * (x - 1) // 2 for x in cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
s = input()
n = len(s)
ans = 0
cs = [0] * (n + 1)
cs[1] = cs[0] + int(s[0])
cs[2] = cs[1] + int(s[1])
cs[3] = cs[2] + int(s[2])
for i in range(n):
    for j in range(i + 3, n + 1):
        if i == 0 and j < n:
            cs[j + 1] = cs[j] + int(s[j])
        if (cs[j] - cs[i]) % 3 != 0:
            continue
        k = int(s[i:j])
        if k % 2019 == 0:
            ans += 1
print(ans)
Problem p02721 (python)

Fixed submission:
#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.count("o") == k:
        for i in range(n):
            if s[i] == "o":
                print(i + 1)
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.cnt("o") == k:
        print(*range(1, n + 1), sep="\n")
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)
Problem p02838 (python)

Fixed submission:
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<= 1
    c = sum(a[i] >> b & 1 for i in range(n))
    ans = (ans + c * (n - c)) % MOD
print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct ModInt {
  using M = ModInt;
  long long v;
  ModInt(long long _v = 0) : v(_v % MOD + MOD) { norm(); }
  M& norm() {
    v = (v < MOD) ? v : v - MOD;
    return *this;
  }
  M operator+(const M& x) const { return M(v + x.v); }
  M operator-(const M& x) const { return M(v + MOD - x.v); }
  M operator*(const M& x) const { return M(v * x.v % MOD); }
  M operator/(const M& x) const { return M(v * x.inv().v); }
  M& operator+=(const M& x) { return *this = *this + x; }
  M& operator-=(const M& x) { return *this = *this - x; }
  M& operator*=(const M& x) { return *this = *this * x; }
  M& operator/=(const M& x) { return *this = *this / x; }
  friend istream& operator>>(istream& input, M& x) {
    return input >> x.v, x.norm(), input;
  }
  friend ostream& operator<<(ostream& output, const M& x) {
    return output << x.v;
  }
  M pow(long long n) const {
    M x(v), res(1);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  M inv() const { return this->pow(MOD - 2); }
  // M inv() const {
  //   int x, y;
  //   extgcd(this->v, MOD, x, y);
  //   return *this + M(x);
  // }

  static long long MOD;
  static vector<M> fact, finv;
  static void build(int n) {
    fact.assign(n + 1, 1);
    for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
    finv.assign(n + 1, fact[n].inv());
    for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * M(i);
  }
  static M comb(int n, int k) {
    if (n < k || k < 0) return M(0);
    return fact[n] * finv[n - k] * finv[k];
  }
  static M extgcd(int a, int b, int* x, int* y) {
    M d(a);
    if (b) {
      d = extgcd(b, a % b, y, x);
      *y -= (a / b) * *x;
    } else {
      *x = 1, *y = 0;
    }
    return d;
  }
};
vector<ModInt> ModInt::fact = vector<ModInt>();
vector<ModInt> ModInt::finv = vector<ModInt>();
long long ModInt::MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> o(120, vector<int>(n + 1, 0));
  vector<vector<int>> x(120, vector<int>(n + 1, 0));
  for (int b = 0; b < 120; b++) {
    for (int i = 0; i < n; i++) {
      o[b][i + 1] += o[b][i];
      x[b][i + 1] += x[b][i];
      if (a[i] >> min(60, b) & 1) {
        o[b][i + 1]++;
      } else {
        x[b][i + 1]++;
      }
    }
  }
  vector<ll> v(120);
  ll nxt = 0;
  for (int b = 0; b < 120; b++) {
    ll c = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] >> min(60, b) & 1) {
        c += x[b][i];
      } else {
        c += o[b][i];
      }
    }
    v[b] = (nxt + c) % 2;
    nxt = (nxt + c) / 2;
  }
  ModInt ans = 0;
  for (int b = 119; b >= 0; b--) {
    ans *= 2;
    ans += v[b];
  }
  cout << ans << endl;
}
Problem p02850 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)


def f(a, b):
    return (a, b) if a < b else (b, a)


def dfs(s, p):
    used = {}
    for t in g[s]:
        idx = rev[f(s, t)]
        if ans[idx] > 0:
            used[ans[idx]] = True 
    c = 1
    for t in g[s]:
        idx = rev[f(s, t)]
        if t == p or ans[idx] > 0:
            continue
        while c in used:
            c += 1
        ans[idx] = c
        c += 1
        dfs(t, s)
        

n = int(input())
g = [[] for _ in range(n)]
rev = {}
for i in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)
    rev[(a, b)] = i
ans = [0] * (n - 1)
dfs(0, -1)
print(max(ans), *ans, sep='\n')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3


def f(a, b):
    return (a, b) if a < b else (b, a)


def dfs(s, p):
    for k, t in enumerate(g[s]):
        idx = rev[f(s, t)]
        if t == p or ans[idx] > 0:
            continue
        ans[idx] = k + 1
        dfs(t, s)

n = int(input())
g = [[] for _ in range(n)]
rev = {}
for i in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)
    rev[(a, b)] = i
ans = [0] * (n - 1)
dfs(0, -1)
print(max(ans), *ans, sep='\n')
Problem p02866 (python)

Fixed submission:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    exit()
c = Counter(d)
if c[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, len(c)):
    if c[i] == 0:
        print(0)
        exit()
    ans *= c[i - 1]**c[i]
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using T = tuple<int, int, int>;

template <typename T>
struct Dijkstra {
  struct Edge {
    int to;
    T cost;
  };
  vector<int> prev;
  vector<vector<Edge>> g;
  Dijkstra(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
  }
  vector<T> build(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  Dijkstra<ll> g(n);
  for (int i = 0; i < n - 2; i++) {
    g.addEdge(i + 1, i, 0);
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c, l--, r--;
    g.addEdge(l, r, c);
  }
  auto d = g.build(0);
  cout << ((d[n - 1] >= 0) ? d[n - 1] : -1) << endl;
}