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

Fixed submission:
def solve():
    S=list(input())
    for i in range(8):
        ans=int(S[0])
        for j in range(3):
            if (i & (1 << j)) != 0:
                ans+=int(S[j+1])
            else:
                ans-=int(S[j+1])
        if ans==7:
            ans=S[0]
            for j in range(3):
                if (i & (1 << j)) != 0:
                    ans+='+'
                else:
                    ans+='-'
                ans+=S[j+1]
            return ans+'=7'

print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    n = list(input())
    n = [ord(c) - ord('0') for c in n]
    sign = ['-', '+']

    for i in range(2):
        for j in range(2):
            for k in range(2):
                t = n[0]
                t += n[1] * (i * 2 - 1)
                t += n[2] * (j * 2 - 1)
                t += n[3] * (k * 2 - 1)
                if t == 7:
                    print(f'{n[0]}{sign[i]}{n[1]}{sign[j]}{n[2]}{sign[k]}{n[3]}=7')
                    return


if __name__ == "__main__":
    solve()
Problem p02563 (python)

Fixed submission:
mod = 998244353
primitive_root = 3
roots = [pow(primitive_root, (mod-1)>>i, mod) for i in range(24)]
inv_roots = [pow(root, mod-2, mod) for root in roots]

def ntt(A, n):
    for i in range(n):
        m = 1<<(n-i-1)
        for s in range(1<<i):
            w = 1
            s *= m*2
            for j in range(m):
                A[s+j], A[s+j+m] = (A[s+j]+A[s+j+m])%mod, (A[s+j]-A[s+j+m])*w%mod
                w *= roots[n-i]
                w %= mod

def intt(A, n):
    for i in range(n):
        m = 1<<i
        for s in range(1<<(n-i-1)):
            w = 1
            s *= m*2
            for j in range(m):
                A[s+j], A[s+j+m] = (A[s+j]+A[s+j+m]*w)%mod, (A[s+j]-A[s+j+m]*w)%mod
                w *= inv_roots[i+1]
                w %= mod
    inv = pow((mod+1)//2, n, mod)
    for i in range(1<<n):
        A[i] *= inv
        A[i] %= mod

def convolution(A, B):
    la = len(A)
    lb = len(B)
    deg = la + lb - 2
    n = deg.bit_length()
    N = 1<<n
    A += [0]*(N-la)
    B += [0]*(N-lb)
    ntt(A, n)
    ntt(B, n)
    A = [a*b%mod for a, b in zip(A, B)]
    intt(A, n)
    return A[:deg+1]


import sys
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = convolution(A, B)
print(*C)

Buggy submission (verdict: Runtime Error):
mod = 1012924417
primitive_root = 5
roots = [pow(primitive_root, (mod-1)>>i, mod) for i in range(22)]
inv_roots = [pow(root, mod-2, mod) for root in roots]

def ntt(A, n):
    for i in range(n):
        m = 1<<(n-i-1)
        for s in range(1<<i):
            w = 1
            s *= m*2
            for j in range(m):
                A[s+j], A[s+j+m] = (A[s+j]+A[s+j+m])%mod, (A[s+j]-A[s+j+m])*w%mod
                w *= roots[n-i]
                w %= mod

def intt(A, n):
    for i in range(n):
        m = 1<<i
        for s in range(1<<(n-i-1)):
            w = 1
            s *= m*2
            for j in range(m):
                A[s+j], A[s+j+m] = (A[s+j]+A[s+j+m]*w)%mod, (A[s+j]-A[s+j+m]*w)%mod
                w *= inv_roots[i+1]
                w %= mod
    inv = pow((mod+1)//2, n, mod)
    for i in range(1<<n):
        A[i] *= inv
        A[i] %= mod

def convolution(A, B):
    la = len(A)
    lb = len(B)
    deg = la + lb - 2
    n = deg.bit_length()
    N = 1<<n
    A += [0]*(N-la)
    B += [0]*(N-lb)
    ntt(A, n)
    ntt(B, n)
    A = [a*b%mod for a, b in zip(A, B)]
    intt(A, n)
    return A[:deg+1]


import sys
input = sys.stdin.readline
n = int(input())
A, B = [0], [0]
for _ in range(n):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
C = convolution(A, B)
print(*C[1:], sep="\n")
Problem p02599 (python)

Fixed submission:
n, q = map(int, input().split())
C = [0] + list(map(int, input().split()))
D = [-1]*(n+1)
A = [0]*q
U = 10**6
LR = tuple(tuple(map(int, input().split())) for _ in range(q))
W = sorted(r*U+i for i, (l, r) in enumerate(LR))
B = [0]*(1<<n.bit_length())
def add(i, a):
  while i <= n:
    B[i] += a
    i += i & -i
def acc(i):
  res = 0
  while i:
    res += B[i]
    i -= i & -i
  return res
temp = 1
for w in W:
  r, i = divmod(w, U)
  while temp <= r:
    c = C[temp]
    add(temp, 1)
    if D[c] != -1:
      add(D[c], -1)
    D[c] = temp
    temp += 1
  l = LR[i][0]
  A[i] = acc(r) - acc(l-1)
print(*A, sep="\n")

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

n, q = map(int, input().split())
C = [0] + list(map(int, input().split()))
D = [-1]*(n+1)
A = [0]*q
U = 10**6
RLI = []
for i in range(n):
  l, r = map(int, input().split())
  RLI.append(r*U*U + l*U + i)
RLI.sort()
B = [0]*(n+1)
def add(i, a):
  while i <= n:
    B[i] += a
    i += i & -i
def acc(i):
  res = 0
  while i:
    res += B[i]
    i -= i & -i
  return res
temp = 1
for rli in RLI:
  rl, i = divmod(rli, U)
  r, l = divmod(rl, U)
  while temp <= r:
    c = C[temp]
    add(temp, 1)
    if D[c] != -1:
      add(D[c], -1)
    D[c] = temp
    temp += 1
  A[i] = acc(r) - acc(l-1)
print(*A, sep="\n")
Problem p02609 (python)

Fixed submission:
def popcount(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

n = int(input())
x = input()
mod = x.count("1")
U = 2**20
C = [0]*U
for i in range(1, U):
  q = popcount(i)
  C[i] = C[i%q] + 1
t_1 = 0
t_2 = 0
for j, s in enumerate(x):
  if s == "1":
    if mod > 1:
      t_1 += pow(2, n-1-j, mod-1)
      t_1 %= mod-1
    t_2 += pow(2, n-1-j, mod+1)
    t_2 %= mod+1
for i in range(n):
  if x[i] == "1":
    if mod == 1:
      print(0)
      continue
    temp = t_1
    temp -= pow(2, n-1-i, mod-1)
    temp %= mod-1
  else:
    temp = t_2
    temp += pow(2, n-1-i, mod+1)
    temp %= mod+1
  res = C[temp] + 1
  print(res)

Buggy submission (verdict: Runtime Error):
def popcount(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

n = int(input())
x = input()
mod = x.count("1")
U = 2**20
C = [0]*U
for i in range(1, U):
  q = popcount(i)
  C[i] = C[i%q] + 1
t_1 = 0
t_2 = 0
for j, s in enumerate(x):
  if s == "1":
    t_1 += pow(2, n-1-j, mod-1)
    t_1 %= mod-1
    t_2 += pow(2, n-1-j, mod+1)
    t_2 %= mod+1
for i in range(n):
  if x[i] == "1":
    temp = t_1
    temp -= pow(2, n-1-i, mod-1)
    temp %= mod-1
  else:
    temp = t_2
    temp += pow(2, n-1-i, mod+1)
    temp %= mod+1
  res = C[temp] + 1
  print(res)
Problem p02618 (python)

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

d = int(input())
C = tuple(map(int, input().split()))
S = tuple(tuple(map(int, input().split())) for _ in range(d))
ans = 0
R = [0]*26
for i in range(1, d+1):
  M = -float("inf")
  idx = -1
  for t in range(26):
    L = list(R)
    L[t] = i
    temp = S[i-1][t]
    for j, (c, l) in enumerate(zip(C, L)):
      temp -= c*(i-l)
    if M < temp:
      M = temp
      idx = t
  R[idx] = i
  print(idx+1)

Buggy submission (verdict: Runtime Error):
for i in"_"*365:print(i%26+1)
Problem p02621 (python)

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

Buggy submission (verdict: Runtime Error):
?ddd1+**+p
Problem p02644 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

def main():
  h, w, k = map(int, input().split())
  x1, y1, x2, y2 = map(lambda x:int(x)-1, input().split())
  v1 = x1*(w+1)+y1
  v2 = x2*(w+1)+y2
  C = "".join(input().rstrip()+"@" for _ in range(h))
  dist = [-1 if c=="@" else 10**10 for c in C]
  ans = 0
  que = deque()
  que.append(v1)
  dist[v1] = 0
  while que:
    v = que.popleft()
    if v == v2:
      print(dist[v2])
      exit()
    d = dist[v]+1
    for dr in (-(w+1), -1, w+1, 1):
      for i in range(1, k+1):
        nv = v+dr*i
        if 0 <= nv < h*(w+1):
          if dist[nv] > d:
            dist[nv] = d
            que.append(nv)
          elif dist[nv] == d:
            continue
          else:
            break
        else:
          break
  print(-1)
if __name__ == "__main__":
  main()

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

def main():
  h, w, k = map(int, input().split())
  x1, y1, x2, y2 = map(lambda x:int(x)-1, input().split())
  v1 = x1*(w+1)+y1
  v2 = x2*(w+1)+y2
  C = "".join(input().rstrip()+"@" for _ in range(h))
  dist = tuple(-1 if c=="@" else 10**10 for c in C)
  ans = 0
  que = deque()
  que.append(v1)
  dist[v1] = 0
  while que:
    v = que.popleft()
    if v == v2:
      print(dist[v2])
      exit()
    d = dist[v]+1
    for dr in (-(w+1), -1, w+1, 1):
      for i in range(1, k+1):
        nv = v+dr*i
        if 0 <= nv < h*(w+1):
          if dist[nv] > d:
            dist[nv] = d
            que.append(nv)
          elif dist[nv] == d:
            continue
          else:
            break
        else:
          break
  print(-1)
if __name__ == "__main__":
  main()
Problem p02692 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n, a, b, c = map(int, input().split())
S = [input().rstrip().replace("AC", "CA") for _ in range(n)]
D = ["AB", "BC", "CA"]
X = [a+b, b+c, c+a]
L = []
for i, s in enumerate(S):
  k = D.index(s)
  if X[k] == 0:
    print("No")
    exit()
  if X[(k+1)%3] == 1 and X[(k+2)%3] == 1 and i < n-1:
    l = D.index(S[i+1])
    if l == (k+1)%3:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
  else:
    if X[(k+1)%3] < X[(k+2)%3]:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
print("Yes")
print(*L, sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, a, b, c = map(int, input().split())
S = [input().rstrip() for _ in range(n)]
D = ["AB", "BC", "CA"]
X = [a+b, b+c, c+a]
L = []
for i, s in enumerate(S):
  if s == "AC":
    s = "CA"
  k = D.index(s)
  if X[k] == 0:
    print("No")
    exit()
  if X[(k+1)%3] == 1 and X[(k+2)%3] == 1 and i < n-1:
    l = D.index(S[i+1])
    if l == (k+1)%3:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
  else:
    if X[(k+1)%3] < X[(k+2)%3]:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
print("Yes")
print(*L, sep="\n")
Problem p02758 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import bisect
MOD = 998244353
n = int(input())
XD = sorted([list(map(int, input().split())) for _ in range(n)])
X, D = zip(*XD)


C = list(range(n))

class RmaxQ:
    def __init__(self, original):
        self.n = len(original)
        self.INF = -float("inf")
        self.N0 = 1 << (self.n-1).bit_length()
        self.seg = [self.INF]*(self.N0 << 1)
        for i, j in enumerate(original, self.N0):
            self.seg[i] = j
        for i in range(self.N0-1, 0, -1):
            self.seg[i] = max(self.seg[2*i], self.seg[2*i+1])

    def get(self, i):
        return self.seg[i+self.N0]
        
    def update(self, i, x):
        i += self.N0
        self.seg[i] = x
        while i > 1:
            i >>= 1
            self.seg[i] = max(self.seg[2*i], self.seg[2*i+1])
                
    def query(self, l, r):
        res = self.INF
        l += self.N0
        r += self.N0
        while l < r:
            if r & 1:
                res = max(res, self.seg[r-1])
            if l & 1:
                res = max(res, self.seg[l])
                l += 1
            l >>= 1
            r >>= 1
     
        return res
    
seg = RmaxQ(C)
for i in range(n):
  x, d = XD[n-1-i]
  t = bisect.bisect_left(X, x+d)
  seg.update(n-1-i, max(t, seg.query(n-1-i, t)))

dp = [0]*(n+1)
l = [0]*n
l[-1] = n
dp[-1] = 1
for i in range(n):
  x, d = XD[n-1-i]
  m = bisect.bisect_left(X, x+d)
  t = seg.query(n-1-i, m)
  dp[n-1-i] = dp[n-i] + dp[t]
  dp[n-1-i] %= MOD
print(dp[0])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
MOD = 998244353
n = int(input())
XD = sorted([list(map(int, input().split())) for _ in range(n)])
X, D = zip(*XD)


C = list(range(n))

class RmaxQ:
    def __init__(self, original):
        self.n = len(original)
        self.INF = -float("inf")
        self.N0 = 1 << (self.n-1).bit_length()
        self.seg = [self.INF]*(self.N0 << 1)
        for i, j in enumerate(original, self.N0):
            self.seg[i] = j
        for i in range(self.N0-1, 0, -1):
            self.seg[i] = max(self.seg[2*i], self.seg[2*i+1])

    def get(self, i):
        return self.seg[i+self.N0]
        
    def update(self, i, x):
        i += self.N0
        self.seg[i] = x
        while i > 1:
            i >>= 1
            self.seg[i] = max(self.seg[2*i], self.seg[2*i+1])
                
    def query(self, l, r):
        res = self.INF
        l += self.N0
        r += self.N0
        while l < r:
            if r & 1:
                res = max(res, self.seg[r-1])
            if l & 1:
                res = max(res, self.seg[l])
                l += 1
            l >>= 1
            r >>= 1
     
        return res
    
seg = RmaxQ(C)
for i in range(n):
  x, d = XD[n-1-i]
  t = bisect.bisect_left(X, x+d
  seg.update(n-1-i, max(t, seg.query(n-1-i, t)))

dp = [0]*(n+1)
l = [0]*n
l[-1] = n
dp[-1] = 1
for i in range(n):
  x, d = XD[n-1-i]
  m = bisect.bisect_left(X, x+d)
  t = seg.query(n-1-i, m)
  dp[n-1-i] = dp[n-i] + dp[t]
  dp[n-1-i] %= MOD
print(dp[0])
Problem p02788 (python)

Fixed submission:
import bisect
n, d, a = map(int, input().split())
XH = sorted([list(map(int, input().split())) for _ in range(n)])
X, H = zip(*XH)
K = [-(-i//a) for i in H]
L = [0]*(n+2)
ans = 0
for i in range(n):
  L[i+1] += L[i]
  s = max(K[i]-L[i+1], 0)
  ans += s
  L[i+1] += s
  L[bisect.bisect_right(X, X[i]+2*d)+1] -= s
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
import numpy as np
n, d, a = map(int, input().split())
XH = sorted([list(map(int, input().split())) for _ in range(n)])
X, H = zip(*XH)
K = np.array([-(-i//a) for i in H])
ans = 0
for now in range(n):
  l = K[now]
  if l > 0:
    ans += l
      K[now:bisect.bisect_right(X, X[now]+2*d)] -= l
print(ans)
Problem p02808 (python)

Fixed submission:
import sys
input = sys.stdin.readline
U = 1000
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z

n, k = map(int, input().split())
A = list(map(int, input().split()))
F = [[0]*(n+1) for _ in range(k+1)]
F[0][0] = 1
for i in range(k):
  for j in range(n+1):
    for m in range(j+1):
      F[i+1][j] += comb(j, m) * F[i][m] * comb(n-(j-m), A[i]-(j-m))
    F[i+1][j] %= MOD
ans = F[k][n]
print(ans)

Buggy submission (verdict: Runtime Error):
M=10**9+7;n,k,*A=map(int,open(0).read().split());C=[[0]*(n+1)for _ in"_"*(n+1)]
for i in range(n+1):
 for j in range(n):C[i][j]=(1,C[i-1][j-1]+C[i-1][j])[j>0]%M
F=[[0]*(n+1)for _ in"_"*n];F[0][0]=1
for i in range(k):
 for j in range(n+1):
  for m in range(j+1):F[i+1][j]+=C[j][m]*F[i][m]*C[n-j+m][A[i]-j+m]
print(F[k][n]%M)
Problem p02837 (python)

Fixed submission:
n = int(input())
A = [0]*n
for i in range(n):
  a = int(input())
  A[i] = [ tuple(map(int, input().split())) for _ in range(a) ]
ans = 0
for i in range(2**n):
  P = [2]*n
  f = False
  for j in range(n):
    if i >> j & 1:
      if P[j] != 2 and P[j] ^ 1:
          f = True
          break
      P[j] = 1
      for x, y in A[j]:
        if P[x-1] != 2 and P[x-1] ^ y:
          f = True
          break
        P[x-1] = y
  if f:
    continue
  c = bin(i).count("1")
  if P.count(1) <= c:
    ans = max(ans, c)
print(ans)

Buggy submission (verdict: Runtime Error):
2
1
2 0
1
1 0
Problem p02867 (python)

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

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(zip(B, A))
B, A = zip(*C)
D = sorted((a, i) for i, a in enumerate(A))
E, indices = zip(*D)
for e, b in zip(E, B):
  if e > b:
    print("No")
    exit()
S = {0}
now = 0
for _ in range(n-1):
  if indices[now] in S:
    print("Yes")
    exit()
  now = indices[now]
  S.add(now)
for i in range(n-1):
  if E[i+1] <= B[i]:
    print("Yes")
    exit()
print("No")

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

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(zip(B, A))
B, A = zip(*C)
D = sorted((a, i) for i, a in enumerate(A))
E, indices = zip(*D)
for e, b in zip(E, B):
  if e > b:
    print("No")
    exit()
S = {0}
now = 0
for _ in range(n-1):
  if indices[now] in S:
    print("Yes")
    exit()
  now = indices[now]
  S.add(now)
for i in range(n):
  if E[i+1] <= B[i]:
    print("Yes")
    exit()
print("No")
Problem p02928 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
t, s = 0, 0

for i in range(n-1):
  for j in range(i+1, n):
    if a[i] > a[j]:
      t += 1
      
a.sort()
l = [ i for i in range(n) ]
for i in range(1, n):
  if a[i] == a[i-1]:
    l[i] = l[i-1]
s = sum(l)
    
print((k*t%1000000007 + s*k*(k-1)//2%1000000007)%1000000007)

Buggy submission (verdict: Runtime Error):
def Kleene(a, k):
  if k==1:
    count = 0
    for i in range(len(a)-1):
      for j in range(i+1, len(a)):
        if a[i] > a[j]:
          count += 1
    return count
  
  else:
    a.sort()
    l = [ i for i in range(len(a)) ]
    for i in range(1, len(a)):
      if a[i] == a[i-1]:
        l[i] = l[i-1]
    count = sum(l) * (k-1)
    return ( Kleene(a, 1) + Kleene(a, k-1) + count ) % 1000000007

n, k = map(int, input().split())
a = list(map(int, input().split()))
print(Kleene(a, k))
Problem p02934 (python)

Fixed submission:
c=0
a=input()
for i in input().split():
  c+=1/int(i)
print(1/c)

Buggy submission (verdict: Runtime Error):
c=0;a=input();for i in input().split():
  c+=1/int(i)
print(1/c)
Problem p02936 (python)

Fixed submission:
n, q = map(int, input().split())
C = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  C[a-1].append(b-1)
  C[b-1].append(a-1)
dist = [-1]*n
dist[0] = 1
A = [0]*n
F = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  F[p-1] += x
S = [0]
T = [0]
while S:
  v = S.pop()
  for nv in C[v]:
    if dist[nv] == -1:
      dist[nv] = dist[v] + 1
      S.append(nv)
while T:
  v = T.pop()
  A[v] += F[v]
  for nv in C[v]:
    if dist[nv] > dist[v]:
      A[nv] += A[v]
      T.append(nv)
print(*A)

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

n, q = map(int, input().split())
C = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  C[a-1].append(b-1)
  C[b-1].append(a-1)
dist = [-1]*n
dist[0] = 1
A = [0]*n
F = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  F[p-1] += x
dq = deque()
dq.append(0)
while dq:
  v = dq.popleft()
  for nv in C[v]:
    if dist[nv] == -1:
      dist[nv] = dist[v] + 1
      dq.append(nv)
def dfs(v):
  A[v] += F[v]
  for nv in C[v]:
    if dist[nv] > dist[v]:
      A[nv] += A[v]
      dfs(nv)
dfs(0)
print(*A)
Problem p02960 (python)

Fixed submission:
s = input()
n = len(s)
mod = 10**9+7
dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1
d = {(j, k):(10*j+k)%13 for k in range(10) for j in range(13)}
for i in range(n):
  if s[i] != "?":
    t = int(s[i])
    for j in range(13):
      dp[i+1][d[(j, t)]] += dp[i][j]
      dp[i+1][d[(j, t)]] %= mod
  else:
    for k in range(10):
      for j in range(13):
        dp[i+1][d[(j, k)]] += dp[i][j]
        dp[i+1][d[(j, k)]] %= mod
print(dp[n][5]%mod)

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

def main():
  s = input()
  n = len(s)
  mod = 10**9+7
  dp = [[0]*13 for _ in range(n+1)]
  dp[0][0] = 1
  d = {(j, k):(10*j+k)%13 for k in range(10) for j in range(13)}
  for i in range(n):
    if s[i] != "?":
      t = int(s[i])
      for j in range(13):
        dp[i+1][d[(j, t)]] += dp[i][j]
        dp[i+1][d[(j, t)]] %= mod
    else:
      for k in range(10):
        for j in range(13):
          dp[i+1][d[(j, k)]] += dp[i][j]
          dp[i+1][d[(j, k)]] %= mod
  print(dp[n][5]%mod)
if __name__ == '__main__':
  main()

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

def main():
  s = input()
  n = len(s)
  mod = 10**9+7
  dp = [[0]*13 for _ in range(n+1)]
  dp[0][0] = 1
  d = {(j, k):(10*j+k)%13 for k in range(10) for j in range(13)}
  for i in range(n):
    if s[i] != "?":
      t = int(s[i])
      for j in range(13):
        dp[i+1][d[(j, t)]] += dp[i][j]
        dp[i+1][d[(j, t)]] %= mod
    else:
      for k in range(10):
        for j in range(13):
          dp[i+1][d[(j, k)]] += dp[i][j]
          dp[i+1][d[(j, k)]] %= mod
  print(dp[n][5]%mod)

if __name__ == '__main__':
  main()

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

def main():
  s = input()
  n = len(s)
  mod = 10**9+7
  dp = [[0]*13 for _ in range(n+1)]
  dp[0][0] = 1
  d = {(j, k):(10*j+k)%13 for k in range(10) for j in range(13)}
  for i in range(n):
    if s[i] != "?":
      t = int(s[i])
      for j in range(13):
        dp[i+1][d[(j, t)]] += dp[i][j]
        dp[i+1][d[(j, t)]] %= mod
    else:
      for k in range(10):
        for j in range(13):
          dp[i+1][d[(j, k)]] += dp[i][j]
          dp[i+1][d[(j, k)]] %= mod
  print(dp[n][5]%mod)

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

Fixed submission:
a,b,c=map(int,input().split());print(min(a*b,c))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split()),print(min(a*b,c))
Problem p02991 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
F = [set() for _ in range(3*n)]
for _ in range(m):
  u, v = map(int, input().split())
  u = (u-1)*3
  v = (v-1)*3
  F[u].add(v+1)
  F[u+1].add(v+2)
  F[u+2].add(v)
s, t = map(int, input().split())
s = (s-1)*3
t = (t-1)*3
dist = [-1]*(3*n)
dist[s] = 0
dq = deque([s])
while dq:
  v = dq.popleft()
  for nv in F[v]:
    if dist[nv] != -1:
      continue
    dist[nv] = dist[v]+1
    dq.append(nv)
    if nv == t:
      break
  else:
    continue
  break
print(dist[t]//3)

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
F = [set() for _ in range(n)]
G = np.zeros((n, n))
for _ in range(m):
  u, v = map(int, input().split())
  u -= 1
  v -= 1
  F[u].add(v)
for i in range(n):
  for j in F[i]:
    for k in F[j]:
      for l in F[k]:
        G[i][l] = 1
csr = csr_matrix(G)
s, t = map(int, input().split())
s -= 1
t -= 1
A = dijkstra(csr, indices=s)
if A[t] == float("inf"):
  print(-1)
else:
  print(int(A[t]))