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

Fixed submission:
s = input()
q = int(input())
appendix = [[], []]
reverse = False
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    reverse ^= True
  else:
    f = bool(int(query[1]) - 1)
    appendix[int(f ^ reverse)].append(query[2])
if reverse:
  print(''.join(appendix[1][::-1]) + s[::-1] + ''.join(appendix[0]))
else:
  print(''.join(appendix[0][::-1]) + s + ''.join(appendix[1]))

Buggy submission (verdict: Runtime Error):
s = input()
q = int(input())
appendix = [[], []]
reverse = False
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    reverse ^= True
  else:
    f = bool(int(query[1]) - 1)
    appendix[int(f ^ reverse)].append(query[2])
print(''.join(appendix[int(reverse)][::-1]) + s + ''.join(appendix[int(not reverse)])
Problem p02758 (python)

Fixed submission:
import heapq

mod = 998244353

n = int(input())
robot = [tuple(map(int, input().split())) for _ in range(n)]
robot.sort(reverse=True)
parent = list(range(n))

root = []
for i in range(n):
  x, d = robot[i]
  while root:
    r = heapq.heappop(root)
    if r[0] < x + d:
      parent[r[1]] = i
    else:
      heapq.heappush(root, r)
      break
  heapq.heappush(root, (x, i))
  
count = 1
dp = [1] * n
for i in range(n):
  p = parent[i]
  if p == i:
    count = count * (dp[i] + 1) % mod
  else:
    dp[p] = dp[p] * (dp[i] + 1) % mod
print(count)

Buggy submission (verdict: Runtime Error):
import heapq

mod = 998244353

def dfs(v: int, child) -> int:
  res = 1
  for u in child[v]:
    res = res * dfs(u, child) % mod
  return res + 1

n = int(input())
robot = [tuple(map(int, input().split())) for _ in range(n)]
robot.sort()
child = [[] for _ in range(n)]

root = []
for i in range(n-1, -1, -1):
  x, d = robot[i]
  while root:
    r = heapq.heappop(root)
    if r[0] < x + d:
      child[i].append(r[1])
    else:
      heapq.heappush(root, r)
      break
  heapq.heappush(root, (x, i))
  
count = 1
for r in root:
  count = count * dfs(r[1], child) % mod
print(count)

Buggy submission (verdict: Runtime Error):
import heapq

mod = 998244353

def dfs(v: int, child) -> int:
  res = 1
  for u in child[v]:
    res = res * dfs(u) % mod
  return res + 1

n = int(input())
robot = [tuple(map(int, input().split())) for _ in range(n)]
robot.sort()
child = [[] for _ in range(n)]

root = []
for i in range(n-1, -1, -1):
  x, d = robot[i]
  while root:
    r = heapq.heappop(root)
    if r[0] < x + d:
      child[i].append(r[1])
    else:
      heapq.heappush(root, r)
      break
  heapq.heappush(root, (x, i))
  
count = 1
for r in root:
  count = count * dfs(r[1], child) % mod
print(count)

Buggy submission (verdict: Runtime Error):
import heapq

mod = 998244353

def dfs(v: int) -> int:
  res = 1
  for u in child[v]:
    res = res * dfs(u) % mod
  return res + 1

n = int(input())
robot = [tuple(map(int, input().split())) for _ in range(n)]
robot.sort()
child = [[] for _ in range(n)]

root = []
for i in range(n-1, -1, -1):
  x, d = robot[i]
  while root:
    r = heapq.heappop(root)
    if r[0] < x + d:
      child[i].append(r[1])
    else:
      heapq.heappush(root, r)
      break
  heapq.heappush(root, (x, i))
  
count = 1
for r in root:
  count = count * dfs(r[1]) % mod
print(count)

Buggy submission (verdict: Runtime Error):
import heapq

def dfs(v: int) -> int:
  res = 1
  for u in child[v]:
    res *= dfs(u)
  return res + 1

n = int(input())
robot = [tuple(map(int, input().split())) for _ in range(n)]
robot.sort()
child = [[] for _ in range(n)]

root = []
for i in range(n-1, -1, -1):
  x, d = robot[i]
  while root:
    r = heapq.heappop(root)
    if r[0] < x + d:
      child[i].append(r[1])
    else:
      heapq.heappush(root, r)
      break
  heapq.heappush(root, (x, i))
  
count = 1
for r in root:
  count *= dfs(r[1])
print(count)
Problem p02765 (python)

Fixed submission:
n, r = map(int, input().split())
print(r + 100 * (10 - min(n, 10)))

Buggy submission (verdict: Runtime Error):
k, q = map(int, input().split())
d = list(map(int, input().split()))
for _ in range(q):
  n, x, m = map(int, input().split())
  dmod = [di % m for di in d]
  same = dmod.count(0) * ((n-1) // k) + dmod[: (n-1) % k].count(0)
  a_last = x + sum(dmod) * ((n-1) // k) + sum(dmod[: (n-1) % k])
  beyond = a_last // m - x // m
  print(n - 1 - same - beyond)
Problem p02770 (python)

Fixed submission:
import numpy as np

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - np.count_nonzero(dmod)) * quot + rest - np.count_nonzero(dmod[:rest])
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)

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

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - dmod.count_nonzero()) * quot + rest - dmod[:rest].count_nonzero()
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)
Problem p02782 (python)

Fixed submission:
mod = 10**9 + 7

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

fact = [1] * (r2 + c2 + 3)
inv = [1] * (r2 + c2 + 3)
inv_fact = [1] * (r2 + c2 + 3)
for i in range(2, r2 + c2 + 3):
  fact[i] = fact[i-1] * i % mod
  inv[i] = -inv[mod % i] * (mod // i) % mod
  inv_fact[i] = inv_fact[i-1] * inv[i] % mod

total = fact[r2 + c2 + 2] * inv_fact[r2 + 1] * inv_fact[c2 + 1] % mod
total -= fact[r1 + c2 + 1] * inv_fact[r1] * inv_fact[c2 + 1] % mod
total -= fact[r2 + c1 + 1] * inv_fact[c1] * inv_fact[r2 + 1] % mod
total += fact[r1 + c1] * inv_fact[r1] * inv_fact[c1] % mod

print(total % mod)

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

mod = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())
f = np.ones((r2 + 1, c2 + 1), dtype=np.int)
g = np.ones((r2 + 1, c2 + 1), dtype=np.int)
for i, j in np.ndindex(r2, c2):
  f[i+1, j+1] = (f[i, j+1] + f[i+1, j]) % mod
print(f[r1:, c1:].sum() % mod)

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

mod = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())
f = np.ones((r2 + 1, c2 + 1), dtype=np.int)
g = np.ones((r2 + 1, c2 + 1), dtype=np.int)
for i, j in np.ndindex(r2, c2):
  f[i+1, j+1] = (f[i, j+1] + f[i+1, j]) % mod
print(f[r1:, c2:].sum() % mod)

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

r1, c1, r2, c2 = map(int, input().split())
f = np.ones((r2 + 1, c2 + 1), dtype=np.int)
g = np.ones((r2 + 1, c2 + 1), dtype=np.int)
for i, j in np.ndindex(r2, c2):
  f[i+1, j+1] = f[i, j+1] + f[i+1, j]
print(f[r1:, c2:].sum())

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

r1, c1, r2, c2 = map(int, input().split())
f = np.ones((r2 + 1, c2 + 1), dtype=np.int)
g = np.ones((r2 + 1, c2 + 1), dtype=np.int)
for i, j in np.ndindex(r2, c2)
  f[i+1, j+1] = f[i, j+1] + f[i+1, j]
print(f[r1:, c2:].sum())
Problem p02783 (python)

Fixed submission:
h, a = map(int, input().split())
print((h-1)//a + 1)

Buggy submission (verdict: Runtime Error):
n, d, a = map(int, input().split())
monster = []
for _ in range(n):
  x, h = map(int, input().split())
  monster.append([x, h])
monster.sort()
bomb = 0
j = 0
for i in range(n):
  while j < n and monster[j][0] - monster[i][0] <= 2 * d:
    j += 1
  if monster[i][1] <= 0:
    continue
  b = (monster[i][1] - 1) // a + 1
  atk = a * b
  bomb += b
  for k in range(i+1, j):
    monster[k][1] -= atk
print(bomb)
Problem p02786 (python)

Fixed submission:
h = int(input())
print(2 ** (len(bin(h)) - 2) - 1)

Buggy submission (verdict: Runtime Error):
h = int(input().split())
print(2 ** (len(bin(h)) - 2) - 1)
Problem p02788 (python)

Fixed submission:
import heapq
from collections import deque

n, d, a = map(int, input().split())
monster = []
for _ in range(n):
  x, h = map(int, input().split())
  heapq.heappush(monster, (x, h))
bomb = 0
damage = 0
queue = deque()
while monster:
  x, h = heapq.heappop(monster)
  while True:
    if queue and x > queue[0][0]:
      damage -= queue.popleft()[1]
    else:
      break
  h -= damage
  if h <= 0:
    continue
  b = (h - 1) // a + 1
  bomb += b
  queue.append((x + 2 * d, a * b))
  damage += a * b
print(bomb)

Buggy submission (verdict: Runtime Error):
n, d, a = map(int, input().split())
monster = []
for _ in range(n):
  x, h = map(int, input().split())
  monster.append((x, h))
monster.sort()
bomb = 0
j = 0
for i in range(n):
  while monster[j][0] - monster[i][0] <= 2 * d and j < n:
    j += 1
  if monster[i][1] <= 0:
    continue
  b = (monster[i][1] - 1) // a + 1
  atk = a * b
  bomb += b
  for k in range(i+1, j):
    monster[k][1] -= atk
print(bomb)
Problem p02837 (python)

Fixed submission:
n = int(input())
peaple = []
for i in range(n):
  a = int(input())
  tests = []
  for j in range(a):
    x, y = input().split()
    tests.append((int(x) - 1, y))
  peaple.append(tests)
  
maximum = 0
for h_bit in range(1, 1<<n):
  h_str = format(h_bit, '0{}b'.format(n))
  flag = False
  for i in range(n):
    if h_str[i] == '1':
      for test in peaple[i]:
        if h_str[test[0]] != test[1]:
          flag = True
          break
    if flag:
      break
  if not flag:
    maximum = max(maximum, h_str.count('1'))
print(maximum)

Buggy submission (verdict: Runtime Error):
n = int(input())
peaple = []
for i in range(n):
  a = int(input())
  tests = []
  for j in range(a):
    x, y = input().split()
    tests.append((int(x) - 1, y))
  peaple.append(tests)
  
maximum = 0
for h_bit in range(1, 1<<n):
  h_str = format(h_bit, '0{}b'.format(n))
  flag = False
  for i in range(n):
    if h_str[i] == '1':
      for tests in peaple[i]:
        for test in tests:
          if h_str[test[0]] != test[1]:
            flag = True
            break
        if flag:
          break
    if flag:
      break
  if not flag:
    maximum = max(maximum, h_str.count('1'))
print(maximum)
Problem p02845 (python)

Fixed submission:
n = int(input())

hats = [0, 0, 0]
count = 1
mod = 1000000007

for a in map(int, input().split()):
  count *= hats.count(a)
  count %= mod
  try:
    hats[hats.index(a)] += 1
  except ValueError:
    count = 0
    break
  
print(count)

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

hats = [0, 0, 0]
count = 1
mod = 1000000007

for a in map(int, input().split()):
  count *= hats.count(a)
  count %= mod
  hats[hats.index(a)] += 1
  
print(count)

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

hats = [0, 0, 0]
count = 1
mod = 1000000007

for a in map(int, input().split()):
  count *= hats.count(a)
  count %= mod
  count[count.index(a)] += 1
  
print(count)
Problem p02861 (python)

Fixed submission:
import numpy as np

n = int(input())
x = np.array([input().split() for _ in range(n)], dtype=np.int)
norm2 = np.sum(x * x, axis=1)
dist = -2. * x.dot(x.T) + norm2
dist = np.sqrt(dist.T + norm2)
print(dist.sum() / n)

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

n = int(input())
x = np.array([input().split() for _ in range(n)], dtype=np.int)
norm2 = np.sum(x * x, axis=1)
dist = -2. * x @ x.T + norm2
dist = np.sqrt(dist.T + norm2)
print(dist.sum() / (n - 1))
Problem p02867 (python)

Fixed submission:
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
b = np.array(input().split(), dtype=np.int)
arg = np.argsort(b)
a = a[arg]
b = b[arg]
arg = np.argsort(a)
if np.all(a[arg] <= b):
  i = arg[0]
  cycle_size = 1
  while i != 0:
    i = arg[i]
    cycle_size += 1
  if cycle_size == n and np.all(a[arg[1:]] > b[:-1]):
    print('No')
  else:
    print('Yes')
else:
  print('No')

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

n = int(input())
a = np.array(input().split(), dtype=np.int)
b = np.array(input().split(), dtype=np.int)
flag = False
mask = ~np.identity(n, dtype=np.bool)
for i in np.where(a <= b)[0]:
  if np.all(np.sort(a[mask[i]]) <= np.sort(b[mask[i]])):
    flag = True
    break
if flag:
  print('Yes')
else:
  print('No')

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

n = int(input())
a = np.array(input().split(), dtype=np.int)
b = np.array(input().split(), dtype=np.int)
flag = False
mask = ~np.identity(n, dtype=np.bool)
for i in np.where(a <= b)[0]:
  if np.all(a[mask[i]].sort() <= b[mask[i]].sort()):
    flag = True
    break
if flag:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split())).sort()
b = list(map(int, input().split())).sort()
flag = True
for i in range(n):
  if a[i] > b[i]:
    flag = False
    break
if flag:
  print('Yes')
else:
  print('No')
Problem p02868 (python)

Fixed submission:
import heapq

n, m = map(int, input().split())
edge = [[]] + [[(0, i)] for i in range(n-1)]
for _ in range(m):
  l, r, c = map(int, input().split())
  edge[l-1].append((c, r-1))

inf = 1 << 60
dp = [0] + [inf] * (n - 1)
queue = [(0, 0)]
check = [False] * n
while queue and not check[-1]:
  dist, act = heapq.heappop(queue)
  check[act] = True
  for cost, vertex in edge[act]:
    if check[vertex]:
      continue
    d = dist + cost
    if dp[vertex] > d:
      heapq.heappush(queue, (d, vertex))
      dp[vertex] = d
if dp[-1] < inf:
  print(dp[-1])
else:
  print(-1)

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

n, m = map(int, input().split())
edge_l = []
edge_r = []
edge_c = []
for _ in range(m):
  l, r, c = map(int, input().split())
  edge_l.append(l - 1)
  edge_r.append(r - 1)
  edge_c.append(c)
l = np.array(edge_l, dtype=np.int)
r = np.array(edge_r, dtype=np.int)
c = np.array(edge_c, dtype=np.int)

dp = np.ones(n, dtype=np.int) * (c.sum() + 1)
dp[0] = 0
active = np.zeros(n, dtype=np.bool)
active[0] = True
while np.any(active):
  act = np.argmax(active)
  use = (l <= act) * (r > act)
  dp[r] = np.minimum(np.min(dp[r[use]] + c[use]), dp[r])
  active[act] = False
  
if dp[-1] > c.sum():
  print(-1)
else:
  print(dp[-1])
Problem p02869 (python)

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

if 2 * k - 1 > n:
  print(-1)
else:
  half_n = n // 2
  if n % 2 == 0:
    for i in range(half_n):
      a = k + i
      b = k + n + i + half_n
      c = k + 2 * n + 2 * i
      print(a, b, c)
      a += half_n
      b -= half_n
      c += 1
      print(a, b, c)
  else:
    for i in range(half_n):
      a = k + i
      b = k + n + i + half_n
      c = k + 2 * n + 2 * i
      print(a, b, c)
      a += half_n + 1
      b -= half_n
      c += 1
      print(a, b, c)
    a = k + half_n
    b = k + n + 2 * half_n
    c = k + 2 * n + 2 * half_n
    print(a, b, c)

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

if 2 * k - 1 > n:
  print(-1)
else:
  d = (n + 1) // 2
  flag_a = False
  for i in range(n):
    a = k + i // 2
    b = k + n + i // 2
    c = k + 2 * n + i
    if flag_a:
      a += d
    else:
      b += d
    print(a, b, c)
    flag = not flag
Problem p02883 (python)

Fixed submission:
import numpy as np

n, k = map(int, input().split())
a = np.sort(np.array(input().split(), dtype=np.int))
f = np.sort(np.array(input().split(), dtype=np.int))
time = f * a[::-1]

sup = time.max()
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  train = ((np.maximum(time - x, 0) + f - 1) // f).sum()
  if k < train:
    inf = x + 1
  else:
    sup = x
print(sup)

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

n, k = map(int, input().split())
a = np.sort(np.array(input().split(), dtype=np.int))
f = np.sort(np.array(input().split(), dtype=np.int))
time = f * a[::-1]

sup = time.max()
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  train = ((time[time > x] - x + f - 1) // f).sum()
  if k < train:
    inf = x + 1
  else:
    sup = x
print(sup)
Problem p02885 (python)

Fixed submission:
a, b = map(int, input().split())
c = a - 2 * b
if c > 0:
  print(c)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
c = a - 2 * b
if c > 0:
  print(c)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
c = a - 2 * b
if c > 0:
  print(c)
else:
  print(0)
Problem p02909 (python)

Fixed submission:
weather = input()

if weather == 'Sunny':
  print('Cloudy')
elif weather == 'Cloudy':
  print('Rainy')
else:
  print('Sunny')

Buggy submission (verdict: Runtime Error):
def calc_length(s: str, l1: int, l2: int, n: int) -> int:
  max_len = min([l2 - l1, n - l2])
  for i in range(1, max_len):
    if s[l1 + i] != s[l2 + i]:
      return i
  return max_len

n = int(input())
s = input()

longest = 0
for l1 in range(n - 2, -1, -1):
  for l2 in range(l1 + longest + 1, n):
    if s[l1] == s[l2]:
      length = calc_length(s, l1, l2, n)
      if length > longest:
        longest = length

print(longest)
Problem p02911 (python)

Fixed submission:
n, k, q = list(map(int, input().split()))
answer = [0 for i in range(n)]
 
for i in range(q):
  answer[int(input()) - 1] += 1
  
for i in range(n):
  if q - answer[i] < k:
    print('Yes')
  else:
    print('No')

Buggy submission (verdict: Runtime Error):
n, k, q = list(map(int, input().split()))
answer = [0 for i in range(n)]

for i in range(q):
  answer[int(input())] += 1
  
for i in range(n):
  if q - answer[i] < k:
    print('Yes')
  else:
    print('No')
Problem p02913 (python)

Fixed submission:
n = int(input())
s = input()

l1 = l2 = length = 0

while l2 + length < n:
  if s[l1 : l2] in s[l2:]:
    length = l2 - l1
    l2 += 1
  else:
    l1 += 1
    l2 = l1 + length + 1

print(length)

Buggy submission (verdict: Runtime Error):
def calc_length(s: str, l1: int, l2, int, n: int) -> int:
  for i in range(1, min[l2 - l1, n - l2]):
    if s[l1 + i] != s[l2 + i]:
      return i
  return i + 1

n = int(input())
s = input()

longest = 0
for l1 in range(n - 1):
  for l2 in range(l1 + 1, n):
    if s[l1] == s[l2]:
      length = calc_length(s, l1, l2, n)
      if length > longest:
        longest = length

print(longest)
Problem p02918 (python)

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

happy = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    happy += 1
print(min([N-1, happy + 2 * K]))

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
S = list(map(int, input().split()))
 
happy = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    happy += 1
print(min([N-1, happy + 2 * K]))

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

happy = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    happy += 1
return min([N-1, happy + 2 * K])

Buggy submission (verdict: Runtime Error):
def calculate_happiness(S: str, N: int) -> int:
  if N == 1:
    return 0
  happiness = 0
  if S[0] == S[1] == 'R':
    happiness += 1
  if S[-1] == S[-2] == 'L':
    happiness += 1
  for i in range(1, N-1):
    if S[i] == S[i+1] == 'R':
      happiness += 1
    elif S[i] == S[i-1] == 'L':
      happiness += 1
  return happiness

def change_string(S: str, l: int, r: int) -> str:
  part = S[l:r+1][::-1].replace('R', '_')
  part = part.replace('L', 'R').replace('_', 'L')
  return S[:l] + part + S[r+1:]

N, K = list(map(int, input().split()))
S = input()
happiness = calculate_happiness(S, N)
opt_S = S
opt_happiness = happpiness
for k in range(K):
  S = opt_S
  for l in range(N-1):
    for r in range(l+1:N):
      new_S = change_string(S, l, r)
      happiness = calculate_happiness(new_S, N)
      if happiness > opt_happiness:
        opt_S = new_S
        opt_happiness = happiness
return(opt_happiness)
Problem p02923 (python)

Fixed submission:
n = int(input())
max_step = 0
step = 0
pre_h = 0
for h in map(int, input().split()):
  if h <= pre_h:
    step += 1
  else:
    if max_step < step:
      max_step = step
    step = 0
  pre_h = h
print(max([max_step, step]))

Buggy submission (verdict: Runtime Error):
n = int(input())
max_step = 0
step = 0
pre_h = 0
for h in map(int, input().split()):
  if h <= pre_h:
    step += 1
  else:
    if max_step < step:
      max_step = step
    step = 0
  pre_h = h
print(max[max_step, step])
Problem p02947 (python)

Fixed submission:
n = int(input())
words = dict()
count = 0
for i in range(n):
  s = ''.join(sorted(input()))
  if s in words:
    count += words[s]
    words[s] += 1
  else:
    words[s] = 1
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
words = dict()
count = 0
for i in range(n):
  s = sorted(input())
  if s in words:
    count += words[s]
    words[s] += 1
  else:
    words[s] = 0
print(count)
Problem p02958 (python)

Fixed submission:
n = int(input())

wrong = 0
for i, p in enumerate(map(int, input().split()), start=1):
  wrong += int(i != p)

if wrong == 0 or wrong == 2:
  print('YES')
else:
  print('NO')

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

wrong = 0
for i, p in enemerate(map(int, input().split()), start=1):
  wrong += int(i != p)

if wrong == 0 or wrong == 2:
  print('YES')
else:
  print('NO')
Problem p02985 (python)

Fixed submission:
mod = 10 ** 9 + 7

n, k = map(int, input().split())
edge = [[] for _ in range(n)]
parent = [0] * n
permutation_k2 = [1] * n
for i in range(n-1):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
  permutation_k2[i+1] = permutation_k2[i] * (k - 2 - i) % mod
count = k * (k - 1) * permutation_k2[len(edge[0]) - 1] % mod
queue = edge[0]
while queue:
  vertex = queue.pop()
  count = count * permutation_k2[len(edge[vertex]) - 1] % mod
  p = parent[vertex]
  for v in edge[vertex]:
    if v == p:
      continue
    queue.append(v)
    parent[v] = vertex
if n == 1:
  print(k)
else:
  print(count)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7

n, k = map(int, input().split())
edge = [[] for _ in range(n)]
parent = [0] * n
for _ in range(n):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
permutation_k2 = [1] * n
for i in range(n-1):
  permutation_k2[i+1] = permutation_k2[i] * (k - 2 - i) % mod
count = k * (k - 1) * permutation_k2[len(edge[0]) - 1] % mod
queue = edge[0]
while queue:
  vertex = queue.pop()
  count = count * permutation_k2[len(edge[vertex]) - 1] % mod
  p = parent[vertex]
  for v in edge[vertex]:
    if v == p:
      continue
    queue.append(v)
    parent[v] = vertex
print(count)
Problem p02991 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
adj_list = [[] for _ in range(3 * n)]
for _ in range(m):
  u, v = map(int, input().split())
  adj_list[3 * u - 3].append(3 * v - 2)
  adj_list[3 * u - 2].append(3 * v - 1)
  adj_list[3 * u - 1].append(3 * v - 3)

s, t = map(int, input().split())
dist = [-1] * (3 * n)
queue = deque([3 * s - 3])
dist[3 * s - 3] = 0
while queue:
  vertex = queue.popleft()
  for next_vertex in adj_list[vertex]:
    if dist[next_vertex] != -1:
      continue
    dist[next_vertex] = dist[vertex] + 1
    queue.append(next_vertex)
t_distance = dist[3 * t - 3]
if t_distance == -1:
  print(-1)
else:
  print(t_distance // 3)

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

n, m = map(int, input().split())
adj_list = [[] for _ in range(3 * n)]
for _ in range(m):
  u, v = map(int, input().split())
  adj_list[3 * u - 3].append(3 * v - 2)
  adj_list[3 * u - 2].append(3 * v - 1)
  adj_list[3 * u - 1].append(3 * v - 3)

s, t = map(int, input().split())
dist = [-1] * (3 * n)
queue = deque([3 * s - 3])
dist[3 * s - 3] = 0
while queue:
  vertex = queue.leftpop()
  for next_vertex in adj_list[vertex]:
    if dist[next_vertex] == -1:
      continue
    dist[next_vertex] = dist[vertex] + 1
    queue.append(next_vertex)
t_distance = dist[3 * t - 3]
if t_distance == -1:
  print(-1)
else:
  print(t_distance // 3)
Problem p02994 (python)

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

total = (l - 1) * n + n * (n + 1) // 2
min_diff = 1e20
for i in range(n):
  apple = l + i
  apple_pie = total - apple
  diff = abs(apple)
  if diff < min_diff:
    min_diff = diff
    min_apple_pie = apple_pie
print(min_apple_pie)

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

total = (l - 1) * n + n * (n + 1) // 2
min_diff = abs(total)
for i in range(n):
  apple = l + i
  apple_pie = total - apple
  diff = abs(apple)
  if diff < min_diff:
    min_diff = diff
    min_apple_pie = apple_pie
print(min_apple_pie)