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

Fixed submission:
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)
for _ in range(M):
  p = heapq.heappop(A)
  p = -p
  p //= 2
  p = -p
  heapq.heappush(A, p)
print(-sum(A))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
class SkewHeap:
  def __init__(self, init_val = None, left = None, right = None):
    self.val = init_val
    self.left = left
    self.right = right
    self.root = None
  def heapmeld(self, h1, h2):
    if h1 == None: return h2
    if h2 == None: return h1
    if h1.val > h2.val:
      h1.val, h1.left, h1.right, h2.val, h2.left, h2.right = h2.val, h2.left, h2.right, h1.val, h1.left, h1.right
    h1.right = self.heapmeld(h2, h1.right)
    return h1
  def heappop(self):
    if self.root == None:
      res = self.val
      h = self.heapmeld(self.left, self.right)
      if h == None: h = SkewHeap(None)
      self.val, self.left, self.right = h.val, h.left, h.right
      return res
    res = self.root.val
    self.root = self.heapmeld(self.root.left, self.root.right)
    return res
  def heappush(self, x):
    h = SkewHeap(x)
    self.root = self.heapmeld(self.root, h)
N, M = map(int, input().split())
a = list(map(int, input().split()))
h = SkewHeap()
res = 0
for e in a:
  h.heappush(-e)
for _ in range(M):
  h.heappush(-(-h.heappop() // 2))
for _ in range(N):
  res -= h.heappop()
print(res)
Problem p02989 (python)

Fixed submission:
n=int(input());d=sorted(list(map(int,input().split())));print(d[n//2]-d[n//2-1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
from collections import deque
from copy import deepcopy as dc
N, M = map(int, input().split())
e = dd(list)
inf = 10 ** 9
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
S, T = map(int, input().split())

stopped = [inf] * (N + 1)
Q = deque()
Q.append(S)
stopped[S] = 0
saw2 = {i: 0 for i in range(1, N + 1)}
saw3 = {i: 0 for i in range(1, N + 1)}
while len(Q) != 0:
  s2 = dc(saw2)
  s3 = dc(saw3)
  p = Q.popleft()
  if stopped[p] >= stopped[T]:
    break
  for q in e[p]:
    for r in e[q]:
      if s2[r] == 1:
        continue
      else:
        s2[r] = 1
      for s in e[r]:
        if s3[s] == 1:
          continue
        else:
          s3[s] = 1
        if stopped[s] > stopped[p] + 1:
          Q.append(s)
          stopped[s] = stopped[p] + 1
if stopped[T] == inf:
  print(-1)
else:
  print(stopped[T])
Problem p03003 (python)

Fixed submission:
import numpy as np
N, M = map(int, input().split())
S = input().split()
T = np.array(input().split(), dtype = np.int32)
mod = 10 ** 9 + 7
dp = np.ones(M + 1, dtype = np.int64)
 
for s in S:
  dp[1:] = ((dp[:-1] * (T == int(s))).cumsum() + dp[1:]) % mod

print(dp[M])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10 ** 9 + 7

res = [[-1 for _ in range(M)] for _ in range(N)]
dpl = [[-1 for _ in range(M)] for _ in range(N)]
def dp(i, j):
  if i < 0:
    return 0
  if j < 0:
    return 0
  if dpl[i][j] != -1:
    return dpl[i][j]
  if i == 1:
    temp = 0
    for k in range(j):
      temp += S[i] == T[k]
    return temp
  elif j == 1:
    temp = 0
    for k in range(j):
      temp += S[k] == T[j]
    return temp
  temp = 0
  for k in range(i):
    for l in range(j):
      temp += dpl[k][l]
      
  return temp

def search(i, j):
  if i < 0:
    return 0
  if j < 0:
    return 0
  if res[i][j] != -1:
    return res[i][j]
  temp = 0
  if S[i] == T[j]:
    temp = 1
    temp += dp[i][j]
  else:
    temp = 0
  return search(i - 1, j) + search(i, j - 1) - search(i - 1, j - 1) + temp

print(search(N - 1, M - 1) % mod)

Buggy submission (verdict: Runtime Error):
inputa = list(map(int, input().split()))
inputb = list(map(int, input().split()))
inputc = list(map(int, input().split()))

seta = set(inputb) & set(inputc)

countb = []
countc = []
result = 0
for i in seta:
  countb.append(inputb.count(i))
  countc.append(inputc.count(i))
for i in range(len(countb)):
  for j in range(i)
  result += countb[i] * countc[j]

print(result)
Problem p03017 (python)

Fixed submission:
inputa = list(map(int, input().split()))
inputb = list(input())
#double mountain
mountain = 0
for i in range(min(inputa[1], inputa[2]) - 1, max(inputa[3], inputa[4])):
  if inputb[i] == "#":
    if mountain == 1:
      mountain = 2
      break
    mountain = 1
  else:
    mountain = 0

if mountain == 2:
  print("No")
  exit()
    
#need oikoshi
oikoshi = 0
if inputa[3] > inputa[4]:
  oikoshi = 1

#triple step
triplestep = 0
for i in range(inputa[2] - 1, inputa[4]):
  if oikoshi == 0:
    break
  if inputb[i - 1] == ".":
    if inputb[i] == ".":
      if inputb[i + 1] == ".":
        triplestep = 1
        break

if oikoshi == 0:
  print("Yes")
else:
  if triplestep == 1:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
dp = [0] * (N + 1)
dp[B] = 1
for i in range(B, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
if dp[D] == 0:
  print("No")
  exit(0)
S[D] = "#"
dp = [0] * (N + 1)
dp[A] = 1
for i in range(A, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
#print(dp)
if dp[C]:
  print("Yes")
else: print("No")
Problem p03045 (python)

Fixed submission:
N, M = map(int, input().split())
XY = [i for i in range(N + 1)]

def root(x):
  temp = x
  while temp != XY[temp]:
    temp = XY[temp]
  XY[x] = temp
  return temp
for _ in range(M):
  x, y = map(int, input().split()[:2])
  XY[root(x)] = root(y)

print(sum(i == v for i, v in enumerate(XY)) - 1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as ddydd
from collections import deque as q
N, M = map(int, input().split())
XYZ = ddydd(list)
TreeMemo = ddydd(int)
link = []
trace = [0] * (N + 1)
start = 0
for _ in range(M):
  x, y, z = map(int, input().split())
  if start == 0:
    start = x
  XYZ[x].append(y)
  XYZ[y].append(x)
  TreeMemo[x] = 0
  TreeMemo[y] = 0
  if not x in link: link.append(x)
  if not y in link: link.append(y)

def searchPreMin(n):
  global trace
  trace.append(n)
  temp = min(XYZ[n])
  if temp < n:
    return searchPreMin(temp)
  else:
    return n
def searchPreMax(n):
  global trace
  trace.append(n)
  temp = max(XYZ[n])
  if temp > n:
    return searchPreMax(temp)
  else:
    return n
def searchMax(n):
  global trace
  if trace[n] != 0:
    return TreeMemo[n]
  trace = []
  n = searchPreMin(n)
  temp = searchPreMax(n)
  for t in trace:
    TreeMemo[t] = temp
  return temp

forest = []
nodes = len(link)
while link:
  temp = link.pop()
  tree = searchMax(temp)
  if not tree in forest: forest.append(tree)
    
print(N - nodes + len(forest))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as ddydd
from collections import deque as q
N, M = map(int, input().split())
XYZ = ddydd(list)
TreeMemo = ddydd(int)
link = []
trace = []
start = 0
for _ in range(M):
  x, y, z = map(int, input().split())
  if start == 0:
    start = x
  XYZ[x].append(y)
  XYZ[y].append(x)
  TreeMemo[x] = 0
  TreeMemo[y] = 0
  if not x in link: link.append(x)
  if not y in link: link.append(y)

def searchPreMin(n):
  global trace
  trace.append(n)
  temp = min(XYZ[n])
  if temp < n:
    return searchPreMin(temp)
  else:
    return n
def searchPreMax(n):
  global trace
  trace.append(n)
  temp = max(XYZ[n])
  if temp > n:
    return searchPreMax(temp)
  else:
    return n
def searchMax(n):
  global trace
  if trace[n] != 0:
    return TreeMemo[t]
  trace = []
  n = searchPreMin(n)
  temp = searchPreMax(n)
  for t in trace:
    TreeMemo[t] = temp
  return temp

forest = []
nodes = len(link)
while link:
  temp = link.pop()
  tree = searchMax(temp)
  if not tree in forest: forest.append(tree)
    
print(N - nodes + len(forest))
Problem p03055 (python)

Fixed submission:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
if N == 1:
  print("First")
  exit(0)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append((v, 1))
  e[v].append((u, 1))
import heapq
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
dij = dijkstra(N, e)
s = 0
d = 0
p = dij.path(1, 0)
for i in range(1, N + 1):
  if p[i] > d:
    s = i
    d = p[i]
p = dij.path(s, 0)
mx = max(p[1: ])
if mx % 3 == 1: print("Second")
else: print("First")

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append((v, 1))
  e[v].append((u, 1))
import heapq
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
dij = dijkstra(N, e)
s = 0
d = 0
p = dij.path(1, 0)
for i in range(1, N + 1):
  if p[i] > d:
    s = i
    d = p[i]
p = dij.path(s, 0)
mx = max(p[1: ])
dp = [-1] * (mx + 1)
dp[0] = 1
for i in range(mx):
  if i + 1 <= mx:
    if dp[i + 1] == -1 or (dp[i + 1] == ((dp[i] + 1) % 2)):
      dp[i + 1] = (dp[i] + 1) % 2
  if i + 2 <= mx:
    if dp[i + 2] == -1 or (dp[i + 2] == ((dp[i] + 1) % 2)):
      dp[i + 2] = (dp[i] + 1) % 2
if dp[-1]: print("Second")
else: print("First")
Problem p03108 (python)

Fixed submission:
N, Q = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(Q)]
res = [0] * (Q - 1) + [N * (N - 1) // 2]
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rnk = [0] * (n + 1)

  def Find_Root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if x == y:
      return 
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1

  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  def Count(self, x):
    return -self.root[self.Find_Root(x)]

uf = UnionFind(N)
convenience = [0] * (N + 1)
for i in range(Q - 1, 0, -1):
  res[i - 1] = res[i]
  if uf.Find_Root(A[i][0]) != uf.Find_Root(A[i][1]):
    res[i - 1] -= uf.Count(A[i][0]) * uf.Count(A[i][1])
    a, b = uf.Count(A[i][0]), uf.Count(A[i][1])
    uf.Unite(A[i][0], A[i][1])
  #print(uf.root, res, a, b)
for i in range(Q):
  print(res[i])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(Q)][: : -1]
res = [N * (N - 1) // 2]
mod = 2305843009213693951
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rnk = [0] * (n + 1)

  def Find_Root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if x == y:
      return 
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1

  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  def Count(self, x):
    return -self.root[self.Find_Root(x)]

class Factorial:
  def __init__(self, n, mod):
    self.f=[1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i=[pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod

uf = UnionFind(N)
f = Factorial(N * (N - 1) // 2, 2305843009213693951)
for b in A:
  uf.Unite(b[0], b[1])
  convenience = 0
  for inc in uf.root:
    if inc < -1:
      convenience += f.combi(-inc, 2)
  res.append(N * (N - 1) // 2 - convenience)
for i in range(Q - 1, -1, -1):
  print(res[i])
Problem p03137 (python)

Fixed submission:
#xi以外の場所にコマを置く理由がない
#コマを置くというのは担当区間の分割
#xi x(i + 1)の間隔を無視するということ
#距離がでかいところから分割してやれば良い
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
l = [X[i + 1] - X[i] for i in range(M - 1)]
l.sort()
for _ in range(N - 1):
  if len(l):
    l.pop()
print(sum(l))

Buggy submission (verdict: Runtime Error):
#xi以外の場所にコマを置く理由がない
#コマを置くというのは担当区間の分割
#xi x(i + 1)の間隔を無視するということ
#距離がでかいところから分割してやれば良い
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
l = [X[i + 1] - X[i] for i in range(M - 1)]
l.sort()
for _ in range(N - 1):
  l.pop()
print(sum(l))
Problem p03242 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = list(input())[: -1]
for i in range(len(n)):
  if n[i] == "1":
    n[i] = "9"
  elif n[i] == "9":
    n[i] = "1"
print("".join(n))

Buggy submission (verdict: Runtime Error):
N = input()
for i in range(len(N)):
  if N[i] == "1":
    N[i] = "9"
  else:
    N[i] = "1"
print(N)
Problem p03707 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())
S = [list(map(int, list(input())[: -1])) for _ in range(N)]
e = [[0] * M for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M - 1): e[i][j + 1] = e[i][j] + ((S[i - 1][j] == 1) and (S[i - 1][j + 1] == 1))
for i in range(1, N):
  for j in range(M): e[i + 1][j] += e[i][j]

cs = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M): cs[i][j + 1] = cs[i][j] + (S[i - 1][j] == 1)
for i in range(1, N):
  for j in range(M + 1): cs[i + 1][j] += cs[i][j]

T = [[0] * N for _ in range(M)]
for i in range(N):
  for j in range(M): T[j][i] = S[i][j]

N, M = M, N
ee = [[0] * M for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M - 1): ee[i][j + 1] = ee[i][j] + ((T[i - 1][j] == 1) and (T[i - 1][j + 1] == 1))
for i in range(1, N):
  for j in range(M): ee[i + 1][j] += ee[i][j]


#print(cs)

for i in range(Q):
  u, l, d, r = map(lambda x: int(x) - 1, input().split())
  rese = e[d + 1][r] - e[d + 1][l] - e[u][r] + e[u][l]
  resee = ee[r + 1][d] - ee[r + 1][u] - ee[l][d] + ee[l][u]
  res = cs[d + 1][r + 1] - cs[d + 1][l] - cs[u][r + 1] + cs[u][l]
  print(res - rese - resee)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())
S = [list(map(int, list(input())[: -1])) for _ in range(N)]
e = [[0] * M for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M - 1): e[i][j + 1] = e[i][j] + ((S[i - 1][j] == 1) and (S[i - 1][j + 1] == 1))
for i in range(1, N):
  for j in range(M): e[i + 1][j] += e[i][j]

T = [[0] * N for _ in range(M)]
for i in range(N):
  for j in range(M): T[j][i] = S[i][j]
N, M = M, N
ee = [[0] * M for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M - 1): ee[i][j + 1] = ee[i][j] + ((T[i - 1][j] == 1) and (T[i - 1][j + 1] == 1))
for i in range(1, N):
  for j in range(M): ee[i + 1][j] += ee[i][j]

cs = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
  for j in range(M): cs[i][j + 1] = cs[i][j] + (S[i - 1][j] == 1)
for i in range(1, N):
  for j in range(M + 1): cs[i + 1][j] += cs[i][j]

#print(cs)

for i in range(Q):
  u, l, d, r = map(lambda x: int(x) - 1, input().split())
  rese = e[d + 1][r] - e[d + 1][l] - e[u][r] + e[u][l]
  resee = ee[r + 1][d] - ee[r + 1][u] - ee[l][d] + ee[l][u]
  res = cs[d + 1][r + 1] - cs[d + 1][l] - cs[u][r + 1] + cs[u][l]
  print(res - rese - resee)
Problem p03768 (python)

Fixed submission:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
e = dd(list)

for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
mxd = 0
res = [[-1] * 11 for _ in range(N + 1)]
Q = int(input())
qd = [0] * Q
qc = [0] * Q
for i in range(Q):
  v, d, c = map(int, input().split())
  qd[i] = d
  qc[i] = c
  res[v][d] = i
  mxd = max(mxd, d)
#print(qc)

#print(mxd)
for t in range(mxd):
  tres = [x[: ] for x in res]
  for x in range(1, N + 1):
    for y in e[x]:
      for i in range(t + 1, 11):
        res[y][i] = max(res[y][i], tres[x][i])

#print(res)
for r in res[1: ]:
  x = -1
  for i in range(11):
    if r[i] != -1: x = max(x, r[i])
  if x == -1: print(0)
  else: print(qc[x])

Buggy 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)

for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

base = 10 ** 6
def clean():
  global res
  for i in range(1, N + 1):
    if len(res[i]) == 0: continue
    p = max(res[i])
    z = p % base
    d = p // base
    newrs = set()
    newrs.add(p)
    for x in res[i]:
      if qd[x % base] > d: newrs.add(x)
    res[i] = newrs

res = [set() for _ in range(N + 1)]
Q = int(input())
qd = [0] * Q
qc = [0] * Q
for i in range(Q):
  v, d, c = map(int, input().split())
  qd[i] = d
  qc[i] = c
  res[v].add(d * base + i)
#print(qc)
clean()
for t in range(10):
  tres = [set() | s for s in res]
  for x in range(1, N + 1):
    for y in e[x]:
      for z in res[x]:
        if qd[z % base] > t: tres[y].add(z)
  res = tres
  clean()
#print(res)

for r in res[1: ]:
  if len(r): print(qc[max(r)])
  else: print(0)

Buggy 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)

for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

res = [set() for _ in range(N + 1)]
Q = int(input())
qd = [0] * Q
qc = [0] * Q
for i in range(Q):
  v, d, c = map(int, input().split())
  qd[i] = d
  qc[i] = c
  res[v].add(i)
#print(qd)

def clean():
  global res
  for i in range(1, N + 1):
    a = sorted(res[i], reverse = True)
    d = -1
    for j in range(len(a)):
      x = a[j]
      if qd[x] <= d: res[i].discard(y)
      d = max(d, qd[x])
clean()
for t in range(10):
  tres = [set() | s for s in res]
  for x in range(1, N + 1):
    for y in e[x]:
      for z in res[x]:
        if qd[z] > t: tres[y].add(z)
  res = tres
  clean()
#print(res)

for r in res[1: ]:
  if len(r): print(qc[max(r)])
  else: print(0)
Problem p02915 (python)

Fixed submission:
print(int(input())**3)

Buggy submission (verdict: Runtime Error):
print(input()**3)
Problem p02550 (python)

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

yj=[x]
lps=0
for i in range(n):
  an=(yj[i]**2)%m
  if an in yj:
    lps=yj.index(an)
    break
  yj.append(an)

blp=yj[:lps]
lp=yj[lps:]
ans=sum(blp)+sum(lp)*((n-len(blp))//len(lp))+sum(lp[:(n-len(blp))%len(lp)])
print(ans)

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

yj=[x]

for i in range(n):
  an=(yj[i]**2)%m
  if an in yj:
    lps=yj.index(an)
    break
  yj.append(an)
  
blp=yj[:lps]
lp=yj[lps:]
ans=sum(blp)+sum(lp)*((n-len(blp))//len(lp))+sum(lp[:(n-len(blp))%len(lp)])
print(ans)
Problem p02580 (python)

Fixed submission:
#import random

def putmx(lis,mx):
  ret=[]
  for (i,j) in zip(range(len(lis)),lis):
    if j==mx:
      ret.append(i)
  return ret
  

h,w,m=map(int,input().split())
hb=[0]*h
wb=[0]*w
bmb=[]
for i in range(h):
  bmb.append({-1})
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].add(ww)
  hb[hh]+=1
  wb[ww]+=1
mhb=max(hb)
mwb=max(wb)
hmx=putmx(hb,mhb)
wmx=set(putmx(wb,mwb))

#print(hb,wb,hmx,wmx)
fl=False
for i in hmx:
  if wmx|bmb[i]!=bmb[i]:
    print(mhb+mwb)
    break
else:
  print(mhb+mwb-1)

#print(hmx,wmx,bmb)

Buggy submission (verdict: Runtime Error):
#import random

def putmx(lis):
  ret=[]
  mx=max(lis)
  for i in range(len(lis)):
    if mx==lis[i]:
      ret.append(i)
  return ret
  

h,w,m=map(int,input().split())
#inp=[(random.randrange(1,h+1),random.randrange(1,w+1)) for i in range(m)]
hb=[0]*h
wb=[0]*w
bmb=[]
for i in range(h):
  bmb.append({-1})
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].add(ww)
  hb[hh]+=1
  wb[ww]+=1

#hmx=[i for i, x in enumerate(hb) if x == max(hb)]
#wmx=[i for i, x in enumerate(wb) if x == max(wb)]
hmx=putmx(hb)
wmx=putmx(wb)
mhb=max(hb)
mwb=max(wb)
#print(hb,wb,hmx,wmx)
if len(hmx)>len(wmx):
  ll=set(wmx)
  bl=hmx
else:
  ll=set(hmx)
  bl=wmx
fl=False
for i in bl:
  if len(bmb[i]&ll)>0:
      print(mhb+mwb-1)
      fl=True
      break
  if fl:
    break
else:
  print(mhb+mwb)

Buggy submission (verdict: Runtime Error):
def putmx(lis):
  ret=[]
  mx=max(lis)
  for i in range(len(lis)):
    if mx==lis[i]:
      ret.append(i)
  return ret

h,w,m=map(int,input().split())

hb=[0]*h
wb=[0]*w
mp=[]
for i in range(h):
  mp.append([0]*w)
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  hb[hh]+=1
  wb[ww]+=1
  mp[hh][ww]=1

hmx=putmx(hb)
wmx=putmx(wb)
mhb=max(hb)
mwb=max(wb)

fl=False
for i in hmx:
  for j in wmx:
    if mp[i][j]!=1:
      print(mhb+mwb)
      fl=True
      break
  if fl:
    break
else:
  print(mhb+mwb-1)

Buggy submission (verdict: Runtime Error):
import numpy as np
h,w,m=map(int,input().split())

hb=[0]*h
wb=[0]*w
mp=np.zeros((h,w))
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  hb[hh]+=1
  wb[ww]+=1
  mp[hh][ww]=1

hmx=[i for i, x in enumerate(hb) if x == max(hb)]
wmx=[i for i, x in enumerate(wb) if x == max(wb)]
mhb=max(hb)
mwb=max(wb)
fl=False
for i in hmx:
  for j in wmx:
    if mp[i][j]!=1:
      print(mhb+mwb)
      fl=True
      break
  if fl:
    break
else:
  print(mhb+mwb-1)
Problem p02594 (python)

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

Buggy submission (verdict: Runtime Error):
#a,b=map(int,input().split())
#lis=list(map(int,input().split()))
#n=int(input())
#s=input()
def yana(int(input())>=30):
  if boo:
    print("Yes")
  else:
    print("No")
Problem p02598 (python)

Fixed submission:
import math as mt
n,k=map(int,input().split())
a=list(map(int,input().split()))
bot=0
top=max(a)


while 1:
  cen=(top+bot)//2
  x=0
  if cen==0:
    print(1)
    break
  for i in a:
    x+=mt.ceil(i/cen)-1
  #print(x,top,cen,bot)
  if x>k:
    bot=cen+1
  else:
    top=cen
  
  if top<=bot:
    print(top)
    break
  if bot==cen:
    print(cen+1)
    break

Buggy submission (verdict: Runtime Error):
import math as mt
n,k=map(int,input().split())
a=list(map(int,input().split()))
bot=0
top=max(a)


while 1:
  cen=(top+bot)//2
  x=0
  if cen==0:
    print(1)
  for i in a:
    x+=mt.ceil(i/cen)-1
  #print(x,top,cen,bot)
  if x>k:
    bot=cen+1
  else:
    top=cen
  
  if top<=bot:
    print(top)
    break
  if bot==cen:
    print(cen+1)
    break

Buggy submission (verdict: Runtime Error):
import math as mt
n,k=map(int,input().split())
a=list(map(int,input().split()))
bot=0
top=max(a)


while 1:
  cen=(top+bot)//2
  x=0
  for i in a:
    x+=mt.ceil(i/cen)-1
  #print(x,top,cen,bot)
  if x>k:
    bot=cen+1
  else:
    top=cen
  
  if top<=bot:
    print(top)
    break
  if bot==cen:
    print(cen+1)
    break