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

Fixed submission:
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
zeta = [0] * (max(A) + 1)
mod = 998244353
res = 0
for a in A:
  zeta[a] += a
for i in range(1, len(zeta)):
  for j in range(2 * i, len(zeta), i):
    zeta[i] += zeta[j]
for i in range(1, len(zeta)):
  zeta[i] *= zeta[i]
for i in range(len(zeta) - 1, 0, -1):
  for j in range(2 * i, len(zeta), i):
    zeta[i] -= zeta[j]
for a in A:
  zeta[a] -= a ** 2
for i in range(1, len(zeta)):
  zeta[i] //= 2
for i in range(1, len(zeta)):
  zeta[i] //= i
  res = (res + zeta[i]) % mod
print(res)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
zeta = [0] * (max(A) + 1)
mod = 998244353
for a in A:
  zeta[a] += a
for i in range(1, len(zeta)):
  for j in range(2 * i, len(zeta), i):
    zeta[i] += zeta[j]
for i in range(1, len(zeta)):
  zeta[i] *= zeta[i]
for i in range(len(zeta) - 1, 0, -1):
  for j in range(2 * i, len(zeta), i):
    zeta[i] -= zeta[j]
for a in A:
  zeta[a] -= a ** 2
for i in range(1, len(zeta)):
  zeta[i] //= 2
for i in range(1, len(zeta)):
  zeta[i] //= i
  res = (res + zeta[i]) % mod
print(res)
Problem p02918 (python)

Fixed submission:
N, M = map(int, input().split())
S = list(input())
temp = S[0]
ind = 0
cs = [1]
for i in range(N - 1):
  if S[i] == S[i + 1]:
    cs[ind] += 1
  else:
    cs.append(1)
    ind += 1
    temp = S[i + 1]
#print(cs)
cscs = [cs[0]] + [0] * (len(cs))
for i in range(len(cs) - 1):
  cscs[i + 1] = cscs[i] + cs[i + 1]
cscs = [0] + cscs
css = [cs[0]] + [0] * (len(cs))
for i in range(len(cs) - 1):
  css[i + 1] = css[i] + cs[i + 1] - 1
css = [0] + css
#print(css)
#print(cscs)
res = 0
for i in range(len(css) - 2 * M):
  temp = css[-2] - css[i + 2 * M] + css[max(i, 0)]
  #print(temp,css[-2],css[i + 2 * M],css[max(i - 1, 0)])
  res = max(res, cscs[i + 2 * M] - cscs[i] + temp)
  #print(res - 1, i, i + 2 * M)
if len(css) - 2 <= 2 * M + 1:
  print(N - 1)
else:
  print(res - 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = list(input())
temp = S[0]
ind = 0
cs = [1]
for i in range(N - 1):
  if S[i] == S[i + 1]:
    cs[ind] += 1
  else:
    cs.append(1)
    ind += 1
    temp = S[i + 1]
#print(cs)
cscs = [cs[0]] + [0] * (len(cs))
for i in range(len(cs) - 1):
  cscs[i + 1] = cscs[i] + cs[i + 1]
cscs = [0] + cscs
css = [cs[0]] + [0] * (len(cs))
for i in range(len(cs) - 1):
  css[i + 1] = css[i] + cs[i + 1] - 1
css = [0] + css
#print(css)
#print(cscs)
res = 0
for i in range(max(len(cs) - 2 * M + 1, 1)):
  temp = css[-2] - css[i + 2 * M] + css[max(i - 1, 0)]
  #print(temp,css[-2],css[i + 2 * M],css[max(i - 1, 0)])
  res = max(res, cscs[i + 2 * M] - cscs[i] + temp)
  #print(res - 1, i, i + 2 * M)
if len(css) - 2 <= 2 * M + 1:
  print(N - 1)
else:
  print(res - 1)
Problem p02936 (python)

Fixed submission:
from collections import defaultdict as dd
from collections import deque as dq
N, Q = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  
res = [0] * (N + 1)
for _ in range(Q):
  p, x = map(int, input().split())
  res[p] += x
visited = [0] * (N + 1)
Q = dq([])
Q.append(1)
visited[1] = 1
while len(Q) != 0:
  n = Q.pop()
  visited[n] = 1
  for o in e[n]:
    if visited[o] == 0:
      res[o] += res[n]
      Q.append(o)
#def dfs(n):
#  global visited
#  global res
#  visited[n] = 1
#  for o in e[n]:
#    if visited[o] == 0:
#      res[o] += res[n]
#      dfs(o)
#dfs(1)
sen = ""
for i in range(1, N + 1):
  sen += str(res[i])
  if i != N:
    sen += " "
print(sen)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
N, Q = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  
res = [0] * (N + 1)
for _ in range(Q):
  p, x = map(int, input().split())
  res[p] += x
visited = [0] * (N + 1)
def dfs(n):
  global visited
  global res
  visited[n] = 1
  for o in e[n]:
    if visited[o] == 0:
      res[o] += res[n]
      dfs(o)
dfs(1)
sen = ""
for i in range(1, N + 1):
  sen += str(res[i])
  if i != N:
    sen += " "
print(sen)
Problem p02937 (python)

Fixed submission:
from collections import defaultdict as dd
from bisect import bisect_left as bl
s = input()
t = input()
ind = dd(list)
res = 0
first = 1
for i in range(len(s)):
  ind[s[i]].append(i)
#print(ind)
for i in range(len(t)):
  if len(ind[t[i]]) == 0:
    print(-1)
    exit(0)
  temp = bl(ind[t[i]], res % len(s))
  #print(temp, res, t[i])
  if first == 0:
    if res % len(s) == ind[t[i]][min(temp, len(ind[t[i]]) - 1)]:
      temp += 1
  first = 0
  if temp == len(ind[t[i]]):
    res += (len(s) - res % len(s)) + ind[t[i]][0]
  else:
    res += ind[t[i]][temp] - res % len(s)
print(res + 1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
from bisect import bisect_left as bl
s = input()
t = input()
ind = dd(list)
res = 0
for i in range(len(s)):
  ind[s[i]].append(i)
#print(ind)
for i in range(len(t)):
  if len(ind[t[i]]) == 0:
    print(-1)
    exit(0)
  temp = bl(ind[t[i]], res % len(s))
  #print(temp, res, t[i])
  if res % len(s) == ind[t[i]][temp]:
    temp += 1
  if temp == len(ind[t[i]]):
    res += (len(s) - res % len(s)) + ind[t[i]][0]
  else:
    res += ind[t[i]][temp] - res % len(s)
print(res + 1)
Problem p02941 (python)

Fixed submission:
import sys
from heapq import heappush as hpu
from heapq import heappop as hpo
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

base = 10 ** 6
sb = [-(b[i] * base + i) for i in range(N) if a[i] != b[i]]
h = []
for t in sb: hpu(h, t)
res = 0
while len(h):
  v = hpo(h)
  i = -v % base
  v = -v // base
  if v < a[i]:
    print(-1)
    exit(0)
  d = v - a[i]
  x = b[i - 1] + b[(i + 1) % N]
  t = d // x
  if t == 0:
    if v == a[i]: continue
    print(-1)
    exit(0)
  b[i] -= x * (t)
  res += t
  hpu(h, -(b[i] * base + i))
print(res)

Buggy submission (verdict: Runtime Error):
import sys
from heapq import heappush as hpu
from heapq import heappop as hpo
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

base = 10 ** 10
sb = [(-b[i], i) for i in range(N) if a[i] != b[i]]
h = []
push = lambda x,i: hpu(h, (-x,i))
for t in sb: push(t)
res = 0
while len(h):
  v, i = hpo(h)
  v = -v
  if v < a[i]:
    print(-1)
    exit(0)
  d = v - a[i]
  x = b[i - 1] + b[(i + 1) % N]
  t = d // x
  if t == 0:
    if v == a[i]: continue
    print(-1)
    exit(0)
  b[i] -= x * (t)
  res += t
  push((-b[i], i))
print(res)

Buggy submission (verdict: Runtime Error):
import sys
from heapq import heappush as hpu
from heapq import heappop as hpo
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

base = 10 ** 10
sb = [(-b[i], i) for i in range(N) if a[i] != b[i]]
h = []
hpu = lambda x: hpu(h, x)
for t in sb: hpu(t)
res = 0
while len(h):
  v, i = hpo(h)
  v = -v
  if v < a[i]:
    print(-1)
    exit(0)
  d = v - a[i]
  x = b[i - 1] + b[(i + 1) % N]
  t = d // x
  if t == 0:
    if v == a[i]: continue
    print(-1)
    exit(0)
  b[i] -= x * (t)
  res += t
  hpu((-b[i], i))
print(res)
Problem p02949 (python)

Fixed submission:
import collections
import sys
import time
sys.setrecursionlimit(10 ** 5)
N, M, P = map(int, input().split())
e = collections.defaultdict(list)
st = time.time()
for _ in range(M):
  u, v, c = map(int, input().split())
  e[u].append((v, c))
def isConnected(n):
  if n == N:
    return True
  vis = [0] * (N + 1)
  que = collections.deque([])
  que.append(n)
  while que:
    nc = que.popleft()
    vis[nc] = 1
    for o in e[nc]:
      if o[0] == N:
        return True
      if vis[o[0]] == 0:
        que.append(o[0])
  return False
inf = 10 ** 10
visited = [0] * (N + 1)
earn = [-inf] * (N + 1)
earn[1] = 0
def dfs(now):
  global visited
  global earn
  nt = time.time() - st
  if nt > 1.95:
    print(max(earn[N], 0))
    exit(0)
  visited[now] = 1
  for n in e[now]:
    if visited[n[0]] == 0:
      if n[1] + earn[now] - P > earn[n[0]]:
        earn[n[0]] = n[1] + earn[now] - P
        dfs(n[0])
        visited[n[0]] = 0
    else:
      if earn[n[0]] < n[1] + earn[now] - P:
        if isConnected(n[0]) == True:
          print(-1)
          exit(0)
dfs(1)
print(max(earn[N], 0))

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M, P = map(int, input().split())
e = dd(list)
for _ in range(M):
  a, b, c = map(int, input().split())
  e[a].append((b, -c + P))
class BellmanFord:
  def __init__(self, n, e):
    self.n = n
    self.edges = []
    self.b = pow(10, 10)
    for k in e.keys():
      for t in e[k]:
        self.edges.append(k * pow(b, 2) + t[0] * b + t[1])
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    d[s] = 0
    b = self.b
    for i in range(self.n + 1):
      for x in self.edges:
        u = x // pow(b, 2)
        v = x // b - u * b
        c = x % b
        if d[u] != float("inf") and (d[u] + c < d[v]):
          d[v] = d[u] + c
    return d[t]
  def path_findloop(self, s, t):
    d = [float("inf")] * (self.n + 1)
    d[s] = 0
    first = 0
    b = self.b
    for i in range(1, self.n * 2 + 1):
      for x in self.edges:
        u = x // pow(b, 2)
        v = x // b - u * b
        c = x % b
        print(u, v, c)
        if u != float("inf") and (d[u] + c < d[v]):
          d[v] = d[u] + c
          if i > N: d[v] = -float("inf")
      if i == self.n:
        first = d[t] + 0
      elif i == self.n * 2:
        if first != d[t]:
          return "-loop"
    return d[t]
bf = BellmanFord(N, e)
res = bf.path_findloop(1, N)
print(res)
if res == "-loop": print(-1)
else: print(max(0, -res))
Problem p02972 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
res = [0] + a[:]
for i in range(N, 0, -1):
  res[i] = sum(res[i : : i]) % 2 
print(sum(res))
print(*[i for i in range(N + 1) if res[i]])

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
res = [0] + a[:]
 
for i in range(n, 0, -1):
    ans[i] = sum(ans[i : : i]) % 2 
print(sum(res))
print(*[i + 1 for i in range(n) if res[i]])

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
res = a[:]
 
for i in range(n, 0, -1):
    ans[i] = sum(ans[i : : i]) % 2 
print(sum(res))
print(*[i + 1 for i in range(n) if res[i]])
Problem p02999 (python)

Fixed submission:
inputa = list(map(int, input().split()))
if inputa[0] < inputa[1]:
  print("0")
else:
  print("10")

Buggy submission (verdict: Runtime Error):
inputa = list(map(int(), input()))
if inputa[0] < inputa[1]:
  print("0")
else:
  print("10")
Problem p03001 (python)

Fixed submission:
inputa = list(map(int, input().split()))
 
S = inputa[0] * inputa[1] / 2
 
if inputa[0] / 2 == inputa[2]:
  if inputa[1] / 2 == inputa[3]:
    print (S, " 1")
    exit(0)
print (S, " 0")

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

S = inputa[0] * inputa[1] / 2

# W:H = x:y
# Hx = yW
# y = (H/W)x

if W / 2 == x:
  if H / 2 == y:
    print (S, " 1")
    exit(0)
print (S, " 0")
Problem p03005 (python)

Fixed submission:
N, K = map(int, input().split())
if K == 1: print(0)
else: print(N - K)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

dp = [0] * (N + 1)
for i in range(N, -1, -1):
  for j in range(3):
    x = a[j]
    y = b[j]
    if i - x >= 0:
      dp[i - x] = max(dp[i - x], dp[i] + y)
for i in range(N + 1): dp[i] += i
#print(dp)
t = max(dp)
e = []
def check(x):
  tt = t - b[e[0]] * x
  return (tt // b[e[1]]) * a[e[1]] + tt % b[e[1]] + a[e[0]] * x

if t > N:
  for i in range(3):
    if b[i] < a[i]: e.append(i)
  if len(e) == 0:
    print(t)
  elif len(e) == 1:
    print(a[e[0]] * (t // b[e[0]]) + t % b[e[0]])
  else:
    if b[e[0]] < b[e[1]]: e[0], e[1] = e[1], e[0]
    x = e[0]
    res = 0
    for i in range(t // b[x] + 1): res = max(res, check(i))
    print(res)
else:
  dp = [0] * (N + 1)
  for i in range(N, -1, -1):
    for j in range(3):
      y = a[j]
      x = b[j]
    if i - x >= 0:
      dp[i - x] = max(dp[i - x], dp[i] + y)
  for i in range(N + 1): dp[i] += i
  print(max(dp))
Problem p03007 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
p = [t for t in a if t >= 0]
m = [t for t in a if t < 0]
p.sort(reverse = True)
m.sort()
l = []
if N == 2:
  print(max(a) - min(a))
  print(max(a), min(a))
  exit(0)
if len(p) == 0:
  u = m.pop()
  v = m.pop()
  l.append((u, v))
  p.append(u - v)
if len(m) == 0 and len(p) >= 2:
  u = p.pop()
  v = p.pop()
  l.append((u, v))
  m.append(u - v)
while len(p) >= 2:
  u = m.pop()
  v = p.pop()
  l.append((u, v))
  m.append(u - v)
while len(m):
  t = p[0]
  u = m.pop()
  l.append((t, u))
  p[0] = t - u
print(p[0])
for res in l:
  print(*res)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
p = [t for t in a if t >= 0]
m = [t for t in a if t < 0]
p.sort(reverse = True)
m.sort()
l = []
#print(a)
if len(p) == 0:
  u = m.pop()
  v = m.pop()
  l.append((u, v))
  p.append(u - v)
if len(m) == 0 and len(p) >= 2:
  u = p.pop()
  v = p.pop()
  l.append((u, v))
  m.append(u - v)
while len(p) >= 2:
  u = m.pop()
  v = p.pop()
  l.append((u, v))
  m.append(u - v)
while len(m):
  t = p[0]
  u = m.pop()
  l.append((t, u))
  p[0] = t - u
print(p[0])
for res in l:
  print(*res)
Problem p03043 (python)

Fixed submission:
import math
inputa = input().split()
inputa[0] = int(inputa[0])
inputa[1] = int(inputa[1])
tempa = []
tempb = float(inputa[1])
tempc = []
res = float(0)
if tempb == 1:
	print(1)
	exit()
while tempb >= 0.5:
	#print(tempb)
	if tempb <= inputa[0]:
		tempa.append(math.floor(inputa[0] - tempb + 1))
	else:
		tempa.append(0)
	tempb /= 2

i = 1
tempc.append(tempa[0])
#print(tempa)
while i < len(tempa):
	tempc.append(tempa[i] - tempa[i - 1])
	i += 1
#print(tempc)
for i, num in enumerate(tempc):
	#print(num / inputa[0] / (2 ** i))
	res += num / inputa[0] / (2 ** i)

print(res)

Buggy submission (verdict: Runtime Error):
inputa = input().split()
inputa[0] = int(inputa[0])
inputa[1] = int(inputa[1])
tempa = []
tempb = float(inputa[1])
tempc = []
res = float(0)
if tempb == 1:
  print(1)
  exit()
while tempb > 1:
  if tempb <= inputa[0]:
    tempa.append(inputa[0] - tempb + 1)
  else:
    tempa.append(0)
    
  tempb /= 2

i = 1
tempc.append(tempa[0])
while i <= len(tempa):
  tempc.append(tempa[i] - tempa[i - 1])
  i += 1

for i, num in enumerate(tempc):
  res += num / inputa[0] / (2 ** i)

print(res)

Buggy submission (verdict: Runtime Error):
inputa = input().split()
inputa[0] = int(inputa[0])
inputa[1] = int(inputa[1])
tempa = []
tempb = float(inputa[1])
tempc = []
res = float(0)
if tempb == 1:
  print(1)
  exit()
while tempb > 1:
  if tempb <= inputa[0]:
    tempa.append(inputa[0] - tempb + 1)
  else:
    tempa.append(0)
    
  tempb /= 2

i = 1
tempc.append(tempa[0])
while i <= len(tempa):
  tempc.append(tempa[i] - tempa[i - 1])
  i += 1

for i, num in enumerate(tempa):
  res += num / inputa[0] / (2 ** i)

print(res)
Problem p03071 (python)

Fixed submission:
x = list(map(int, input().split()))
print(max(x) * 2 - 1) if min(x) != max(x) else print(x[0] * 2)

Buggy submission (verdict: Runtime Error):
print(max(list(map(input().split()))) * 2 - 1)
Problem p03074 (python)

Fixed submission:
N, K = map(int, input().split())
S = list(input()) + [-1]
bw = [0] * N
ind = 0
for i in range(N):
  bw[ind] += S[i] == S[i + 1]
  if S[i] != S[i + 1]:
    bw[ind] += 1
    ind += 1
ind = 0
res = 0
cumsumbw = [0] + [bw[0]] + [0] * (N - 1)
for i in range(1, N):
  cumsumbw[i + 1] = cumsumbw[i] + bw[i]
if N - 2 * K <= 0:
  print(N)
  exit(0)
for i in range(N - 2 * K):
  if S[cumsumbw[i]] == "1":
    res = max(res, cumsumbw[i + 2 * K + 1] - cumsumbw[i])
  else:
    res = max(res, cumsumbw[i + 2 * K] - cumsumbw[i])
  #print(res)
print(res)
#print(bw)
#print(cumsumbw)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = list(input())
bw = [0] * N
ind = 0
for i in range(N):
  bw[ind] += S[i] == S[i + 1]
  if S[i] != S[i + 1]:
    bw[ind] += 1
    ind += 1
ind = 0
res = 0
cumsumbw = [0] + [bw[0]] + [0] * (N - 1)
for i in range(1, N):
  cumsumbw[i + 1] = cumsumbw[i] + bw[i]
if N - 2 * K <= 0:
  print(N)
  exit(0)
for i in range(N - 2 * K):
  if S[i] == "1":
    res = max(res, cumsumbw[i + 2 * K + 1] - cumsumbw[i])
  else:
    res = max(res, cumsumbw[i + 2 * K] - cumsumbw[i])
print(res)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)
N, K = map(int, input().split())
S = list(map(int, list(input())))
def solve(l, k):
  if k == K:
    temp = 1
    thrbl = 0
    for i in range(l + 1, N):
      temp += 1
      if thrbl == 0 and S[i] == 1:
        thrbl = 1
      elif thrbl == 1 and S[i] == 0:
        temp -= 1
        break
    #print(l, temp, k)
    return temp
  temp = 0
  for i in range(l + 1, N):
    if S[i] == 0:
      temp = solve(i, k + 1)
      thrbl = 0
      for j in range(l + 1, i):
        temp += 1
        if thrbl == 0 and S[j] == 1:
          thrbl = 1
        elif thrbl == 1 and S[j] == 0:
          temp -= 1
          break
      if k == 1:
        thrbl = 0
        for j in range(l, -1, -1):
          temp += 1
          #print(j)
          if j == l:
            continue
          if thrbl == 0 and S[j] == 1:
            thrbl = 1
          elif thrbl == 1 and S[j] == 0:
            temp -= 1
            break
      #print(l, i, temp, k)
      return temp
res = 0
for i in range(N):
  if S[i] == 0:
    if i > 0 and S[i - 1] != 0:
      res = max(solve(i, 1), res)
    elif i == 0:
      res = max(solve(i, 1), res)
print(res) if res != 0 else print(N)
Problem p03078 (python)

Fixed submission:
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
AB = []
for i in range(X):
  for j in range(Y):
    AB.append(ABC[0][i] + ABC[1][j])
AB.sort(reverse = True)
res = []
for i in range(min(K, X * Y)):
  for j in range(Z):
    res.append(AB[i] + ABC[2][j])
res.sort(reverse = True)
for i in range(K):
  print(res[i])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
AB = []
for i in range(X):
  for j in range(Y):
    AB.append(ABC[0][i] + ABC[1][j])
AB.sort(reverse = True)
res = []
for i in range(K):
  for j in range(Z):
    res.append(AB[i] + ABC[2][j])
res.sort(reverse = True)
for i in range(K):
  print(res[i])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
temp = []
minabc = bl((X, Y, Z), min(X, Y, Z))
abcs = [i for i in range(3) if i != minabc]
for i in range((X, Y, Z)[abcs[0]]):
  for j in range((X, Y, Z)[abcs[1]]):
    temp.append(ABC[abcs[0]][i] + ABC[abcs[1]][j])
temp.sort()
r = len(temp) - 1
u = 0
Q = dq([])
Q.append([r, u])
res = []
visited = [[0] * len(temp) for _ in range((X, Y, Z)[minabc])]
while len(Q):
  q = Q.popleft()
  res.append(temp[q[0]] + ABC[minabc][q[1]])
  if r - q[0] + q[1] > K:
    continue
  if q[0] != 0 and visited[q[1]][q[0] - 1] == 0:
    Q.append([q[0] - 1, q[1]])
    visited[q[1]][q[0] - 1] = 1
  if q[1] != (X, Y, Z)[minabc] - 1 and visited[q[1] + 1][q[0] - 1] == 0:
    Q.append([q[0], q[1] + 1])
    visited[q[1] + 1][q[0]] = 1
res.sort()
for _ in range(K):
  print(res.pop())

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
temp = []
minabc = bl((X, Y, Z), min(X, Y, Z))
abcs = [i for i in range(3) if i != minabc]
for i in range((X, Y, Z)[abcs[0]]):
  for j in range((X, Y, Z)[abcs[1]]):
    temp.append(ABC[abcs[0]][i] + ABC[abcs[1]][j])
temp.sort()
r = len(temp) - 1
u = 0
Q = dq([])
Q.append([r, u])
res = []
visited = [[0] * len(temp) for _ in range((X, Y, Z)[minabc])]
while len(Q):
  q = Q.popleft()
  res.append(temp[q[0]] + ABC[minabc][q[1]])
  if r - q[0] + q[1] > K:
    continue
  if q[0] != 0 and visited[q[1]][q[0] - 1] == 0:
    Q.append([q[0] - 1, q[1]])
    visited[q[1]][q[0] - 1] = 1
  if q[1] != (X, Y, Z)[minabc] - 1 and visited[q[1] + 1][q[0] - 1] == 0:
    Q.append([q[0], q[1] + 1])
    visited[q[1] + 1][q[0]] = 1
res.sort()
for _ in range(K):
  print(res.pop())
Problem p03096 (python)

Fixed submission:
import sys
from bisect import bisect_left as bl
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(input())
table = [[] for _ in range(2 * pow(10, 5) + 1)]
a = []
t = 0
mod = 10 ** 9 + 7
for i in range(N):
  x = int(input())
  if t != x:
    table[x].append(i)
    t = x
  a.append(x)
#print(table[4], table[3])
dp = [0] * N
dp[0] = 1
for i in range(N):
  j = br(table[a[i]], i)
  k = bl(table[a[i]], i)
  if j < len(table[a[i]]) and (table[a[i]][k] == i):
    dp[table[a[i]][j]] += dp[i]
    dp[table[a[i]][j]] %= mod
  if i + 1 < N: 
    dp[i + 1] += dp[i]
    dp[i + 1] %= mod
  #print(dp)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(input())
table = [[] for _ in range(N + 1)]
a = []
t = 0
mod = 10 ** 9 + 7
for i in range(N):
  x = int(input())
  if t != x:
    table[x].append(i)
    t = x
  a.append(x)
#print(table)
dp = [0] * N
dp[0] = 1
for i in range(N):
  j = br(table[a[i]], i)
  if j < len(table[a[i]]):
    dp[table[a[i]][j]] += dp[i]
    dp[table[a[i]][j]] %= mod
  if i + 1 < N: 
    dp[i + 1] += dp[i]
    dp[i + 1] %= mod
  #print(dp)
print(dp[-1])
Problem p03148 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

s = [tuple(map(int, input().split())) for _ in range(N)]
s.sort(key = lambda x: -x[1])
table = [(-1, -1)] * (N + 1)
c = 0
for i in range(N):
  if table[s[i][0]] == (-1, -1):
    table[s[i][0]] = (i, s[i][1])
    c += 1

table.sort(key = lambda x: -x[1])
res = [0] * (min(c, M) + 1)
vis = set()
p = M
for i in range(M): res[0] += s[i][1]
for x in range(1, min(c, M) + 1):
  res[x] = res[x - 1] + pow(x, 2) - pow(x - 1, 2)
  if table[x - 1][0] >= M:
    res[x] += table[x - 1][1]
    p -= 1
    while p in vis:
      p -= 1
    res[x] -= s[p][1]
  vis.add(table[x - 1][0])
  #print(p)
print(max(res))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

s = [tuple(map(int, input().split())) for _ in range(N)]
s.sort(key = lambda x: -x[1])
table = [(-1, -1)] * (N + 1)
c = 0
for i in range(N):
  if table[s[i][0]] == (-1, -1):
    table[s[i][0]] = (i, s[i][1])
    c += 1

table.sort(key = lambda x: -x[1])
res = [0] * (M + 1)
vis = set()
p = M
for i in range(M): res[0] += s[i][1]
for x in range(1, c + 1):
  res[x] = res[x - 1] + pow(x, 2) - pow(x - 1, 2)
  if table[x - 1][0] >= M:
    res[x] += table[x - 1][1]
    p -= 1
    while p in vis:
      p -= 1
    res[x] -= s[p][1]
  vis.add(table[x - 1][0])
  #print(p)
print(max(res))