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

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

d.sort()
left = d[int(N/2-1)]
right = d[int(N/2)]

dif = right - left

print(dif)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(map(int, input().split()))

d.sort()

left = d[int(N/2)]
right = d[int(N/2) +1]

dif = right - left

print(dif)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(map(int, input().split()))

d.sort()

left = d[N//2]
right = d[N//2 +1]

dif = right - left

print(dif)
Problem p02594 (python)

Fixed submission:
x = int(input())
if x >= 30:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
x = int(input())
if x >= 30:
    print("Yes")
    else:
        print("No")
Problem p02595 (python)

Fixed submission:
[N, D] = input().split()
s = 0
N = int(N)
D = int(D)
D = D**2
for i in range(N):
    [X, Y] = input().split()
    X = int(X)
    Y = int(Y)
    Z = X**2 + Y**2
    if Z <= D:
        s += 1
print(s)

Buggy submission (verdict: Runtime Error):
[N, D] = input().split()
s = 0
D = int(D)
D = D**2
for i in range(N):
    [X, Y] = input().split()
    X = int(X)
    Y = int(Y)
    Z = X**2 + Y**2
    if Z <= D:
        s += 1
print(s)

Buggy submission (verdict: Runtime Error):
[N, D] = input().split()
s = 0
D = int(D)
for i in range(N):
    [X, Y] = input().split()
    X = int(X)
    Y = int(Y)
    Z = X**2 + Y**2
    if Z <= D**2:
        s +=1
print(s)

Buggy submission (verdict: Runtime Error):
[N, D] = input().split()
s = 0
D = int(D)
for i in range(N):
    [X, Y] = input().split()
    X = int(X)
    Y = int(Y)
    Z = X**2 + Y**2
    if Z <= D:
        s +=1
print(s)
Problem p02547 (python)

Fixed submission:
n = int(input())
conseq = 0
ans = False
for i in range(n):
  d1,d2 = map(int,input().split())
  if d1 == d2:
    conseq += 1
    if conseq >= 3:
      ans = True
  else:
    conseq = 0

if ans:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
ans = False
for i in range(n):
  d1,d2 = map(int,input().split())
  if d1 == d2:
    conseq += 1
    if conseq >= 3:
      ans = True
  else:
    conseq = 0

if ans:
  print('Yes')
else:
  print('No')
Problem p02572 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
 
mod = 10**9+7
sum_a = sum(a)%mod
sum_a2 = sum_a**2%mod
 
for i in range(n):
    sum_a2 -= (a[i]**2)%mod
    sum_a2 %= mod
    
if sum_a2%2 == 0:
    ans = sum_a2//2
else:
    ans = ((sum_a2+mod)//2)%mod

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

mod = 10**9+7
sum_a = sum(a)%mod
sum_a2 = sum_a**2%mod

for i in range(n):
    sum_a2 -= (a[i]**2)
    sum_a2 %= mod
    
if sum_a2%2 == 0:
    ans = sum_a2//2
else:
    ans = ((ans+mod)//2)%mod

print(ans)
Problem p02580 (python)

Fixed submission:
H,W,M = map(int,input().split())

horizontal = [[i,0] for i in range(H)]
vertical = [[i,0] for i in range(W)]
table = {}

for i in range(M):
    h,w = map(int,input().split())
    h -= 1
    w -= 1
    table[(h,w)] = True
    vertical[w][1] += 1
    horizontal[h][1] += 1

vertical.sort(key=lambda x:-x[1])
horizontal.sort(key = lambda x:-x[1])

h_max = horizontal[0][1]
v_max = vertical[0][1]
    
for i in range(H):
    if horizontal[i][1]<h_max:
        i -= 1
        break
for j in range(W):
    if vertical[j][1]<v_max:
        j -= 1
        break

flag = False
for h in horizontal[:i+1]:
    for v in vertical[:j+1]:
        if table.get((h[0],v[0]))==None:
            flag = True
            break
    if flag:
        break

if flag:
    print(h_max+v_max)
else:
    print(h_max+v_max-1)

Buggy submission (verdict: Runtime Error):
H,W,M = map(int,input().split())

horizontal = [[i,0] for i in range(H)]
vertical = [[i,0] for i in range(W)]
table = [[0]*W for _ in range(H)]

for i in range(M):
    h,w = map(int,input().split())
    h -= 1
    w -= 1
    table[h][w] = 1
    vertical[w][1] += 1
    horizontal[h][1] += 1

vertical.sort(key=lambda x:-x[1])
horizontal.sort(key = lambda x:-x[1])

h_max = horizontal[0][1]
v_max = vertical[0][1]
    
for i in range(H):
    if horizontal[i][1]<h_max:
        break
for j in range(W):
    if vertical[j][1]<v_max:
        break

flag = False
for h in horizontal[:i]:
    for v in vertical[:j]:
        if table[h[0]][v[0]] == 0:
            flag = True
            break
    if flag:
        break

if flag:
    print(h_max+v_max)
else:
    print(h_max+v_max-1)

Buggy submission (verdict: Runtime Error):
H,W,M = map(int,input().split())

horizontal = [[i,0] for i in range(H)]
vertical = [[i,0] for i in range(W)]
table = [[0]*W for _ in range(H)]

for i in range(M):
    h,w = map(int,input().split())
    h -= 1
    w -= 1
    table[h][w] = 1
    vertical[w][1] += 1
    horizontal[h][1] += 1

vertical.sort(key=lambda x:-x[1])
horizontal.sort(key = lambda x:-x[1])

h_max = horizontal[0][1]
v_max = vertical[0][1]
    
for i in range(H):
    if horizontal[i][1]<h_max:
        break
for j in range(W):
    if vertical[j][1]<v_max:
        break

flag = False
for h in horizontal[:i]:
    for v in vertical[:j]:
        if table[h[0]][v[0]] == 0:
            print(h,v)
            flag = True
            break
    if flag:
        break

if flag:
    print(h_max+v_max)
else:
    print(h_max+v_max-1)
Problem p02596 (python)

Fixed submission:
k = int(input())

flag = False

resid  = 7
if resid%k==0:
    i = -1
    flag = True
else:
    for i in range(k):
        resid = (resid*10+7)%k
        if resid == 0:
            flag = True
            break

if flag:
    print(i+2)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
k = int(input())

import fractions

flag = False

for i in range(n):
    f = fractions.gcd(k,(10**n-1)/9*7)
    if f == k:
        flag = True
        break

if flag:
    print(i+1)
else:
    print(-1)
Problem p02659 (python)

Fixed submission:
a,b = input().split()
a = int(a)
b100 = int(b[0])*100+int(b[2])*10+int(b[3])

print((a*b100)//100)

Buggy submission (verdict: Runtime Error):
a,b = input().split()
a = int(a)
b = int(b*100)

print((a*b)//100)
Problem p02793 (python)

Fixed submission:
import fractions
from functools import reduce

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

x = lcm_list(a)
ans = 0

for i in a:
    ans += (x//i)
ans %= 1000000007

print(ans)

Buggy submission (verdict: Runtime Error):
import fraction
from functools import reduce

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

def lcm_base(x, y):
    return (x * y) // fraction.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

x = lcm_list(a)
ans = 0

for i in a:
    ans += (x//i)
    ans %= 1000000007

print(ans)

Buggy submission (verdict: Runtime Error):
import fraction
from functools import reduce

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

def lcm_base(x, y):
    return (x * y) // fraction.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

x = lcm_list(a)
ans = 0

for i in a:
    ans += (x//x)
    ans %= 1000000007

print(ans)
Problem p02757 (python)

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,p = nm()
s = list(map(int, list(ns())))
ans = 0
if p == 2:
  for i in range(n):
    if s[i]%2 == 0:
      ans += i+1
  print(ans); exit(0)
if p == 5:
  for i in range(n):
    if s[i]%5 == 0:
      ans += i+1
  print(ans); exit(0)
   
g = [0]*(n+1)
d = [0]*p
d[0] = 1
t = 1
for i in range(n-1,-1,-1):
    g[i] = (g[i+1] + s[i]*t)%p
    ans += d[g[i]]
    d[g[i]] += 1
    t = (t*10)%p
print(ans)

Buggy submission (verdict: Runtime Error):
n,p = map(int, input().split())
s = list(map(int, list(ns())))
if p in (2, 5):
  print(sum(i+1 for i in range(n) if s[i]%p == 0))
  exit(0)
   
ans = g = 0
d = [0]*p
d[0] = 1
t = 1
for i in range(n-1,-1,-1):
    g = (g + s[i]*t)%p
    ans += d[g]
    d[g] += 1
    t = (t*10)%p
print(ans)
Problem p03011 (python)

Fixed submission:
l = list(map(int,input().split()))
print(sum(l)-max(l))

Buggy submission (verdict: Runtime Error):
l = map(int,input().split())
print(sum(*l)-max(*l))

Buggy submission (verdict: Runtime Error):
l = map(int,input().split())
print(sum(l)-max(l))

Buggy submission (verdict: Runtime Error):
l* = map(int,input().split())
print(sum(l)-max(l))
Problem p03053 (python)

Fixed submission:
from collections import deque
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = [(0,1),(1,0),(0,-1),(-1,0)]
q = deque()
cnt = h*w
t = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      q.append((i,j))
      a[i][j] = 0
      cnt -= 1
while cnt:
  y,x = q.popleft()
  for dx,dy in d:
    if 0 <= x+dx < w and 0 <= y+dy < h and a[y+dy][x+dx] == ".":
      a[y+dy][x+dx] = a[y][x] + 1
      cnt -= 1
      q.append((y+dy,x+dx)) 
for i in range(h):
  m = max(a[i])
  t = max(t,m)
print(t)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = [(0,1),(1,0),(0,-1),(-1,0)]
q = deque()
cnt = h*w
t = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      q.append((i,j))
      a[i][j] = 0
      cnt -= 1
for _ in range(cnt):
  y,x = q.popleft()
  for dx,dy in d:
    if 0 <= x+dx < w and 0 <= y+dy < h and a[y+dy][x+dx] == ".":
      a[y+dy][x+dx] = a[y][x] + 1
      q.append((y+dy,x+dx)) 
for i in range(h):
  m = max(a[i])
  t = max(t,m)
print(t)
Problem p03055 (python)

Fixed submission:
n = int(input())
l = [list() for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

def dfs(p):
  dep = [None]*n
  dep[p] = 0
  q = [p]
  while q:
    v = q.pop()
    for x in l[v]:
      if dep[x] is None:
        dep[x] = dep[v] + 1
        q.append(x)
  return dep
      
dep = dfs(0)
p = dep.index(max(dep))
dep = dfs(p)
q = max(dep)-1
print("First" if q%3 else "Second")

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [list() for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

dep = [n]*n
def dfs(v,t,p):
  dep[v] = t
  for x in l[v]:
    if x == p:
      continue
    dfs(x,t+1,v)
  return

dfs(0,0,-1)
p = dep.index(max(dep))
dep = [n]*n
dfs(p,0,-1)
q = max(dep)-1
print("First" if q%3 else "Second")
Problem p03135 (python)

Fixed submission:
x, t = map(int, input().split())
print(x/t)

Buggy submission (verdict: Runtime Error):
x, t = = map(int, input().split())
print(x/t)
Problem p03137 (python)

Fixed submission:
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
y = list()
for i in range(m-1):
    y.append(x[i+1]-x[i])
y.sort(reverse=True)
print(x[-1]-x[0]-sum(y[:n-1]))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
y =[x[i+1] - x[i] for i in range(m-1)]
a=[0]
for i in range(n-1):
    a.append(y.index(max(y)) + 1)
    y[y.index(max(y))] = 0
a.append(m)
s = 0
for i in range(n):
    s += x[a[i+1]-1]-x[a[i]]
print(s)
Problem p03209 (python)

Fixed submission:
def burg(lev,x):
  if lev <= 0:
    return int(x>0)
  if x <= 1:
    return 0
  if 1 < x < h[lev-1]+2:
    return burg(lev-1,x-1)
  if x == h[lev-1]+2:
    return p[lev-1] + 1
  if h[lev-1]+2 < x < h[lev]:
    return p[lev-1] + 1 + burg(lev-1,x-(h[lev-1]+2))
  if x >= h[lev]:
    return p[lev]

n,x = map(int, input().split())
h = [1]*(n+2)
p = [1]*(n+2)
for i in range(1,n+2):
  h[i] = h[i-1]*2 + 3
  p[i] = p[i-1]*2 + 1
print(burg(n,x))

Buggy submission (verdict: Runtime Error):
def burg(lev,x):
  if lev == 0:
    return x>0
  if x == 1:
    return 0
  if 1 < x <= h[lev-1]+1:
    return burg(lev-1,x-1)
  if x ==  h[lev-1]+2:
    return p[lev-1] + 1
  if h[lev-1]+3 <= x <= h[lev-1]*2 + 2:
    return p[lev-1] + 1 + burg(lev-1,x-(h[lev-1]+2))
  if x >= h[lev]:
    return paty[lev]

n,x = map(int, input().split())
h = [1]*(n+2)
p = [1]*(n+2)
for i in range(1,n+2):
  h[i] = h[i-1]*2 + 3
  p[i] = p[i-1]*2 + 1
print(burg(n,x))
Problem p03221 (python)

Fixed submission:
n,m = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(m)]
d = [list() for _ in range(n)]
dic = [dict() for _ in range(n)]
for x in l:
  d[x[0]-1].append(x[1])
for r in range(n):
  d[r].sort()
  dic[r] = dict(zip(d[r],range(1,len(d[r])+1)))
for x in l:
  p = x[0]
  y = dic[x[0]-1][x[1]]
  print("{:06}{:06}".format(p,y))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(m)]
d = [list() for _ in range(n)]
for x in l:
  d[x[0]-1].append(x[1])
for r in d:
  r.sort()
for x in l:
  p = x[0]
  y = d[x[0]-1].index(x[1]) + 1
  print("{:06}{:06}".format(p,y)
Problem p03275 (python)

Fixed submission:
class BIT:
    '''
    0-indexed
    '''
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)
        self.depth = n.bit_length()

    def _bitsum(self, i):
        ret = 0
        while i:
            ret += self.tree[i]
            i ^= i & -i
        return ret

    def bitsum(self, l, r=None): # [l, r)
        if r is None:
            return self._bitsum(l)
        else:
            return self._bitsum(r) - self._bitsum(l)

    def bitadd(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
        return

n = int(input())
m = n * (n + 1) // 4
a = list(map(int, input().split()))
d = dict()
_a = sorted(set(a + [0]))
for i, x in enumerate(_a):
  d[x] = i
a = [d[x] for x in a]


def check(X):
  b = [0] + [(y>=X)*2 - 1 for y in a]
  for i in range(n):
    b[i+1] += b[i]
  c = min(b)
  b = [x-c for x in b] 
  bit = BIT(max(b) + 2)
  ans = 0
  for x in b:
    ans += bit.bitsum(x + 1)
    bit.bitadd(x, 1)
  return ans >= m

t = [len(_a), 0]
while t[0] - t[1] > 1:
  mid = (t[0] + t[1]) // 2
  t[check(mid)] = mid
print(_a[t[1]])

Buggy submission (verdict: Runtime Error):
class BIT:
    '''
    0-indexed
    '''
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)
        self.depth = n.bit_length()

    def _bitsum(self, i):
        ret = 0
        while i:
            ret += self.tree[i]
            i ^= i & -i
        return ret

    def bitsum(self, l, r=None): # [l, r)
        if r is None:
            return self._bitsum(l)
        else:
            return self._bitsum(r) - self._bitsum(l)

    def bitadd(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
        return

n = int(input())
m = (n * (n - 1) // 2) // 2
a = list(map(int, input().split()))
d = dict()
_a = sorted(set(a))
for i, x in enumerate(_a):
  d[x] = i
a = [d[x] for x in a]


def check(X):
  b = [0] + [(y>=X)*2 - 1 for y in a]
  for i in range(n):
    b[i+1] += b[i]
  c = min(b)
  b = [x-c for x in b] 
  bit = BIT(n + 10)
  ans = 0
  for x in b:
    ans += bit.bitsum(x+1)
    bit.bitadd(x, 1)
  return ans >= m

t = [len(_a) + 1, -1]
while t[0] - t[1] > 1:
  mid = (t[0] + t[1]) // 2
  t[check(mid)] = mid
print(_a[t[1]])
Problem p03329 (python)

Fixed submission:
n = int(input())
ans = n
l9 = [9**i for i in range(6,0,-1)]
l6 = [6**i for i in range(7,-1,-1)]
for i in range(n//9+1):
  x9 = i*9
  x61= n-x9
  csum = 0
  for x in l9:
    csum += x9//x
    x9 %= x
  for x in l6:
    csum += x61//x
    x61 %= x
  if ans > csum:
    ans = csum
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = n
l9 = [9**i for i in range(6,0,-1)]
l6 = [6**i for i in range(7,-1,-1)]
for i in range(n//9+1):
  x9 = i*9
  x61= n-x9
  csum = 0
  for x in l9:
    csum += x9//x
    x9 %= x
  for x in x61:
    csum += x61//x
    x61 %= x
  if ans > csum:
    ans = csum
print(ans)
Problem p03332 (python)

Fixed submission:
n,a,b,k = map(int,input().split())
mod = 998244353
fun = [1]*(n+1)
for i in range(1,n+1):
  fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
  rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
  if r > n:
    return 0
  return fun[n]*rev[r]%mod*rev[n-r]%mod
ans = 0
for i in range(min(n,k//a)+1):
  j = (k-a*i)//b
  if i*a+j*b == k and 0<=j<=n:
    ans += nCr(n,i)*nCr(n,j)
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial as fac
def cc(n,r):
  return fac(n)//fac(r)//fac(n-r)
n, a, b, k = map(int, input().split())
mod = 998244353
for i in range(min(k//a+1,n+1)):
  j = k-a*i
  if j%b == 0 andj<=n:
    ans += cc(n,i)*cc(n,j)%mod
    ans %= mod
print(ans)
Problem p03430 (python)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
  s = list(ns())
  ls = len(s)
  lk = ni()
  dp = [[[0]*ls for _ in range(ls)] for i in range(2)]
  ans = 0
  for i in range(ls):
    dp[0][i][i] = 1
  for k in range(lk+1):
    v = k & 1
    for dis in range(1, ls):
      for i in range(ls - dis):
        j = i + dis
        dp[v][i][j] = 0
        if s[i] == s[j]:
          dp[v][i][j] = dp[v][i+1][j-1] + 2
        elif k:
          dp[v][i][j] = dp[v^1][i+1][j-1] + 2
        dp[v][i][j] = max(dp[v][i][j], dp[v][i+1][j], dp[v][i][j-1])
    ans = max(ans, dp[v][0][-1])

  print(ans)
  return

solve()

Buggy submission (verdict: Runtime Error):
s = list(map(ord, list(input())))
ls = len(s)
lk = int(input())
if lk*2 >= ls: print(ls); exit(0)
lk = 2*lk - ls%2
dp = [[[0]*(lk+1) for _ in range(ls+1)] for i in range(ls+1)]
for k in range(lk+1):
  for i in range(ls):
    for j in range(ls):
      if s[i] == s[-j-1]:
        dp[i+1][j+1][k] = max(dp[i+1][j+1][k], dp[i][j][k] + 1)
      else:
        dp[i+1][j+1][k] = max(dp[i+1][j+1][k], dp[i+1][j][k], dp[i][j+1][k], (k > 0)*(dp[i][j][k-1] + 1))
print(max(dp[ls][ls]))
Problem p03617 (python)

Fixed submission:
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())*4
l = [q,h/2,s/4,d/8]
v = [1,2,4,8]
cost = 0
while n:
  now = l.index(min(l))
  cost += n//v[now] * r[now]
  n %= v[now]
  v.pop(now)
  r.pop(now)
  l.pop(now)
print(cost)

Buggy submission (verdict: Runtime Error):
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())*4
l = [q,h/2,s/4,d/8]
v = [1,2,4,8]
cost = 0
while n:
  now = l2.index(min(l))
  cost += n//v[now] * r[now]
  n %= v[now]
  v.pop(now)
  r.pop(now)
  l.pop(now)
print(cost)

Buggy submission (verdict: Runtime Error):
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())
l = [q,h/2,s/4,d/8]
cost = 0
while n:
  now = l2.index(min(l))
  cost += n//r[now]
  n %= r[now]
  r.pop(now)
  l.pop(now)
print(cost)
Problem p03618 (python)

Fixed submission:
from collections import Counter
s = input()
n = len(s)
d = Counter(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(1 + n*(n-1)//2 - c)

Buggy submission (verdict: Runtime Error):
from collections import Count
s = input()
n = len(s)
d = Count(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(n*(n-1)//2 - c)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n+1)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a][b] = c
  road[b][a] = c
q,k = map(int, input().split())
dfs = [inf]*(n+1)
dfs[k] = 0
def dodfs(x):
  for i in road[x]:
    if dfs[i] == inf:
      dfs[i] = dfs[x] + road[x][i]
      dodfs(i)
  return   
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x] + dfs[y])

Buggy submission (verdict: Runtime Error):
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n+1)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a][b] = c
  road[b][a] = c
q,k = map(int, input().split())
dfs = [inf]*(n+1)
dfs[k] = 0
def dodfs(x):
  for i in road[x]:
    if dfs[i] == inf:
      dfs[i] = dfs[x] + road[x][i]
      dodfs(i)
  return   
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x] + dfs[y])

Buggy submission (verdict: Runtime Error):
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a-1][b-1] = c
  road[b-1][a-1] = c
q,k = map(int, input().split())
dfs = [inf]*n
dfs[k-1] = 0

def dodfs(x):
  for i in road[x-1]:
    if dfs[i] == inf:
      dfs[i] = dfs[x-1] + road[x-1][i]
      dodfs(i)
  return
      
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x-1] + dfs[y-1])
Problem p03723 (python)

Fixed submission:
a,b,c = map(int, input().split())
if a==b==c:
  if a%2:
    print(0)
  else:
    print(-1)
else:
  cnt = 0
  while a%2 == b%2 == c%2 == 0:
    a,b,c = (b+c)//2,(a+c)//2,(a+b)//2
    cnt += 1
  print(cnt)

Buggy submission (verdict: Runtime Error):
import math
n = list(map(int, input().split()))
d = max(m)-min(m)
if d:
  cnt = 0
  while d%2 == 0:
    d //= 2
    cnt += 1
  print(cnt)
elif n[0]%2:
  print(0)
else:
  print(-1)
Problem p03768 (python)

Fixed submission:
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
  n, m = nm()
  G = [list() for _ in range(n)]
  for _ in range(m):
    a, b = nm()
    a -= 1; b -= 1
    G[a].append(b)
    G[b].append(a)
  Q = int(input())
  queries = [tuple(nm()) for _ in range(Q)][::-1]
  dp = [[Q]*11 for _ in range(n)]
  for i in range(Q-1, -1, -1):
    v, d, _ = queries[i]
    dp[v-1][d] = i
    
  for d in range(10, 0, -1):
    for v in range(n):
      for x in G[v] + [v]:
        if dp[x][d-1] > dp[v][d]:
          dp[x][d-1] = dp[v][d]
          
  queries.append((-1, -1, 0))
  color = [queries[dp[v][0]][2] for v in range(n)]
  print(*color, sep='\n')
  return

solve()

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

n, m = map(int, input().split())
G = [list() for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  a -= 1; b -= 1
  G[a].append(b)
  G[b].append(a)
Q = int(input())
queries = [tuple(map(int, input().split())) for _ in range(Q)][::-1]
dp = [[Q]*n for _ in range(11)]
for i, (v, d, _) in enumerate(queries):
  dp[v-1][d] = i
for d in range(10, 0, -1):
  for v in range(n):
    if dp[v][d] < Q:
      dp[v][d-1] = min(dp[v][d-1], dp[v][d])
      for x in G[v]:
        dp[x][d-1] = min(dp[x][d-1], dp[v][d])
queries.append((-1, -1, 0))
color = [queries[dp[v][0]][2] for v in range(n)]
print(*color, sep='\n')

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

n, m = map(int, input().split())
G = [list() for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  a -= 1; b -= 1
  G[a].append(b)
  G[b].append(a)
Q = int(input())
queries = [tuple(map(int, input().split())) for _ in range(Q)][::-1]
dp = [[Q]*n for _ in range(n)]
for i, (v, d, _) in enumerate(queries):
  dp[v-1][d] = i
for d in range(10, 0, -1):
  for v in range(n):
    if dp[v][d] < Q:
      dp[v][d-1] = min(dp[v][d-1], dp[v][d])
      for x in G[v]:
        dp[x][d-1] = min(dp[x][d-1], dp[v][d])
queries.append((-1, -1, 0))
color = [queries[dp[v][0]][2] for v in range(n)]
print(*color, sep='\n')