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

Fixed submission:
from collections import Counter

N= int(input())

a = list(map(int, input().split()))

x = Counter(a)

ok = False
if len(x) == 3 and len(a) % 3 == 0:
    for i in a:
        if x[i] != len(a) // 3:
            break
    else:
        w = 0
        for j in x:
            w ^= j
        if w == 0:
            ok = True
elif len(x) == 1:
    if x.get(0) is not None:
        ok = True
elif len(x) == 2 and len(a) % 3 == 0:
    if x.get(0) is not None and x[0] == len(a) // 3:
        ok = True

if ok:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA, self), BridgeEdge(nodeB, self)]
        nodeA.addEdge(self.edges[1])
        nodeB.addEdge(self.edges[0])
        self.dir = True
        self.vec = None

class BridgeEdge:
    def __init__(self, node, edge):
        self.edge = edge
        self.node = node
    def another(self):
        return self.edge.edges[1 if self.edge.edges[0] == self else 0]

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
        self.parent = None
        self.judge = 0
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)
    def __repr__(self):
        return str((self.id, None if self.parent is None else self.parent.node.id))

N, M = map(int, input().split())

nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(N)):
    bridges.append(Bridge(nodes[A], nodes[B]))

s = [(None, nodes[1])]
idx = 0
ok = True
while idx < len(s):
    pre, cur = s[idx]
    idx += 1


    for nxt in cur.bridges:
        if nxt.node.judge <= 0:
            nxt.node.parent = nxt.another()
            cur.judge += 1
            nxt.edge.vec = (cur.id, nxt.node.id)
            s.append((cur, nxt.node))


    if cur.judge % 2 == 1:
        ok = not ok
        wrk = cur
        while wrk.parent is not None:
            br = wrk.parent.edge
            br.dir = not br.dir
            wrk = wrk.parent.node

if ok:
    for br in bridges:
        if br.dir:
            print("{} {}".format(br.vec[1], br.vec[0]))
        else:
            print("{} {}".format(br.vec[0], br.vec[1]))
else:
    print("-1")
Problem p03006 (python)

Fixed submission:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

dic = dict()
for cx, cy in xy:
    for x, y in xy:
        if cx != x or cy != y:
            w = (x-cx,y-cy)
            if dic.get(w) is None:
                dic[w] = 0
            dic[w] += 1

cnt = 1
m = 0
for x in dic:
    m = max(m, dic[x])
cnt += N - 1 - m
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

counter = Counter(((b1[0] - b2[0], b1[1] - b2[1]) for b1 in xy for b2 in xy if b1 != b2))
print(N - (counter.most_common()[0]+[(0,0)])[1])

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

counter = Counter(((b1[0] - b2[0], b1[1] - b2[1]) for b1 in xy for b2 in xy if b1 != b2))
print(N - counter.most_common()[0][1])

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

counter = Counter(((b1[0] - b2[0], b1[1] - b2[1]) for b1 in xy for b2 in xy if b1 != b2))
print(N - counter.most_common()[0][1])

Buggy submission (verdict: Runtime Error):
from itertools import combinations

n = int(input())
balls = []
cost = n
for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

for b1, b2 in combinations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    if p != 0 or q != 0:
        sub = 0
        for b3, b4 in permutations(balls, 2):
            dx, dy = b3[0] - b4[0], b3[1] - b4[1]
            if dx == p and dy == q:
                sub += 1
        cost = min(cost, n - sub)

print(max(cost, 1))

Buggy submission (verdict: Runtime Error):
from itertools import combinations

n = int(input())
balls = []
cost = n
for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

for b1, b2 in combinations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    if p != 0 or q != 0:
        sub = 0
        for ball in balls:
            bx, by = ball
            dx, dy = bx - b2[0], by - b2[1]
            if dx % p == 0 and dy % q == 0 and dx // p == dy // q:
                sub += 1
        cost = min(cost, n - sub)

print(max(cost, 1))
Problem p03023 (python)

Fixed submission:
N = int(input())
print("{:.0f}".format((180 -  360 / N) * N))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def opt(a, b):
    c = gcd(a, b)
    return a//c, b//c

def dot(A, B):
    a = A[0] * B[0]
    b = A[1] * B[1]
    return opt(a, b)

def add(A, B):
    return opt(A[0]*B[1] + B[0]*A[1], A[1] * B[1])

N, A, B, C = map(int, input().split())

A = opt(A, 100)
B = opt(B, 100)
C = opt(C, 100)

g = 1000000007

c = [((1, 1), 0, 0, 0)]
ans = (0, 1)
e = (0, 1)
pi = 0
while pi < len(c):

    PQ, cnt, acnt, bcnt = c[pi]
    pi += 1

    if e[1] > (e[1] - e[0]) * g * 100:
        continue
    if acnt >= N or bcnt >= N:
        e = add(e, PQ)
        ans = add(ans, opt(cnt * PQ[0], PQ[1]))
        continue

    cnt += 1
    c.append((dot(PQ, A), cnt, acnt+1, bcnt))
    c.append((dot(PQ, B), cnt, acnt, bcnt+1))
    c.append((dot(PQ, C), cnt, acnt, bcnt))


print(ans[0] * pow(ans[1], g-2,g)%g)
Problem p03030 (python)

Fixed submission:
N = int(input())
SP = [[x+1] + list(input().split()) for x in range(N)]

SP2 = sorted(sorted(SP, key=lambda x:int(x[2]), reverse=True), key=lambda x:x[1])

for i in range(N):
    print(SP2[i][0])

Buggy submission (verdict: Runtime Error):
N = int(input())
S = sorted((map(lambda y: (y[0], -int(y[1]), x), input().split()) for x in range(1, N+1)))
for x in S:
  print(x[2])
Problem p03037 (python)

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

allL = 1
allR = N
for L, R in (map(int, input().split()) for _ in range(M)):
  allL = max(allL, L)
  allR = min(allR, R)

print(max(allR - allL + 1, 0))

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

allL = 1
allR = N
for L, R in map(int, input().split()) in range(M):
  allL = max(allL, L)
  allR = min(allR, R)

print(max(allR - allL + 1, 0))
Problem p03061 (python)

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

def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    g = x % y
    if g == 0:
        return y
    return gcd(y, g)

R = [0] * N
R[N-1] = w = 0
for i in range(N-2, -1, -1):
    R[i] = w = gcd(w, A[i+1])

L = [0] * N
L[0] = w = 0
for i in range(1, N):
    L[i] = w = gcd(w, A[i-1])

w = 1
for i in range(N):
    w = max(w, gcd(L[i], R[i]))

print(w)

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

from functools import lru_cache
@lru_cache(maxsize = None)
def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    if y == 0:
        return x
    return gcd(y, x % y)


def L(x):
    if x <= 0:
        return 0
    else:
        return gcd(L(x-1), A[x-1])

def R(x):
    if x >= N - 1:
        return 0
    else:
        return gcd(A[x+1], R(x+1))

for i in range(N-1, -1, -1):
    R(i)

w = 1
for i in range(N):
    w = max(w, gcd(L(i), R(i)))

print(w)

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

def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    if y == 0:
        return x
    return gcd(y, x % y)

from functools import lru_cache
@lru_cache(maxsize = None)

def L(x):
    if x <= 0:
        return 0
    else:
        return gcd(L(x-1), A[x-1])

def R(x):
    if x >= N - 1:
        return 0
    else:
        return gcd(A[x+1], R(x+1))

for i in range(N-1, -1, -1):
    R(i)

w = 1
for i in range(N):
    w = max(w, gcd(L(i), R(i)))

print(w)

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

def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    if y == 0:
        return x
    return gcd(y, x % y)

from functools import lru_cache
@lru_cache(maxsize = 10005)

def L(x):
    if x <= 0:
        return 0
    else:
        return gcd(L(x-1), A[x-1])

def R(x):
    if x >= N - 1:
        return 0
    else:
        return gcd(A[x+1], R(x+1))

w = 1
for i in range(N):
    w = max(w, gcd(L(i), R(i)))

print(w)

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

def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    if y == 0:
        return x
    return gcd(y, x % y)

from functools import lru_cache
@lru_cache(maxsize = None)

def L(x):
    if x <= 0:
        return 0
    else:
        return gcd(L(x-1), A[x-1])

def R(x):
    if x >= N - 1:
        return 0
    else:
        return gcd(A[x+1], R(x+1))

w = 1
for i in range(N):
    w = max(w, gcd(L(i), R(i)))

print(w)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = list(map(int, input().split()))

sw = 0
for i in range(N):
    w = A[0 if i != 0 else 1]
    for j in range(N):
        if j != i:
            w = math.gcd(w, A[j])
    sw = max(sw, w)

print(sw)
Problem p03067 (python)

Fixed submission:
import sys
import math
N = list(map(int, input().split()))

t = False
if (N[0] < N[1]) == (N[0] < N[2]):
    if abs(N[1] - N[0]) > abs(N[2] - N[0]):
        t = True

print("Yes" if t else "No")

Buggy submission (verdict: Runtime Error):
x = map(int, input().split())
x = x[0], x[2], x[1]
print("Yes" if all(map(lambda x, y: x==y, x, sorted(x))) else "No")

Buggy submission (verdict: Runtime Error):
x = input().split()
x = x[0], x[2], x[1]
print("yes" all(map(lambda x, y: x==y, x, sorted(x))) else "No")
Problem p03068 (python)

Fixed submission:
import re
N = int(input())
S = input()
K = int(input())

w = S[K-1]
print(re.sub("[^#]", "*", S.replace(w, "#")).replace("#", w))

Buggy submission (verdict: Runtime Error):
input()
s = list(input())
print("".join(("*" if x != y else x for x in s[int(input())] for y in s )))
Problem p03071 (python)

Fixed submission:
A, B = map(int, input().split())

AB = []
AB += [A, B]

def push(AB):
  if AB[0] >= AB[1]:
    i = 0
  else:
    i = 1
  ret = AB[i]
  AB[i] -= 1
  return ret

s = 0
for _ in range(2):
	s += push(AB)

print(s)

Buggy submission (verdict: Runtime Error):
class BufInput:
  def __init__(self):
    self.save = False
    self.buf = None
  def read(self, save=False):
    if self.save:
      ret = self.buf
    else:
      try:
        ret = input()
      except EOFError as e:
      	ret = None
    self.save = save
    self.buf = ret
    return ret
    
  
bi = BufInput()
while bi.read(True):
  n, k = map(int, bi.read().split())
  s = bi.read().rstrip()

  def findEx(s, f, pos, notfound):
    pos = s.find(f, pos)
    if pos == -1:
      pos = notfound
    return pos

  ans = 0
  left = 0
  right = 0
  while right < n:
      if k > 0:
          right = findEx(s, '01', right, n-1) + 1
          k = k - 1
          right = findEx(s, '10', right, n-1) + 1
          ans = max(ans, right - left)
      else:
          left = findEx(s, '01', left, n-1) + 1
          k = k + 1

  print(ans)

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

def findEx(s, f, pos, notfound):
  pos = s.find(f, pos)
  if pos == -1:
    pos = notfound
  return pos
    
ans = 0
left = 0
right = 0
while right < n:
    if k > 0:
        right = findEx(s, '01', right, n-1) + 1
        k = k - 1
        right = findEx(s, '10', right, n-1) + 1
        ans = max(ans, right - left)
    else:
        left = findEx(s, '01', left, n-1) + 1
        k = k + 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
k += 1
s = "01" + input().rstrip()
ans = 0
i = 0
left = 2
right = 1
while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input().rstrip()
ans = 1
left = 0
right = -1
pos = s.find('10', 0)
if pos == -1:
  i = n
else:
  i = pos + 1

while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)
Problem p03074 (python)

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


#n, k = 5, 3
#s = "00010"

m = 0
cur_s = cur_e = 0

while True:
  while cur_e < n and s[cur_e] == '1':
    cur_e+=1
  
  if k <= 0 or cur_e >= n:
    wm = cur_e - cur_s
    if wm > m:
      m = wm
      
    if cur_e >= n:
      break
 
    while cur_s < n and s[cur_s] == '1':
      cur_s+=1
    while cur_s < n and s[cur_s] == '0':
      cur_s+=1
    k+=1

  if k > 0:
    while cur_e < n and s[cur_e] == '0':
      cur_e+=1
    k-=1
    
print(m)

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

  def findEx(s, f, pos, notfound):
    pos = s.find(f, pos)
    if pos == -1:
      pos = notfound
    return pos

  ans = 0
  left = 0
  right = 0
  while right < n:
      if k > 0:
          right = findEx(s, '01', right, n-1) + 1
          k = k - 1
          right = findEx(s, '10', right, n-1) + 1
          ans = max(ans, right - left)
      else:
          left = findEx(s, '01', left, n-1) + 1
          k = k + 1

  print(ans)

  if input() == "":
    break

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input().rstrip()
ans = 1
left = 0
right = -1
pos = s.find('10', 0)
if pos == -1:
  i = n
else
  i = pos + 1

while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)

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

#s = "0001111011110"
#n, k = len(s), 1

s="1"+s

k_pt = 0
cur_tail = 0
for cur in range(1, n):

  cur_tail+=1

  if  s[cur-1] == '1' and s[cur] == '0':
    k_pt+=1

  if  s[cur_tail-1] == '0' and s[cur_tail] == '1':
    k_pt-=1

  if k_pt <= k:
      cur_tail-=1

print(cur-cur_tail)

Buggy submission (verdict: Runtime Error):

n, k = map(int, input().split())
s = input().rstrip()
m = 0
cur_s = cur_e = 0

while True:
  while s[cur_e] == '1':
    cur_e++
  
  if k <= 0 or cur_e >= n:
    wm = cur_e - cur_s
    if wm < m:
      m = wm
      
    if cur_e >= n:
      break
 
    while s[cur_s] == '1':
      cur_s++
    while s[cur_s] == '0':
      cur_s++
    k++

  if k > 0:
    while s[cur_e] = '0':
      cur_e++
    k--
    
print(m)
Problem p03085 (python)

Fixed submission:
T='ATCG'
print(T[T.find(input())^1])

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

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])
Problem p03086 (python)

Fixed submission:
S=input()

c=m=0
for x in S:
  #print((m,c,x,"ACGT".find(x)))
  if "ACGT".find(x)>=0:
    c+=1
    m = max(m, c)
  else:
    c = 0

print(m)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
L=[tuple(map(int, input().split())) for _ in range(Q)]
print("\n".join([str(len(S[nS-1:nE])-len(S[nS-1:nE].replace("AC", "|"))) for nS, nE in L]))
Problem p03087 (python)

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

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

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

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

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

lis = [0] * (len(S)+1)
for i in range(len(S)+1):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S) and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1

    
for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy submission (verdict: Runtime Error):
_=input()
A=map(lambda x:("A", int(x)), input())
B=map(lambda x:("B", int(x)), input())
C=map(lambda x:("C", int(x)), input())
S = sorted(A, cmp=lambda x, y:-x[1] + y[1])

A=None
B=None
C=None
for i in len(S):
  if A==None and x[0]=="A":
    A=i
  elif B==None and x[0]=="B":
    B=i
  elif C==None and x[0]=="C":
  	C=i

for i in [A, B, C].sort()[::-1]:
  del S[i]

print(S)
Problem p03095 (python)

Fixed submission:
N = input()
c = [1]*("z".encode()[0]-"a".encode()[0]+1)
for x in map(lambda x: x-"a".encode()[0], input().encode()):
	c[x] += 1

m = 1
for x in c:
  m = (m * x) % (1e9+7)

print("{:.0f}".format(m-1))

Buggy submission (verdict: Runtime Error):
c = [1]*("z".encode()-"a".encode()+1)
for x in map(lambda x: x-"a".encode(), input().encode()):
	c[x] += 1

m = 1
for x in c:
  m *= c

print(m-1)
Problem p03125 (python)

Fixed submission:
A, B=map(int, input().split())
print(A+B if B%A==0 else B-A)

Buggy submission (verdict: Runtime Error):
A, B=map(int, input())
print(A+B if B%A==0 else B-A)
Problem p03147 (python)

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

Hk = set([0])
for h in H:
  Hk.add(h)
Hk = sorted(Hk)

def po(h, s, e):
  if h >= len(Hk)-1:
    return Hk[h] - Hk[h-1]
  posS = s
  cnt = 0
  for posE in range(s, e+1):
    if posE >= e or H[posE] <= Hk[h]:
      if posS < posE:
        cnt += po(h+1, posS, posE)
      posS = posE + 1
  if h > 0:
    cnt += Hk[h] - Hk[h-1]
  return cnt

print(po(0, 0, len(H)))

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

Hk = set()
for h in H:
  Hk.add(h)

def po(h, s, e):
  if h >= Hk[-1]:
    return 1
  posS = s
  hit = False
  cnt = 0
  for posE in range(s, e+1):
    if posE >= e or H[posE] <= Hk[h]:
      hit or= (posE < e)
	if posS < posE:
      cnt += po(h+1, posS, posE)
  if hit:
    cnt += 1
  return cnt
Problem p03150 (python)

Fixed submission:
S = input()
key = "keyence"
for i in range(len(key)+1):
  if key == S[:i] + S[len(S)-len(key)+i:]:
    print("YES")
    break
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
S = input()
key = "keyence"
for i in range(len(key)+1):
  if S.find(key[:i]) == 0 and s.find(key[i:], len(S)-i) == len(S) - i:
    print("Yes")
    break
else:
  print("No")
Problem p03160 (python)

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
P = [0] + [-1] * (len(H)-1)

def minv(i, v):
  if i < len(H):
    cost = v()
    if P[i] < 0:
      P[i] = cost
    else:
      P[i] = min(P[i], cost)

for i in range(len(H)-1):
  minv(i + 1, lambda : P[i] + abs(H[i] - H[i+1]))
  minv(i + 2, lambda : P[i] + abs(H[i] - H[i+2]))

print(P[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
P = [-1] * len(H)

def minv(i, v):
  if i < len(H):
    if P[i] < 0:
      P[i] = v
    else:
      P[i] = min(P[i], v)

for i in range(len(H)-1):
  minv(i + 1, H[i] + abs(H[i] - H[i+1]))
  minv(i + 2, H[i] + abs(H[i] - H[i+2]))

print(H[-1])
Problem p03161 (python)

Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))
P = [0] + [-1] * (len(H)-1)

def minv(i, v):
  if i < len(H):
    cost = v()
    if P[i] < 0:
      P[i] = cost
    else:
      P[i] = min(P[i], cost)

for i in range(len(H)-1):
  for k in range(1, K+1):
    minv(i + k, lambda : P[i] + abs(H[i] - H[i+k]))

print(P[-1])

Buggy submission (verdict: Runtime Error):
N, K = int(input())
H = list(map(int, input().split()))
P = [0] + [-1] * (len(H)-1)

def minv(i, v):
  if i < len(H):
    cost = v()
    if P[i] < 0:
      P[i] = cost
    else:
      P[i] = min(P[i], cost)

for i in range(len(H)-1):
  for k in range(1, K+1):
    minv(i + k, lambda : P[i] + abs(H[i] - H[i+k]))

print(P[-1])

Buggy submission (verdict: Runtime Error):
N, K = int(input())
H = list(map(int, input().split()))
P = [0] + [-1] * (len(H)-1)

def minv(i, v):
  if i < len(H):
    cost = v()
    if P[i] < 0:
      P[i] = cost
    else:
      P[i] = min(P[i], cost)

for i in range(len(H)-1):
  for k in range(1, K+1):
    minv(i + 1, lambda : P[i] + abs(H[i] - H[i+k]))

print(P[-1])
Problem p03162 (python)

Fixed submission:
N = int(input())
wa, wb, wc = [0] * 3
for a, b, c in (map(int, input().split()) for _ in range(N)):
  wa, wb, wc = a + max(wb, wc), b + max(wa, wc), c + max(wa, wb)
print(max(wa, wb, wc))

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

DP = [-1] * (W+1)
DP[W] = 0

def maxv(i, v):
    if i >= 0:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    for i in range(1, W+1):
        if DP[i] >= 0:
            maxv(i-w, DP[i]+v)
            maxv(0, DP[i-w])

print(DP[0])
Problem p03163 (python)

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

DP = [-1] * (W+1)
DP[W] = 0

def maxv(i, v):
    if i >= 0:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    for i in range(1, W+1):
        if DP[i] >= 0:
            maxv(i-w, DP[i]+v)
            maxv(0, DP[i-w])

print(DP[0])

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

DP = {0: 0}
for i in range(N):
    wi, vi = map(int, input().split())
    for j in DP:
        if j+wi <= W:
            DP_dst[j+wi] = max(DP.get(j+wi, 0), DP[j]+vi)
    DP = DP_dst
print(max((DP[x] for x in DP)))
Problem p03164 (python)

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

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break

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

DP = [-1] * (W+1)
DP[W] = 0

def maxv(i, v):
    if i >= 0:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    for i in range(1, W+1):
        if DP[i] >= 0:
            maxv(i-w, DP[i]+v)
            maxv(0, DP[i-w])

print(DP[0])