Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from numpy import argmax as mode
from numpy import bincount as bc
N = int(input())
V = list(map(int, input().split()))
a = [V[2 * i] for i in range(N // 2)]
b = [V[2 * i + 1] for i in range(N // 2 + N % 2)]
bca = bc(a)
bcb = bc(b)
#print(bca, bcb)
if mode(bca) == mode(bcb):
  print(N - a.count(mode(bca)) - max(sorted(bca)[-2], sorted(bcb)[-2]))
else:
  print(N - a.count(mode(bca)) - b.count(mode(bcb)))

Fixed submission:
from numpy import argmax as mode
from numpy import bincount as bc
N = int(input())
V = list(map(int, input().split()))
a = [V[2 * i] for i in range(N // 2)]
b = [V[2 * i + 1] for i in range(N // 2 + N % 2)]
bca = bc(a)
bcb = bc(b)
#print(bca, bcb)
if mode(bca) == mode(bcb):
  print(N - a.count(mode(bca)) - max(sorted(bca)[-2], sorted(bcb)[-2]))
else:
  print(N - a.count(mode(bca)) - b.count(mode(bcb)))
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
from collections import deque as dq
input = sys.stdin.readline
N, M = map(int, input().split())
S = list(input())[: -1]
e = dd(list)
a = [0] * (N + 1)
b = [0] * (N + 1)
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

Q = dq([])
for x in range(1, N + 1):
  for y in e[x]:
    if S[y] == "A": a[x] += 1
    if S[y] == "B": b[x] += 1
  if a[x] == 0 or (b[x] == 0): Q.append(x)

vis = [0] * (N + 1)
while len(Q):
  x = Q.popleft()
  vis[x] = 1
  for y in e[x]:
    if S[x] == "A": a[y] -= 1
    if S[y] == "B": b[y] -= 1
    if a[y] == 0 or (b[y] == 0): Q.append(y)

if sum(vis) < N: print("Yes")
else: print("No")

Fixed submission:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
S = ["?"] + list(input())[: -1]
e = dd(set)
a = [0] * (N + 1)
b = [0] * (N + 1)
for _ in range(M):
  u, v = map(int, input().split())
  e[u].add(v)
  e[v].add(u)

s = []
for x in range(1, N + 1):
  for y in e[x]:
    if S[y] == "A": a[x] += 1
    if S[y] == "B": b[x] += 1
  if a[x] == 0 or (b[x] == 0): s.append(x)

vis = [0] * (N + 1)
while len(s):
  x = s.pop()
  if vis[x]: continue
  vis[x] = 1
  for y in e[x]:
    if x == y: continue
    if S[x] == "A": a[y] -= 1
    if S[x] == "B": b[y] -= 1
    if a[y] == 0 or (b[y] == 0): s.append(y)
 
if sum(vis) < N: print("Yes")
else: print("No")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
S = list(map(int, list(input())[: -1]))
K = int(input())
x = 0
for i in range(len(S)):
  if S[i] == 1: x += 1
  else: break
if S[0] == 1:
  if K == x: print(1)
  else: print(S[x])
else: print(S[0])

Fixed submission:
import sys
input = sys.stdin.readline
S = list(map(int, list(input())[: -1]))
K = int(input())
x = 0
for i in range(len(S)):
  if S[i] == 1: x += 1
  else: break
if K <= x: print(1)
else: print(S[x])
Buggy python submission (verdict: Time Limit Exceeded):
D, G = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(D)]
visited = [0] * D
def dfs(s, c):
  temp = 10 ** 3
  for i in range(D):
    if visited[i] == 0:
      visited[i] = 1
      if s >= p[i][0] * (i + 1) * 100 + p[i][1]:
        temp = min(temp, dfs(s - p[i][0] * (i + 1) * 100 - p[i][1], c + p[i][0]))
      else:
        temp = min(temp, -(-s // ((i + 1) * 100)) + c, p[i][0] + c)
      visited[i] = 0
  return temp
print(dfs(G, 0))

Fixed submission:
D, G = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(D)]
visited = [0] * D
def dfs(s, c):
  temp = 10 ** 3
  for i in range(D):
    if visited[i] == 0:
      visited[i] = 1
      if s >= p[i][0] * (i + 1) * 100 + p[i][1]:
        temp = min(temp, dfs(s - p[i][0] * (i + 1) * 100 - p[i][1], c + p[i][0]))
      else:
        temp = min(temp, -(-s // ((i + 1) * 100)) + c, p[i][0] + c)
      visited[i] = 0
  return temp
print(dfs(G, 0))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations as 敬語使うべきじゃん
N, C = map(int, input().split())
D = [[0] * (C + 1)] + [[0] + list(map(int, input().split())) for _ in range(C)]
c = [[0] * (N + 1)] + [[0] + list(map(int, input().split())) for _ in range(N)]
#print(D, c)

group = [[] for _ in range(3)]
for i in range(1, N + 1):
  for j in range(1, N + 1):
    m = (i + j) % 3
    group[m].append(c[i][j])
#print(group)

#色変えるだで
#色変えたときにかかるコストを先に計算しますよーしますしますし
costs = [[0] * (C + 1) for _ in range(3)]
for i in range(3):
  for color in range(1, C + 1):
    temp = 0
    for j in range(len(group[i])):
      temp += D[group[i][j]][color]
    costs[i][color] = temp
#print(costs)
res = 10 ** 10
for per in list(敬語使うべきじゃん(list(range(1, C + 1)), 3)):
  #print(per)
  #色はグループごとにちがう
  i, j, k = per[0], per[1], per[2]
  res = min(res, costs[0][i] + costs[1][j] + costs[2][k])
print(res)
  


Fixed submission:
from itertools import permutations as 敬語使うべきじゃん
N, C = map(int, input().split())
D = [[0] * (C + 1)] + [[0] + list(map(int, input().split())) for _ in range(C)]
c = [[0] * (N + 1)] + [[0] + list(map(int, input().split())) for _ in range(N)]
#print(D, c)

group = [[] for _ in range(3)]
for i in range(1, N + 1):
  for j in range(1, N + 1):
    m = (i + j) % 3
    group[m].append(c[i][j])
#print(group)

#色変えるだで
#色変えたときにかかるコストを先に計算しますよーしますしますし
costs = [[0] * (C + 1) for _ in range(3)]
for i in range(3):
  for color in range(1, C + 1):
    temp = 0
    for j in range(len(group[i])):
      temp += D[group[i][j]][color]
    costs[i][color] = temp
#print(costs)
res = 10 ** 10
for per in list(敬語使うべきじゃん(list(range(1, C + 1)), 3)):
  #print(per)
  #色はグループごとにちがう
  i, j, k = per[0], per[1], per[2]
  res = min(res, costs[0][i] + costs[1][j] + costs[2][k])
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
#累積和＋煮豚ん
N = int(input())
A = list(map(int, input().split()))
cumsum = [0]
cumsumx = [0]
for i in range(N):
  cumsum.append(cumsum[i] + A[i])
  cumsumx.append(cumsumx[i] ^ A[i])
res = 0
"""
for i in range(1, N + 1):
  for j in range(i, N + 1):
    #print(i, j, cumsum[j - 1] - cumsum[i], cumsumx[j] ^ cumsumx[i - 1])
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      res += 1
"""   
for i in range(1, N + 1):
  l = i
  r = N
  j = (l + r) / 2

  while True:
    j = (l + r) // 2
    if r - l < 2:
      #print(i, j, l, r)
      break
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      l = j
    else:
      r = j
  #print(i, j)
  if j < N:
    if cumsum[j + 1] - cumsum[i - 1] == cumsumx[j + 1] ^ cumsumx[i - 1]:
        j += 1
  res += j - i + 1
    
print(res)
#print(cumsum)
#print(cumsumx)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
cumsum = [0]
cumsumx = [0]
for i in range(N):
  cumsum.append(cumsum[i] + A[i])
  cumsumx.append(cumsumx[i] ^ A[i])
res = 0
"""
for i in range(1, N + 1):
  for j in range(i, N + 1):
    #print(i, j, cumsum[j - 1] - cumsum[i], cumsumx[j] ^ cumsumx[i - 1])
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      res += 1
"""   
for i in range(1, N + 1):
  l = i
  r = N
  j = (l + r) / 2

  while True:
    j = (l + r) // 2
    if r - l < 2:
      #print(i, j, l, r)
      break
    if cumsum[j] - cumsum[i - 1] == cumsumx[j] ^ cumsumx[i - 1]:
      l = j
    else:
      r = j
  #print(i, j)
  if j < N:
    if cumsum[j + 1] - cumsum[i - 1] == cumsumx[j + 1] ^ cumsumx[i - 1]:
        j += 1
  res += j - i + 1
    
print(res)
#print(cumsum)
#print(cumsumx)
Buggy python submission (verdict: Time Limit Exceeded):
S = input(); K = int(input())
subs = []
for i in range(1, max(len(S), 5) + 1):
  for j in range(len(S) - i + 1):
    subs.append(S[j: j + i])
subsset = set(subs)
subs = sorted(list(subsset))
print(subs[K - 1])

Fixed submission:
S = input(); K = int(input())
subs = []
for i in range(1, min(len(S), 5) + 1):
  for j in range(len(S) - i + 1):
    subs.append(S[j: j + i])
subsset = set(subs)
subs = sorted(list(subsset))
print(subs[K - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
primes = [2]
res = []
for i in range(3, 55556):
  p = len(primes)
  f = 1
  for j in range(p):
    if i % primes[j] == 0:
      f = 0
  if f:
    primes.append(i)
for q in primes:
  if q % 5 == 1:
    res.append(q)
  if len(res) == N:
    break
print(*res)

Fixed submission:
N = int(input())
primes = [2]
res = []
for i in range(3, 55556):
  p = len(primes)
  f = 1
  for j in range(p):
    if i % primes[j] == 0:
      f = 0
  if f:
    primes.append(i)
    if i % 5 == 1:
      res.append(i)
  if len(res) == N:
    print(*res)
    break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
primes = [2]
res = []
for i in range(3, 55556):
  p = len(primes)
  f = 1
  for j in range(p):
    if i % primes[j] == 0:
      f = 0
  if f:
    primes.append(i)
for q in primes:
  if q % 5 == 1:
    res.append(q)
  if len(res) == N:
    break
print(*res)

Fixed submission:
N = int(input())
primes = [2]
res = []
for i in range(3, 55556):
  p = len(primes)
  f = 1
  for j in range(p):
    if i % primes[j] == 0:
      f = 0
  if f:
    primes.append(i)
    if i % 5 == 1:
      res.append(i)
  if len(res) == N:
    print(*res)
    break
Buggy python submission (verdict: Runtime Error):
print((input().count(o)+7)*100)

Fixed submission:
print((input().count("o")+7)*100)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
res = 0
t = 10 ** 10
for _ in range(N):
  x, y = map(int, input().split())
  if x != y: f = 0
  if x > y:
    t = min(t, y)
  res += y
if f:
  print(0)
  exit(0)

print(res - t)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
res = 0
t = float("inf")
c = 0
for _ in range(N):
  x, y = map(int, input().split())
  if x > y: t = min(y, t)
  if x == y: c += 1
  res += x
if c == N:
  print(0)
  exit(0)
print(res - t)
Buggy python submission (verdict: Runtime Error):
l, e = map(int, input().split()); res = 0
for i in range(l, r + 1):
  if str(i) == str(i)[: : -1]:
    res += 1
print(res)

Fixed submission:
l, r = map(int, input().split()); res = 0
for i in range(l, r + 1):
  if str(i) == str(i)[: : -1]:
    res += 1
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
if N < A or N < B:
  print(-1)
  exit(0)
res = [x for x in range(N - A + 1, N + 1)]
k = N - A
if k < B - 1:
  print(-1)
  exit(0)
b = [0] * (B - 1)
for i in range(k):
  b[i % (B - 1)] += 1
if max(b) > A:
  print(-1)
  exit(0)
for i in b:
  t = [x for x in range(k - i + 1, k + 1)]
  res += t
  k -= i
print(*res)

Fixed submission:
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
if N < A or N < B:
  print(-1)
  exit(0)
res = [x for x in range(N - A + 1, N + 1)]
k = N - A
if k < B - 1:
  print(-1)
  exit(0)
b = [0] * (B - 1)
for i in range(k):
  b[i % (B - 1)] += 1
if len(b):
  if max(b) > A:
    print(-1)
    exit(0)
for i in b:
  t = [x for x in range(k - i + 1, k + 1)]
  res += t
  k -= i
print(*res)
Buggy python submission (verdict: Runtime Error):
if a % 2 and (b % 2): print("Odd")
else: print("Even")

Fixed submission:
a, b = map(int, input().split())
if a % 2 and (b % 2): print("Odd")
else: print("Even")
Buggy python submission (verdict: Runtime Error):
import sys
import heapq
input = sys.stdin.readline
N = int(input())
d = list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[1])
  exit(0)
for t in range(13):
  res = True
  q = sorted(d)
  heapq.heapify(q)
  l = [0, 24]
  i = 0
  c = 0
  while len(q) and c < 2 * N ** 2:
    p = heapq.heappop(q)
    if abs(p - l[i]) < t:
      heapq.heappush(q, 24 - p)
    else:
      i += 1
      l.append(p)
      l.sort()
    c += 1
  if c >= 2 * N ** 2:
    res = False
  l.sort()
  for i in range(1, len(l)):
    if abs(l[i - 1] - l[i]) < t:
      res = False
      break
  #print(l)
  if res:
    rres = t
  else:
    break
 #print(res, t)
print(rres)

Fixed submission:
import sys
import heapq
input = sys.stdin.readline
N = int(input())
d = list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[0])
  exit(0)
for t in range(13):
  res = True
  q = sorted(d)
  heapq.heapify(q)
  l = [0, 24]
  i = 0
  c = 0
  while len(q) and c < 2 * N ** 2:
    p = heapq.heappop(q)
    if abs(p - l[i]) < t:
      heapq.heappush(q, 24 - p)
    else:
      i += 1
      l.append(p)
      l.sort()
    c += 1
  if c >= 2 * N ** 2:
    res = False
  l.sort()
  for i in range(1, len(l)):
    if abs(l[i - 1] - l[i]) < t:
      res = False
      break
  #print(l)
  if res:
    rres = t
  else:
    break
 #print(res, t)
print(rres)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
d = [0] + list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[1])
  exit(0)
for t in range(13):
  res = True
  l = sorted(d)
  nl = sorted(d)
  for _ in range(N + 1):
    l.sort()
    for i in range(N):
      if abs(l[i] - l[i + 1]) < t:
        nl.append(24 - l[i + 1])
        nl.remove(l[i + 1])
    if abs(l[0] - l[-1]) < t:
      nl.append(24 - l[-1])
      nl.remove(l[-1])
    nl.sort()
    l = nl
  for i in range(N):
    if abs(nl[i] - nl[i + 1]) < t:
      res = False
  if abs(nl[-1] - nl[0]) < t:
    res = False
  if res:
    rres = t
    #print(nl)
  else:
    break
 #print(res, t)
print(rres)

Fixed submission:
import sys
import heapq
input = sys.stdin.readline
N = int(input())
d = list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[0])
  exit(0)
for t in range(13):
  res = True
  q = sorted(d)
  heapq.heapify(q)
  l = [0, 24]
  i = 0
  c = 0
  while len(q) and c < 2 * N ** 2:
    p = heapq.heappop(q)
    if abs(p - l[i]) < t:
      heapq.heappush(q, 24 - p)
    else:
      i += 1
      l.append(p)
      l.sort()
    c += 1
  if c >= 2 * N ** 2:
    res = False
  l.sort()
  for i in range(1, len(l)):
    if abs(l[i - 1] - l[i]) < t:
      res = False
      break
  #print(l)
  if res:
    rres = t
  else:
    break
 #print(res, t)
print(rres)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.buffer.readline
N = int(input())
e = dd(list)
for i in range(1, N):
  n1 = 10 * i
  n2 = i + 1
  e[i].append((n1 % N, 0))
  e[i].append((n2 % N, 1))
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [(0, s)]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      if v in vis: continue
      vis.add(v[1])
      for p in self.e[v[1]]:
        d[p[0]] = min(d[p[0]], d[v[1]] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, (d[p[0]], p[0]))
    return d[t]
d = dijkstra(N, e)
print(d.path(1, 0) + 1)

Fixed submission:
import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.buffer.readline
N = int(input())
e = dd(list)
for i in range(1, N):
  n1 = 10 * i
  n2 = i + 1
  e[i].append((n1 % N, 0))
  e[i].append((n2 % N, 1))
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d[t]
d = dijkstra(N, e)
print(d.path(1, 0) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
ss = set(r)
r.sort()
d = [[float("inf")] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
  a, b, c = map(int, input().split())
  d[a][b] = c
  d[b][a] = c
res = float("inf")
for s in range(1, N + 1):
  dp = [[float("inf")] * (pow(2, R)) for _ in range(N + 1)]
  if s in r:
    dp[s][1 << bl(r, s)] = 0
  else: continue
  for i in range(1, N + 1):
    for j in range(pow(2, R)):
      for k in range(1, N + 1):
        x = bl(r, k)
        if j & (1 << x):
          continue
        #print(j, k, j + (1 << x))
        if k in ss:
          dp[k][j + (1 << x)] = min(dp[k][j + (1 << x)], dp[i][j] + d[i][k])
        else: dp[k][j] = min(dp[k][j], dp[i][j] + d[i][k])
  for i in range(1, N + 1):
    res = min(res, dp[i][-1])
print(res)

Fixed submission:
import sys
from itertools import permutations as per
input = sys.stdin.readline
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[float("inf")] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
  d[i][i] = 0
for _ in range(M):
  a, b, c = map(int, input().split())
  d[a][b] = c
  d[b][a] = c

for k in range(1, N + 1):
  for i in range(1, N + 1):
    for j in range(1, N + 1):
      d[i][j] = min(d[i][k] + d[k][j], d[i][j])
res = float("inf")
for p in per(r, R):
  t = 0
  for i in range(R - 1):
    t += d[p[i]][p[i + 1]]
  res = min(t, res)
print(res)

Buggy python submission (verdict: Runtime Error):
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
ss = set(r)
d = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
  a, b, c = map(int, input().split())
  d[a][b] = c
  d[b][a] = c
res = float("inf")
for s in range(1, N + 1):
  dp = [[float("inf")] * (pow(2, R)) for _ in range(N + 1)]
  if s in r:
    dp[s][1 << bl(r, s)] = 0
  else: continue
  for i in range(1, N + 1):
    for j in range(pow(2, R)):
      for k in range(1, N + 1):
        x = bl(r, k)
        if j & (1 << x):
          continue
        #print(j, k, j + (1 << x))
        if k in ss:
          dp[k][j + (1 << x)] = min(dp[k][j + (1 << x)], dp[i][j] + d[i][k])
        else: dp[k][j] = min(dp[k][j], dp[i][j] + d[i][k])
  for i in range(1, N + 1):
    res = min(res, dp[i][-1])
print(res)

Fixed submission:
import sys
from itertools import permutations as per
input = sys.stdin.readline
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[float("inf")] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
  d[i][i] = 0
for _ in range(M):
  a, b, c = map(int, input().split())
  d[a][b] = c
  d[b][a] = c

for k in range(1, N + 1):
  for i in range(1, N + 1):
    for j in range(1, N + 1):
      d[i][j] = min(d[i][k] + d[k][j], d[i][j])
res = float("inf")
for p in per(r, R):
  t = 0
  for i in range(R - 1):
    t += d[p[i]][p[i + 1]]
  res = min(t, res)
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
if N > 1:
  print(N)
  res = [N] * N
  print(*res)
elif N == 0:
  print(2)
  print(1, 1)
elif N == 1:
  print(2)
  print(2, 0)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
if 50 >= N > 1:
  print(N)
  res = [N] * N
  print(*res)
elif N > 50:
  print(50)
  res = [49] * 50
  t = N // 50
  for i in range(50):
    res[i] += t
  u = N % 50
  if u:
    for i in range(u):
      res[i] += 50 - u + 1
    for i in range(u, 50):
      res[i] -= u
  print(*res)
elif N == 0:
  print(2)
  print(1, 1)
elif N == 1:
  print(2)
  print(2, 0)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())

dp = [0] * N
dp[0] = A
dp[-1] = B
x = -1
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
for i in range(N - 2):
  if dp[i] < B:
    dp[i + 1] = dp[i] + D
  else:
    #print(dp[i], (i - 1) * (D - C), B)
    f = abs(dp[i] - (i - 1) * (D - C))
    if f <= B:
      x = i
      dp[i] = B
    else:
      x = i + -(-abs(B - f) // (D - C)) * 2
      if x >= N: no()
      dp[x] = B
    break

#print(x, dp[x])
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Fixed submission:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
for i in range(N - 1):
  r = D * (N - i - 1) + A
  l = C * (N - i - 1) + A

  r -= C * i
  l -= D * i
  #print(l, r, i)
  if B in range(l, r + 1):
    print("YES")
    exit(0)
print("NO")

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())

dp = [0] * N
dp[0] = A
dp[-1] = B
x = -1
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
for i in range(N - 2):
  if dp[i] < B:
    dp[i + 1] = dp[i] + D
  else:
    #print(dp[i], (i - 1) * (D - C), B)
    if abs(dp[i] - (i - 1) * (D - C)) <= B:
      x = i
      dp[i] = B
    else:
      x = i + -(-abs(B - dp[i]) // (D - C)) * 2
      if x >= N: no()
      dp[x] = B
    break

#print(x, dp[x])
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if -(-C // (D - C)) > t: no()
print("YES")


Fixed submission:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
for i in range(N - 1):
  r = D * (N - i - 1) + A
  l = C * (N - i - 1) + A

  r -= C * i
  l -= D * i
  #print(l, r, i)
  if B in range(l, r + 1):
    print("YES")
    exit(0)
print("NO")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
H, W, h, w = map(int, input().split())
unit = 10 ** 9 - 1
c = H * W
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): c -= 1
res = [[unit // c] * W for _ in range(H)]
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): res[i][j] = -(unit // c * (h * w - 1) + 1)
if sum([sum(r) for r in res]) > 0:
  print("Yes")
  for r in res: print(*r)
else: print("No")

Fixed submission:
import sys
input = sys.stdin.readline
H, W, h, w = map(int, input().split())
unit = 10 ** 9 - 1
c = H * W
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): c -= 1
if c == 0:
  print("No")
  exit(0)
res = [[unit // c] * W for _ in range(H)]
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): res[i][j] = -(unit // c * (h * w - 1) + 1)
if sum([sum(r) for r in res]) > 0:
  print("Yes")
  for r in res: print(*r)
else: print("No")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
A, B = map(int, input().split())
if A < B: print("LESS")
elif A == B: print("EQUAL")
else: print("GREATER")


Fixed submission:
import sys
input = sys.stdin.readline
A = int(input())
B = int(input())
if A < B: print("LESS")
elif A == B: print("EQUAL")
else: print("GREATER")

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A < B: print("LESS")
elif A == B: print("EQUAL")
else: print("GREATER")

Fixed submission:
import sys
input = sys.stdin.readline
A = int(input())
B = int(input())
if A < B: print("LESS")
elif A == B: print("EQUAL")
else: print("GREATER")
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
e = dd(list)
inc = [0] * (N + 1)
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  inc[u] += 1
  inc[v] += 1
s = 0
inc[0] = float("inf")
for i in range(N):
  if inc[i] < inc[s]:
    s = i
vis = set()
vis.add(s)
res = []
def dfs(x):
  global vis
  global res
  vis.add(x)
  res.append(x)
  c = 0
  for y in e[x]:
    if y in vis: continue
    c += 1
    dfs(y)
  if c == 0:
    for y in e[s]:
      if not (y in vis):
        c += 1
    if c == 0:
      print(len(res))
      print(*res)
      exit(0)
  res.pop()
  vis.discard(x)

dfs(s)

Fixed submission:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, M = map(int, input().split())
e = dd(list)
inc = [0] * (N + 1)
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  inc[u] += 1
  inc[v] += 1
s = 0
inc[0] = float("inf")
for i in range(N):
  if inc[i] < inc[s]:
    s = i
vis = set()
vis.add(s)
res = []
def dfs(x):
  global vis
  global res
  vis.add(x)
  res.append(x)
  c = 0
  for y in e[x]:
    if y in vis: continue
    c += 1
    dfs(y)
  if c == 0:
    for y in e[s]:
      if not (y in vis):
        c += 1
    if c == 0:
      print(len(res))
      print(*res)
      exit(0)
  res.pop()
  vis.discard(x)

dfs(s)