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

Fixed submission:
N, A, B, C = map(int, input().split())
S = [list(input()) for i in range(N)]

v = [A, B, C]
id_d = {'A':0, 'B':1, 'C':2}
ans = [0] * N
for i, s in enumerate(S):
  s1, s2 = s
  id1, id2 = id_d[s1], id_d[s2]
  v1, v2 = v[id1], v[id2]
  if v1 == v2 == 0:
    if i == 0:
      print('No')
      quit()
    else:
      pre_s1, pre_s2 = S[i-1]
      pre_id1, pre_id2 = id_d[pre_s1], id_d[pre_s2]
      if pre_s1 in [s1, s2]:
        v[pre_id1] += 2
        v[pre_id2] -= 2
        ans[i-1] = pre_s1
        if v[pre_id2] < 0:
          print('No')
          quit()
      else: # pre_s2 in [s1, s2]
        v[pre_id2] += 2
        v[pre_id1] -= 2
        ans[i-1] = pre_s2
        if v[pre_id1] < 0:
          print('No')
          quit()
  v1, v2 = v[id1], v[id2]
  if v1 >= v2:
    ans[i] = s2
    v[id1] -= 1
    v[id2] += 1
  else:
    ans[i] = s1
    v[id1] += 1
    v[id2] -= 1

print('Yes')
print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
S = [list(input()) for i in range(N)]

v = [A, B, C]
id_d = {'A':0, 'B':1, 'C':2}
ans = [0] * N
for i, s in enumerate(S):
  s1, s2 = s
  id1, id2 = id_d[s1], id_d[s2]
  v1, v2 = v[id1], v[id2]
  if v1 == v2 == 0:
    if i == 0:
      print('No')
      quit()
    else:
      pre_s1, pre_s2 = S[i-1]
      pre_id1, pre_id2 = id_d[pre_s1], id_d[pre_s2]
      if pre_s1 in [s1, s2]:
        v[pre_id1] += 2
        v[pre_id2] -= 2
        ans[i-1] = pre_s1
        if v[pre_id2] < 0:
          print('No')
          quit()
      else: # pre_s2 in [s1, s2]
        v[pre_id2] += 2
        v[pre_id1] -= 2
        ans[i-1] = pre_s2
        if v[pre_id1] < 0:
          print('No')
          quit()
  v1, v2 = v[id1], v[1d2]
  if v1 >= v2:
    ans[i] = s2
    v[id1] -= 1
    v[id2] += 1
  else:
    ans[i] = s1
    v[id1] += 1
    v[id2] -= 1

print('Yes')
print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
v = [A, B, C]
id_d = {'A':0, 'B':1, 'C':2}
ans = [0] * N
temp = []
temp_idx = {('A', 'B'):[], ('A', 'C'):[], ('B', 'C'):[]}
for i in range(N):
  s1, s2 = list(input())
  id1, id2 = id_d[s1], id_d[s2]
  v1, v2 = v[id1], v[id2]
  if v1 == v2 == 0:
    if sorted([s1, s2]) == ['A', 'B']:
      s3 = 'C'
    if sorted([s1, s2]) == ['A', 'C']:
      s3 = 'B'
    else:
      s3 = 'A'
    if temp_idx[tuple(sorted((s1, s3)))]:
      idx = temp_idx[tuple(sorted((s1, s3)))].pop()
      _i, _s1, _s2 = temp[idx]
      ans[_i] = s1
      v[id1] = 1
      v[id2] = 1
    elif temp_idx[tuple(sorted((s2, s3)))]:
      idx = temp_idx[tuple(sorted((s2, s3)))].pop()
      _i, _s1, _s2 = temp[idx]
      ans[_i] = s2
      v[id1] = 1
      v[id2] = 1
    else:
      print('No')
      quit()
  else:
    if v1 > v2:
      ans[i] = s2
      v[id_d[s1]] -= 1
      v[id_d[s2]] += 1
    elif v1 < v2:
      ans[i] = s1
      v[id_d[s2]] -= 1
      v[id_d[s1]] += 1
    else: # v1 == v2
      v[id_d[s1]] -= 1
      v[id_d[s2]] -= 1
      temp.append([i, s1, s2])
      temp_idx[tuple(sorted((s1, s2)))].append(i)

for i, s1, s2 in temp:
  if ans[i] == 0:
    ans[i] = s1

print('Yes')
print(*ans, sep='\n')
Problem p02698 (python)

Fixed submission:
import bisect
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int, input().split()))

tree = [[] for i in range(N)]
for i in range(N-1):
  u, v = map(int, input().split())
  tree[u-1].append(v-1); tree[v-1].append(u-1)


ans = [0] * N
ans[0] = 1
INF = 10**10
dp = [INF] * N
dp[0] = A[0]
stack = []
def dfs(node, par):
  global ans
  global dp
  global stack
  children = tree[node]
  for child in children:
    if child == par:
      continue
    num = A[child]
    idx = bisect.bisect_left(dp, num)
    stack.append([idx, dp[idx]])
    dp[idx] = num
    ans[child] = bisect.bisect_left(dp, INF)
    dfs(child, node)
    # 巻き戻し
    idx, num = stack.pop()
    dp[idx] = num

dfs(0, -1)
print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())
A = list(map(int, input().split()))

tree = [[] for i in range(N)]
for i in range(N-1):
  u, v = map(int, input().split())
  tree[u-1].append(v-1)
  tree[v-1].append(u-1)


ans = [0] * N
ans[0] = 1
dp = []
def dfs(node, par, dp):
  global ans
  children = tree[node]
  for child in children:
    if child == par:
      continue
    num = A[child]
    idx = bisect.bisect_left(dp, num)
    if idx == len(dp):
      _dp = dp.copy() + [num]
      ans[child] = idx + 1
      dfs(child, node, _dp)
    else:
      _dp = dp.copy()
      _dp[idx] = num
      ans[child] = idx + 1
      dfs(child, node, _dp)

dp = [A[0]]
dfs(0, -1, dp)
print(*ans, sep='\n')
Problem p02720 (python)

Fixed submission:
cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def add_v(v):
  global cands
  global K
  v = str(v)
  v0 = int(v[-1])
  if v0 == 0:
    cands += [int(v+'0'), int(v+'1')]
    K -=2
  elif v0 == 9:
    cands += [int(v+'8'), int(v+'9')]
    K -= 2
  else:
    cands += [int(v+str(v0-1)), int(v+str(v0)), int(v+str(v0+1))]
    K -= 3

K = int(input())
idk = K
K -= 9
idx = 0
while K >= 0:
  add_v(cands[idx])
  idx += 1

print(cands[idk-1])

Buggy submission (verdict: Runtime Error):
cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def add_v(v):
  global cands
  global K
  v0 = v % 10
  v0 = int(v[-1])
  if v0 == 0:
    cands += [v*10, v*10+1]
    K -=2
  elif v0 == 9:
    cands += [v*10+8, v*10+9]
    K -= 2
  else:
    cands += [v*10+v0-1, v*10+v0, v*10+v0+1]
    K -= 3

K = int(input())
idk = K
K -= 9
idx = 0
while K >= 0:
  add_v(cands[idx])
  idx += 1

print(cands[idk-1])
Problem p02722 (python)

Fixed submission:
N = int(input())

def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return (_N-1)%p == 0

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N-1])
for i in range(2, n+1):
  if (N-1)%i == 0:
    P1.add(i)
    P1.add((N-1)//i)
  if N%i == 0:
    P0.add(i)
    P0.add(N//i)

P0.discard(1)
P1.discard(1)
ans = len(P1)
for p in P0:
  ans += check(p)

print(ans)

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

def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return (_N-1)%p == 0

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N-1])
for i in range(2, n+1):
  if (N-1)%i == 0:
    P1.add(i)
    P1.add((N-1)//i)
  if N%i == 0:
    P0.add(i)
    P0.add(N//i)

P2.discard(1)
P1.discard(1)
ans = len(P1)
for p in P0:
  ans += check(p)

print(ans)
Problem p02782 (python)

Fixed submission:
r1, c1, r2, c2 = map(int, input().split())

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**6+2):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def memo_comb(n, r, mod=MOD):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

def g(r, c):
  res = 0
  for i in range(r+1):
    res += memo_comb(i+c+1, i+1)
    res %= MOD
  
  return res

ans = g(r2, c2) - g(r2, c1-1) - g(r1-1, c2) + g(r1-1, c1-1)
ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
r1, c1, r2, c2 = map(int, input().split())

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**6+1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def memo_comb(n, r, mod=MOD):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

def g(r, c):
  res = 0
  for i in range(r+1):
    res += memo_comb(i+c+1, i+1)
    res %= MOD
  
  return res

ans = g(r2, c2) - g(r2, c1-1) - g(r1-1, c2) + g(r1-1, c1-1)
ans %= MOD
print(ans)
Problem p02796 (python)

Fixed submission:
N = int(input())

RL = []
for i in range(N):
  x, l = map(int, input().split())
  RL.append([x+l, x-l])

RL.sort()
right = -10**9

ans = 0
for r, l in RL:
  if l >= right:
    right = r
    ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())

LR = []
for i in range(N):
  X, L = map(int, input().split())
  LR.append([X-L, 1, i])
  LR.append([X+L, 0, i])

LR.sort()

tree = np.eye(N, dtype=bool)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())

LR = []
for i in range(N):
  X, L = map(int, input().split())
  LR.append([X-L, 1, i])
  LR.append([X+L, 0, i])

LR.sort()

tree = np.eye(N, dtype=bool)

is_now = np.zeros(N, dtype=bool)
for y, lr, idx in LR:
  if lr == 1:
    is_now[idx] = True
    tree[idx] += is_now
  else:
    is_now[idx] = False

tree += tree.T

a = np.sum(tree)
B = np.argsort(tree.sum(axis=0))[::-1]

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())

LR = []
for i in range(N):
  X, L = map(int, input().split())
  LR.append([X-L, 1, i])
  LR.append([X+L, 0, i])

LR.sort()

tree = np.eye(N, dtype=bool)

is_now = np.zeros(N, dtype=bool)
for y, lr, idx in LR:
  if lr == 1:
    is_now[idx] = True
    tree[idx] += is_now
  else:
    is_now[idx] = False

tree += tree.T

a = np.sum(tree)
B = np.argsort(tree.sum(axis=0))[::-1]

for i, b in enumerate(B):
  if a == N:
    break
  tree[b] = tree[:, b] = False
  tree[b, b] = True
  a = np.sum(tree)

print(N - i)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())

LR = []
for i in range(N):
  X, L = map(int, input().split())
  LR.append([X-L, 1, i])
  LR.append([X+L, 0, i])

LR.sort()

tree = np.zeros([N, N], dtype=bool)

is_now = np.zeros(N, dtype=bool)
for y, lr, idx in LR:
  if lr == 1:
    is_now[idx] = True
    tree[idx] += is_now
  else:
    is_now[idx] = False
    tree[idx] += is_now


tree += tree.T

a = np.sum(tree, axis=0)
while (a != 1).any():
  idx = a.argmax()
  tree = np.delete(np.delete(tree, idx, 0), 1)
  a = np.sum(tree, axis=0)

print(len(tree))
Problem p02807 (python)

Fixed submission:
MOD = 10**9 + 7
N = int(input())
X = list(map(int, input().split()))
D = [dj - di for di, dj in zip(X, X[1:])]

def power(n, r, mod=10**9+7):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def framod(n, a=1, mod=10**9+7):
    for i in range(1,n+1):
        a = a * i % mod
    return a

count_d = []
frac_Nm1 = framod(N-1)
for i in range(1, N):
  count_d.append(frac_Nm1 * power(i, MOD-2) % MOD)

for i in range(1, N-1):
  count_d[i] += count_d[i-1]


ans = sum([d*c % MOD for d, c in zip(D, count_d)]) % MOD
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
d = [dj - di for di, dj in zip(X, X[1:])][::-1]

MOD = 10**9 + 7
count_d = [[0] * (N) for i in range(N-1)]
count_d[0][1] = 1

fac = 1
for n in range(1, N-1):
  fac = fac*n % MOD
  for i in range(1, n+2):
    count_d[n][i] = ((n+1-i+1)*count_d[n-1][i] + (i-1)*count_d[n-1][i-1] + fac)%MOD

ans = 0
for di, ci in zip(d, count_d[-1][1:]):
  ans += di*ci % MOD
  ans %= MOD

print(ans)
Problem p02822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
MOD = 10**9 + 7
tree = [[] for i in range(N+1)]
for i in range(N-1):
  a, b = map(int, input().split())
  tree[a].append(b)
  tree[b].append(a)

# 頂点1をルートにして各頂点より下にある部分木の頂点数を求めていく
root, par = 1, 0
sizes = [0] * (N+1)
order = [[root, par]]
def calc_nums(node, par):
  global sizes
  global order
  if sizes[node] > 0:
    return sizes[node]
  children = tree[node]
  res = 1
  for child in children:
    if child == par:
      continue
    order.append([child, node])
    res += calc_nums(child, node)
  sizes[node] = res
  return res

_ = calc_nums(root, par)

# 2の累乗を事前に計算しておく
prod2 = [1]
for i in range(N):
  prod2.append(prod2[-1] * 2 % MOD)

# 各頂点について、その頂点が穴あき度としてカウントされる状況を独立に計算する
demo = 0 # 分子
div = prod2[N] # 分母
base = prod2[N-1] - 1
for node, par in order:
  children = tree[node]
  num = base
  num_par = N - 1
  for child in children:
    if child == par:
      continue
    s = sizes[child]
    num_par -= s
    num -= prod2[s] - 1 
  num -= prod2[num_par] - 1
  demo += num
    
ans = demo * pow(div, MOD-2, MOD) % MOD
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
MOD = 10**9 + 7
tree = [[] for i in range(N+1)]
for i in range(N-1):
  a, b = map(int, input().split())
  tree[a].append(b)
  tree[b].append(a)

# 頂点1をルートにして各頂点より下にある部分木の頂点数を求めていく
root, par = 1, 0
sizes = [0] * (N+1)
order = [[root, par]]
def calc_nums(node, par):
  global sizes
  global order
  if sizes[node] > 0:
    return sizes[node]
  children = tree[node]
  res = 1
  for child in children:
    if child == par:
      continue
    order.append([child, node])
    res += calc_nums(child, node)
  sizes[node] = res
  return res

calc_nums(root, par)

# 2の累乗を事前に計算しておく
prod2 = [1]
for i in range(N):
  prod2.append(prod2[-1] * 2 % MOD)

# 各頂点について、その頂点が穴あき度としてカウントされる状況を独立に計算する
demo = 0 # 分子
div = prod2[N] # 分母
base = prod2[N-1] - 1
for node, par in order:
  children = tree[node]
  num = base
  num_par = N - 1
  for child in children:
    if child == par:
      continue
    s = sizes[child]
    num_par -= s
    num -= prod2[s] - 1 
  num -= prod2[num_par] - 1
  demo += num
    
ans = demo * pow(div, MOD-2, MOD) % MOD
print(ans)
Problem p02824 (python)

Fixed submission:
import bisect

N, M, V, P = map(int, input().split())
A = list(map(int, input().split())) + [-M-1]
A.sort()

Ap = A[-P] # 初期状態でP番目に大きい点数
I = N + 2 - P
right = N + 1 - P
left = 0

while left + 1 < right:
  mid = (left + right) // 2
  b = A[mid] + M
  if b < Ap:
    left = mid
  else:
    v = V - (bisect.bisect_right(A, A[mid])-1) - (P-1)
    if v <= 0:
      right = mid
    else:
      mv = M*v
      for i in range(mid+1, I):
        if A[i] == A[mid]:
          continue
        mv -= b - A[i]
        if mv <= 0:
          break
      if mv <= 0:
        right = mid
      else:
        left = mid

print(N + 1 - right)

Buggy submission (verdict: Runtime Error):
import bisect

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

Ap = A[-P] # 初期状態でP番目に大きい点数
idx = bisect.bisect_left(A, Ap) # 初期状態で得点がApより小さい問題の数
ans = N - idx # 初期状態で得点がAp以上であれば候補に入る


for i, a in enumerate(A[:idx]):
  j = 1
  b = a + M
  if b < Ap:
    continue
  n0 = bisect.bisect_right(A, a) # M人全員から投票されてもbを超えない問題の数
  n1 = N - bisect.bisect_left(A, b+1) # 投票されない状態で既にbより点数が高い問題の数
  mv = (V - n0) * M # 上の問題達には取り敢えず投票しておいて、他に選べる問題の数
  if mv <= 0:
    j = 0
    break
  else:
    res = False
    p = P - 1
    for _a in A[n0:][::-1]:
      if p:
        p -= 1
        diff = M
      else:
        diff = b - _a
      if diff <= 0:
        break
      else:
        mv -= diff
        if mv <= 0:
          res = True
          j = 0
          break
    if res:
      break

ans += idx - i - j # 一度候補に入る数を発見したら、それ以降も当然候補に入る
print(ans)
Problem p02838 (python)

Fixed submission:
import numpy as np
 
mod = 10**9 + 7
max_digit = 60
N = int(input())
A = np.array(list(map(int, input().split())))

result = 0
base = 1
for _ in range(max_digit + 1):
  a = A % 2
  c = np.count_nonzero(a == 0)
  result = (result + (base*(N - c)*c) % mod) % mod
  A = A >> 1
  base *= 2

print(result)

Buggy submission (verdict: Runtime Error):
import numpy as np
 
mod = 10**9 + 7
N = input()
A = np.array(list(map(int, input().split())))
A = np.atleast_2d(A)

print((np.sum((A ^ A.T) % mod) % mod) // 2)

Buggy submission (verdict: Runtime Error):
import numpy as np
 
mod = 10**9 + 7
N = input()
A = np.array(list(map(int, input().split())), dtype='uint64') % mod
A = np.atleast_2d(A)

print((np.sum((A ^ A.T) % mod) % mod) // 2)

Buggy submission (verdict: Runtime Error):
import numpy as np

mod = 10**9 + 7
N = input()
A = np.atleast_2d(list(map(int, input().split()))) % mod

print((np.sum((A ^ A.T) % mod) % mod) // 2)
Problem p02843 (python)

Fixed submission:
X = int(input())

dp = [False] * (X + 1)
dp[0] = True
for i in range(X):
  if dp[i]:
    for x in [100, 101, 102, 103, 104, 105]:
      if i+x <= X:
        dp[i+x] = True

if dp[-1]:
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
X = int(input().split())

dp = [False] * (X + 1)
dp[0] = True
for i in range(X):
  if i:
    for x in [100, 101, 102, 103, 104, 105]:
      if i+x <= X:
        dp[i+x] = True

if dp[-1]:
  print(1)
else:
  print(0)
Problem p02845 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

ans = 1
num_color = [-1, -1, -1]
for a in A:
  ans = (ans * num_color.count(a-1)) % MOD
  try:
    num_color[num_color.index(a-1)] = a
  except:
    print(0)
    quit()

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

ans = 1
num_color = [-1, -1, -1]
for a in A:
  ans = (ans * num_color.count(a-1)) % MOD
  num_color[num_color.index(a-1)] = a

print(ans)
Problem p02850 (python)

Fixed submission:
from collections import deque

N = int(input())

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


q = deque()
q.append([0, 0, 0])

colors = [0] * (N-1)
while q:
  node, parent, edge_color = q.popleft()
  c = 1
  for child, index in G[node]:
    if child == parent:
      continue
    
    if c == edge_color:
      c += 1
    
    q.append([child, node, c])
    colors[index] = c
    c += 1

print(max(colors))
print(*colors, sep='\n')

Buggy submission (verdict: Runtime Error):
N = int(input())
count = [0 for i in range(N)]
n = []
for _ in range(N-1):
  a, b = map(int, input().split())
  count[a-1] += 1
  count[b-1] += 1
  n.append([a, b])

K = max(count)
All = set(range(1, K+1))
memo = [[] for i in range(N)]
print(K)
for a, b in n:
  m = list(All - set(memo[a-1] + memo[b-1]))[0]
  memo[a-1].append(m)
  memo[b-1].append(m)
  print(m)

Buggy submission (verdict: Runtime Error):
N = int(input())
count = [0 for i in range(N)]
n = []
for _ in range(N-1):
  a, b = map(int, input().split())
  count[a-1] += 1
  count[b-1] += 1
  n.append([a, b])

K = max(count)
All = set([j for j in range(1, K+1)])
memo = [[] for i in range(N)]
print(K)
for i in range(N-1):
  a, b = n[i]
  m = list(All - set(memo[a-1] + memo[b-1]))[0]
  memo[a-1].append(m)
  memo[b-1].append(m)
  print(m)
Problem p02852 (python)

Fixed submission:
N, M = map(int, input().split())
S = input()

steps = [[] for i in range(N+1)]
steps[0] = [0]
num_steps = 0
root = [0] + [-1]*N
pos = 1

while pos <= N:
  starts = steps[num_steps]
  if not starts:
    break
  for start in starts:
    end = min(start+M+1, N+1)
    for i in range(pos, end):
      if S[i] == '0':
        steps[num_steps+1].append(i)
        root[i] = start
    
    pos = end
  
  num_steps += 1


if root[N] == -1:
  ans = -1
else:
  pos = N
  ans = []
  while pos > 0:
    pre_pos = root[pos]
    ans.append(str(pos - pre_pos))
    pos = pre_pos
  
  ans = ans[::-1]
  ans = ' '.join(ans)


print(ans)

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

steps = [[] for i in range(N)]
steps[0] = [0]
num_steps = 0
root = [0] + [-1]*N
pos = 1

while pos <= N:
  starts = steps[num_steps]
  if not starts:
    break
  for start in starts:
    end = min(start+M+1, N+1)
    for i in range(pos, end):
      if S[i] == '0':
        steps[num_steps+1].append(i)
        root[i] = start
    
    pos = end
  
  num_steps += 1


if root[N] == -1:
  ans = -1
else:
  pos = N
  ans = []
  while pos > 0:
    pre_pos = root[pos]
    ans.append(str(pos - pre_pos))
    pos = pre_pos
  
  ans = ans[::-1]
  ans = ' '.join(ans)


print(ans)

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

steps = [[] for i in range(N)]
steps[0] = [0]
num_steps = 0
root = [0] + [-1]*N
pos = 1

while pos <= N:
  starts = steps[num_steps]
  if not starts:
    ans = -1
    break
  for start in starts:
    end = min(start+M+1, N+1)
    for i in range(pos, end):
      if S[i] == '0':
        steps[num_steps+1].append(i)
        root[i] = start
    
    pos = end
  
  num_steps += 1


if pos == N+1:
  pos = N
  ans = []
  while pos > 0:
    pre_pos = root[pos]
    ans.append(str(pos - pre_pos))
    pos = pre_pos
  
  ans = ans[::-1]
  ans = ' '.join(ans)


print(ans)
Problem p02853 (python)

Fixed submission:
X, Y = map(int, input().split())
price = [0, 300000, 200000, 100000] + [0]*300
ans = price[X] + price[Y] + 400000*(X == Y == 1)

print(ans)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
price = [0, 300000, 200000, 100000]
ans = price[X] + price[Y] + 400000*(X == Y == 1)

print(ans)
Problem p02920 (python)

Fixed submission:
N = int(input())
N2 = 2**N
S = list(map(int, input().split()))
S.sort(reverse=True)

slimes = [S[0]]
S[0] = float('inf')
num = 1
for i in range(N):
  slimes.sort()
  n = num
  idx = 0
  while n and idx<=N2-1:
    if S[idx] < slimes[n-1]:
      slimes.append(S[idx])
      S[idx] = float('inf')
      idx += 1
      n -= 1
    else:
      idx += 1
  
  if n:
    print('No')
    quit()
  
  num *= 2

print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
N2 = 2**N
S = list(map(int, input().split()))
S.sort(reverse=True)

slimes = [S[0]]
S[0] = float('inf')
num = 1
min_idx = 1
for i in range(N):
  slimes.sort()
  n = num
  idx = min_idx
  is_continuous = True
  while n and idx<=N2-1:
    if S[idx] < slimes[n-1]:
      slimes.append(S[idx])
      S[idx] = float('inf')
      idx += 1
      n -= 1
      min_idx += is_continuous:
    else:
      if S[idx] < float('inf'):
        is_continuous = False
      idx += 1
      min_idx += is_continuous
  
  if n:
    print('No')
    quit()
  
  num *= 2

print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)

n = [0] * (2**N)
n[0] = N
_n = N-2
for i in range(1, 2**N):
  nn = n[i-1] - 1
  if nn >= 0:
    n[i] = nn
  else:
    n[i] = _n
    _n -= 1
    if _n < 0:
      if i+1 < 2**N:
        n[i+1] = 1
      break


par = 0
idx = 1
res = True
while idx < 2**N:
  for i in range(n[par]):
    res *= S[par] > S[idx]
    if not res:
      print('No')
      quit()
    idx += 1
  par += 1

print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)

n = [0] * (2**N)
n[0] = N
_n = N-2
for i in range(1, 2**N):
  nn = n[i-1] - 1
  if nn >= 0:
    n[i] = nn
  else:
    n[i] = _n
    _n -= 1
    if _n < 0:
      n[i+1] = 1
      break


par = 0
idx = 1
res = True
while idx < 2**N:
  for i in range(n[par]):
    res *= S[par] > S[idx]
    if not res:
      print('No')
      quit()
    idx += 1
  par += 1

print(n)
print('Yes')