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

Fixed submission:
A, op, B = input().split()
if op == '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))

Buggy submission (verdict: Runtime Error):
A, op, B = input().split()
if op = '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))
Problem p03845 (python)

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

s = sum(T)
for i in range(M):
  P, X = map(int, input().split())
  print(s - T[P-1] + X)

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

s = sum(T)
for i in range(N):
  P, X = map(int, input().split())
  print(s - T[P-1] + X)
Problem p03962 (python)

Fixed submission:
s = set(map(int, input().split()))
print(len(s))

Buggy submission (verdict: Runtime Error):
s = set(map(int, input().split()))
print(s.count())
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print( (a + b) * h // 2)

Buggy submission (verdict: Runtime Error):
a, b, h = map(int, input().split())
print( (a+b) * h // 2)
Problem p04011 (python)

Fixed submission:
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N <= K:
  print(N * X)
else:
  print(K * X + (N-K) * Y)

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

if N <= K:
  print(N * X)
else:
  print(K * X + (N-K) * Y)
Problem p04012 (python)

Fixed submission:
w = input()

f = True
for i in range(len(w)):
  if w.count(w[i]) % 2 == 1:
    print("No")
    f = False
    break
if f:
  print("Yes")

Buggy submission (verdict: Runtime Error):
w = input()

f = True
for i in renge(len(w)):
  if w.count(w[i]) % 2 == 1:
    print("No")
    f = False
if f:
  print("Yes")
Problem p04031 (python)

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

r = (200 ** 2)*100

for i in range(-100,101):
  res = 0
  for j in range(N):
    res += (L[j] - i) ** 2
  r = min(r, res)
print(r)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [int(input()) for i in range(N)]

r = 200*100

for i in range(-100,101):
  res = 0
  for j in range(N):
    res += (L[j] - i) ** 2
  r = min(r, res)
print(r)
Problem p04045 (python)

Fixed submission:
N, K = map(int, input().split())
DL = list(map(int, input().split()))
Dlist = [1,1,1,1,1,1,1,1,1,1]
for i in range(len(DL)):
  Dlist[DL[i]]=0

while True:
  f = True
  Nx = str(N)
  for i in range(len(Nx)):
    if Dlist[int(Nx[i])] == 0:
      f = False
  if f:
    print(N)
    break
  else:
    N += 1

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
Dlist = [1,1,1,1,1,1,1,1,1,1]
for i in range(K):
  D = int(input())
  Dlist[D]=0

while True:
  f = True
  Nx = str(N)
  for i in range(len(Nx)):
    if Dlist[int(Nx[i])] == 0:
      f = False
  if f:
    print(N)
    break
  else:
    N += 1
Problem p03210 (python)

Fixed submission:
x=input()
if x=='7' or x=='5' or x=='3':
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
x=input()
if x=='7' or x=='5' or x=='3': print('YES') else print('NO')
Problem p03385 (python)

Fixed submission:
s=input()
s=''.join(sorted(s))
if s=='abc':
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s=input()
s.sort()
if s=='abc':
  print('Yes')
else:
  print('No')
Problem p02609 (python)

Fixed submission:
N = int(input())
X = input()

def popcnt1(n):
    return bin(n).count("1")

k = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2,1] #18まで

c = 0
for i in range(N):
    if X[i] == "1":
        c += 1

m1 = 0
p1 = 0

for i in range(N):
    if c != 1:
        if X[i] == "1":
            m1 += pow(2,N-1-i,c-1)
            m1 %= c-1
            p1 += pow(2,N-1-i,c+1)
            p1 %= c+1
    else:
        if X[i] == "1":
            p1 += pow(2,N-1-i,c+1)
            p1 %= c+1

for i in range(N):
    if c != 1: 
        if X[i] == "0":
            B2 = p1 + pow(2,N-1-i,c+1)
            B2 %= c+1
        else:
            B2 = m1 - pow(2,N-1-i,c-1)
            B2 %= c-1
    else:
        if X[i] == "0":
            B2 = p1 + pow(2,N-1-i,c+1)
            B2 %= c+1
        else:
            print(0)
            continue

    S = len(bin(B2))
    c2 = popcnt1(B2)

    if c2 == 0:
        print(1)
    else:
        print(2+k[B2%c2])

Buggy submission (verdict: Runtime Error):
N = int(input())
X = input()

k = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2,1] #18まで
one = [0]*N

c = 0
for i in range(N):
    if X[i] == "1":
        c += 1
for i in range(N):
    if X[i] == "1":
        one[i] = c-1
    else:
        one[i] = c+1
#print(one)

b1 = bin_num = int(X, 2)

for i in range(N):
    if X[i] == "0":
        B1 = b1 + 2**(N-1-i)
    else:
        B1 = b1 - 2**(N-1-i)
    #print(B1)
    B2 = B1%one[i]
    x = format(B2, 'b')
    #print(x)
    S = len(str(x))

    c2 = 0
    for j in range(S):
        if x[j] == "1":
            c2 += 1

    if c2 == 0:
        print(1)
    else:
        print(2+k[B2%c2])

Buggy submission (verdict: Runtime Error):
N = int(input())
X = input()
S = len(str(X))

k = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2] #17まで

c = 0
for i in range(S):
    if X[i] == "1":
        c += 1

for i in range(S):
    if X[i] == "1":
        waru = c-1
    else:
        waru = c+1
    #print(waru)
    atai = 0
    for j in range(S):
        if i != j:
            atai += 2**(S-1-j)*int(X[j])
        else:
            atai += 2**(S-1-j)* ((int(X[j])+1)%2)

    nex = atai % waru
    print(1+k[nex])
Problem p02665 (python)

Fixed submission:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
A = list(map(int,(input().split())))
flag = 0

if N != 0:

    if A[0] != 0:
        flag = -1
    if A[-1] == 0:
        flag = -1

    S = [-1]*N
    S[0] = sum(A)
    for i in range(1,N):
        S[i] = S[i-1] - A[i]

    M = [-1]*N
    M[0] = 2
    for i in range(1,N):
        M[i] = (M[i-1]-A[i])*2
        if M[i] <= 0:
            flag = -1
    #print(S,M)

    if flag != -1:
        V = [-1]*N
        for i in range(N):
            if S[i] > M[i]:
                V[i] = M[i]
            else:
                V[i] = S[i]
        ans = sum(V)+1

        if S[-1] <= M[-1]:
            #print(V)
            print(ans)
        else:
            print(-1)
    else:
        print(-1)

else:
    if A[0] == 1:
        print(1)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
A = list(map(int,(input().split())))
flag = 0

if A[0] != 0:
    flag = -1
if A[-1] == 0:
    flag = -1

S = [-1]*N
S[0] = sum(A)
for i in range(1,N):
    S[i] = S[i-1] - A[i]

M = [-1]*N
M[0] = 2
for i in range(1,N):
    M[i] = (M[i-1]-A[i])*2
    if M[i] <= 0:
        flag = -1
#print(S,M)

if flag != -1:
    V = [-1]*N
    for i in range(N):
        if S[i] > M[i]:
            V[i] = M[i]
        else:
            V[i] = S[i]
    ans = sum(V)+1
    #print(V)
    print(ans)
else:
    print(-1)
Problem p02768 (python)

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

mod = 10**9+7

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

sum = pow(2,n,mod)
case = combination(n,a,mod) + combination(n,b,mod) + 1
ans = sum-case
while ans < 0 :
    ans += mod

print(ans)

Buggy submission (verdict: Runtime Error):
1000000000 141421 173205
Problem p02775 (python)

Fixed submission:
N=list(map(int,input()))
N.reverse()
N.append(0)
n=len(N)
pay=[0]*n
price = list(N)

for i in range (n):
    if N[i]>5:
        pay[i]=0
        N[i+1]=N[i+1]+1
    elif  N[i]<5:
        pay[i]=N[i]
    else:
        if N[i+1]>=5:
            pay[i]=0
            N[i+1]=N[i+1]+1
        else:
            pay[i]=N[i]


#print(price)
#print(pay)
sum_pay=sum(pay)

c=0
for i in range (n):
    if pay[i]-price[i]>=0:
        c=c+pay[i]-price[i]
    else:
        c=c+10+pay[i]-price[i]
        pay[i+1]=pay[i+1]-1

sum_otsuri=c

#print(sum_otsuri)
#print(sum_pay)

sum=sum_otsuri+sum_pay
print(sum)

Buggy submission (verdict: Runtime Error):
N=list(map(int,input()))
N.reverse()
N.append(0)
n=len(N)
pay=[0]*n
price = N.copy()

for i in range (n):
    if N[i]>5:
        pay[i]=0
        N[i+1]=N[i+1]+1
    elif  N[i]<5:
        pay[i]=N[i]
    else:
        if N[i+1]>=5:
            pay[i]=0
            N[i+1]=N[i+1]+1
        else:
            pay[i]=N[i]

sum_pay=sum(pay)

c=0
for i in range (n):
    if pay[i]-price[i]>=0:
        c=c+pay[i]-price[i]
    else:
        c=c+10+pay[i]-price[i]
        pay[i+1]=pay[i+1]-1

sum_otsuri=c

sum=sum_otsuri+sum_pay
print(sum)

Buggy submission (verdict: Runtime Error):
N=list(map(int,input()))
N.reverse()
N.append(0)
n=len(N)
pay=[0]*n
price = N.copy()

for i in range (n):
    if N[i]>5:
        pay[i]=0
        N[i+1]=N[i+1]+1
    elif  N[i]<5:
        pay[i]=N[i]
    else:
        if N[i+1]>=5:
            pay[i]=0
            N[i+1]=N[i+1]+1
        else:
            pay[i]=N[i]


#print(price)
#print(pay)
sum_pay=sum(pay)

c=0
for i in range (n):
    if pay[i]-price[i]>=0:
        c=c+pay[i]-price[i]
    else:
        c=c+10+pay[i]-price[i]
        pay[i+1]=pay[i+1]-1

sum_otsuri=c

#print(sum_otsuri)
#print(sum_pay)

sum=sum_otsuri+sum_pay
print(sum)

Buggy submission (verdict: Runtime Error):
N=list(map(int,input()))
N.reverse()
N.append(0)
n=len(N)
pay=[0]*n
price = N.copy()

for i in range (n):
    if N[i]>5:
        pay[i]=0
        N[i+1]=N[i+1]+1
    else:
        pay[i]=N[i]


#print(price)
#print(pay)
sum_pay=sum(pay)

c=0
for i in range (n):
    if pay[i]>=price[i]:
        c=c+pay[i]-price[i]
    else:
        c=c+10+pay[i]-price[i]
        if  pay[i+1]!=0:
            pay[i+1]=pay[i+1]-1
        else:
            pay[i+1]=9
            pay[i+1]=pay[i+1]-1

sum_otsuri=c

#print(sum_otsuri)
#print(sum_pay)

sum=sum_otsuri+sum_pay
print(sum)
Problem p02789 (python)

Fixed submission:
[M,N]=list(map(int, input().split()))
if M==N:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
[N]=list(map(int, input().split()))
A=list(map(int, input().split()))
c=0
for i in range (0,N):
    B=sorted(A[0:i+1],reverse=True)
    if B[i] == A[i]:
        c=c+1
print(c)
Problem p02850 (python)

Fixed submission:
from collections import deque

N = int(input())

g = [[] for _ in range(N)]
color = [[] for _ in range(N)]
mi = [[] for _ in range(N)]
MA = [[] for _ in range(N)]
edge = {}
ans = [0]*(N-1)
M = 0

for i in range(N-1):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
    ans[i] = (a,b)

stack = deque([0])
not_visit = [True]*N
not_visit[0] = False
while stack:
    now = stack.popleft()
    for i in g[now]:
        if not_visit[i]:
            stack.append(i)
            if not mi[now]:
                mi[now] = 1
                MA[now] = 1
                mi[i] = 1
                MA[i] = 1
                M = 1
                color[now].append(mi[now])
                color[i].append(mi[now])
                edge[(now+1,i+1)] = mi[now]
                edge[(i+1,now+1)] = mi[now]
            else:
                if mi[now] != 1:
                    mi[now] -= 1
                    color[now].append(mi[now])
                    color[i].append(mi[now])
                    edge[(now+1,i+1)] = mi[now]
                    edge[(i+1,now+1)] = mi[now]
                    if mi[i]:
                        mi[i] = min(mi[i],mi[now])
                    else:
                        mi[i] = mi[now]
                        MA[i] = mi[now]
                else:
                    MA[now] += 1
                    color[now].append(MA[now])
                    color[i].append(MA[now])
                    edge[(now+1,i+1)] = MA[now]
                    edge[(i+1,now+1)] = MA[now]
                    M = max(M,MA[now])
                    if MA[i]:
                        MA[i] = max(MA[i],MA[now])
                    else:
                        MA[i] = MA[now]
                        mi[i] = MA[now]

            not_visit[i] = False

print(M)
for i in range(N-1):
    print(edge[ans[i]])

Buggy submission (verdict: Runtime Error):
import heapq

N = int(input())

color = [[] for _ in range(N)]
ans = [None]*(N-1)


for i in range(N):
    heapq.heapify(color[i])

for i in range(N-1):
    a,b = map(int,input().split())
    
    if i == 0:
        color[a-1].append(1)
        color[b-1].append(1)
        ans[i] = 1

    else:
        if color[a-1]:
            if color[a-1][0] != 1:
                mim = heapq.heappop(color[a-1])
                heapq.heappush(color[a-1],mim)
                heapq.heappush(color[a-1],mim-1)
                heapq.heappush(color[b-1],mim-1)
                ans[i] = mim-1
            else:
                nax = color[a-1][-1]
                heapq.heappush(color[a-1],nax+1)
                heapq.heappush(color[b-1],nax+1)
                ans[i] = nax+1
        else:
            if color[b-1][0]!= 1:
                mim = heapq.heappop(color[b-1])
                heapq.heappush(color[b-1],mim)
                heapq.heappush(color[b-1],mim-1)
                heapq.heappush(color[a-1],mim-1)
                ans[i] = mim-1
            else:
                nax = color[b-1][-1]
                heapq.heappush(color[b-1],nax+1)
                heapq.heappush(color[a-1],nax+1)
                ans[i] = nax+1

print(max(ans))
for i in range(N-1):
    print(ans[i])
Problem p02923 (python)

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

for i in range (N-1):
    gap[i] = H[i]-H[i+1]

c = 0
for i in range (N-1):
    if gap[i] >= 0:
        c += 1
        if i == N-2:
            M.append(c)
    else:
        M.append(c)
        c = 0

if N == 1:
    print(0)
else:
    print(max(M))

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

for i in range (N-1):
    gap[i] = H[i]-H[i+1]

c = 0
for i in range (N-1):
    if gap[i] >= 0:
        c += 1
        if i == N-2:
            M.append(c)
    else:
        M.append(c)
        c = 0

if N == 1:
    M = 0
    
print(max(M))

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

for i in range (N-1):
    gap[i] = H[i]-H[i+1]

c = 0
for i in range (N-1):
    if gap[i] >= 0:
        c += 1
        if i == N-2:
            M.append(c)
    else:
        M.append(c)
        c = 0

print(max(M))
Problem p02983 (python)

Fixed submission:
L,R = map(int,input().split())

if R - L >= 2018:
    print(0)
else:
    min = 2020
    for i in range(L,R):
        for j in range(i+1,R+1):
            mod = i * j % 2019
            if mod <= min:
                min = mod
    print(min)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())

if R - L >= 2018:
    print(0)
else:
    m = 2020
    for i in range(L,R):
        for j in range(i+1,R+1):
            mod = i * j % 2019
            if mod <= m:
                m = mod

print(m)
Problem p03032 (python)

Fixed submission:
N,K = map(int,(input().split()))
V = list(map(int,(input().split())))
left = [0]*(N+1)
right = [0]*(N+1)
ans = []

for i in range(1,N+1):
    left[i] = left[i-1] + V[i-1]

for i in range(1,N+1):
    right[i] = right[i-1] + V[N-i]


for i in range(min(N+1,K+1)):
    negal = []

    l = i
    for count in range(l):
        if l > 0 and V[count] < 0:
            negal.append(V[count])

    for j in range(min(N+1-i,K+1-i)):
        negar = []

        r = j
        for count in range(1,r+1):
            if r > 0 and V[N-count] < 0:
                negar.append(V[N-count])

        b = max(0,K-i-j)
        now = left[i] + right[j]

        nega = []
        nega.extend(negal)
        nega.extend(negar)
        nega.sort()
        s = 0
        for k in range(min(b,len(nega))):
            s += nega[k]
        
        if nega:
            ans.append(now-s)
        else:
            ans.append(now)

print(max(ans))

Buggy submission (verdict: Runtime Error):
N,K = map(int,(input().split()))
V = list(map(int,(input().split())))
left = [0]*(N+1)
right = [0]*(N+1)
ans = []

for i in range(1,N+1):
    left[i] = left[i-1] + V[i-1]

for i in range(1,N+1):
    right[i] = right[i-1] + V[N-i]

for i in range(K+1):
    nega = []

    l = i
    for count in range(l):
        if l > 0 and V[count] < 0:
            nega.append(V[count])

    for j in range(K+1-i):

        r = j
        for count in range(1,r+1):
            if r > 0 and V[N-count] < 0:
                nega.append(V[N-count])

        b = K-i-j
        now = left[i] + right[j]
        nega.sort()
        s = 0
        for k in range(min(b,len(nega))):
            s += nega[k]
        
        if nega:
            ans.append(now-s)
        else:
            ans.append(now)

print(max(ans))

Buggy submission (verdict: Runtime Error):
N,K = map(int,(input().split()))
V = list(map(int,(input().split())))
left = [0]*(N+1)
right = [0]*(N+1)
ans = []

for i in range(1,N+1):
    left[i] = left[i-1] + V[i-1]

for i in range(1,N+1):
    right[i] = right[i-1] + V[N-i]

for i in range(K+1):
    nega = []

    l = i
    for count in range(l):
        if l > 0 and V[count] < 0:
            nega.append(V[count])

    for j in range(K+1-i):

        r = j
        for count in range(1,r+1):
            if r > 0 and V[N-count] < 0:
                nega.append(V[N-count])

        b = K-i-j
        now = left[i] + right[j]
        nega.sort()
        s = 0
        for k in range(min(b,len(nega))):
            s += nega[k]
 
        ans.append(now-s)

print(max(ans))
Problem p03044 (python)

Fixed submission:
N = int(input())
g = [[[]for i in range(2)] for j in range(N)]

for i in range(N-1):
    u,v,d = map(int,input().split())
    if d%2 == 0:
        g[u-1][0].append(v-1)
        g[v-1][0].append(u-1)
    else:
        g[u-1][1].append(v-1)
        g[v-1][1].append(u-1)

ans = [-1]*N
ans[0] = 0

stack = [0]
not_visit = [True for i in range(N)]
not_visit[0] = False

while stack:
    now = stack.pop()
    for h in range(2):
        if h == 0: #距離が偶数ならば
            for i in range(len(g[now][h])):
                if not_visit[g[now][h][i]]:
                    not_visit[g[now][h][i]] = False
                    ans[g[now][h][i]] = ans[now]
                    stack.append(g[now][h][i])
        if h == 1: #距離が奇数ならば
            for i in range(len(g[now][h])):
                if not_visit[g[now][h][i]]:
                    not_visit[g[now][h][i]] = False
                    ans[g[now][h][i]] = (ans[now] + 1)%2
                    stack.append(g[now][h][i])

for i in range(N):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
g = [[[]for i in range(2)] for j in range(N)]

for i in range(N-1):
    u,v,d = map(int,input().split())
    if d%2 == 0:
        g[u-1][0].append(v-1)
        g[v-1][0].append(u-1)
    else:
        g[u-1][1].append(v-1)
        g[v-1][1].append(u-1)

ans = [-1]*N
ans[0] = 0

stack = [0]
not_visit = [True for i in range(N)]
not_visit[0] = False

while stack:
    now = stack.pop()
    for h in range(2):
        for i in range(len(g[now][h])):
            if not_visit[g[now][h][i]]: #距離が偶数ならば
                not_visit[g[now][0][i]] = False
                ans[g[now][0][i]] = ans[now]
                stack.append(g[now][0][i])
        for i in range(len(g[now][h])):
            if not_visit[g[now][h][i]]: #距離が奇数ならば
                not_visit[g[now][1][i]] = False
                ans[g[now][1][i]] = (ans[now] + 1)%2
                stack.append(g[now][1][i])

for i in range(N):
    print(ans[i])
Problem p03087 (python)

Fixed submission:
import bisect

N,Q = map(int,(input().split()))
S = list(input())

l = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)

for i in range(Q):
    a,b = map(int,(input().split()))
    print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))

Buggy submission (verdict: Runtime Error):
import bisect

N,Q = map(int,(input().split()))
S = list(input())

l = []
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)
s = 0
for i in range(Q):
    a,b = map(int,(input().split()))
    if l:
        print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import bisect

N,Q = map(int,(input().split()))
S = list(input())

l = []
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)
s = 0
for i in range(Q):
    a,b = map(int,(input().split()))
    print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))
Problem p03161 (python)

Fixed submission:
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

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

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

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

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:j+1])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])
Problem p03263 (python)

Fixed submission:
H,W = map(int,(input().split()))
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int,(input().split())))

ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] %2 == 1:
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(H-1):
    if a[i][W-1] %2 == 1:
        a[i+1][W-1] += 1
        ans.append([i+1,W,i+2,W])

print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Buggy submission (verdict: Runtime Error):
H,W = map(int,(input().split()))
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int,(input().split())))

ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] %2 == 1:
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(H-1):
    if a[i][W-1] %2 == 1:
        a[i+1][W-1] += 1
        ans.append(i+1,W,i+2,W)

print(len(ans))
for i in range(len(ans)):
    print(*ans[i])
Problem p03288 (python)

Fixed submission:
R = int(input())
if R < 1200:
    print("ABC")
elif R < 2800:
    print("ARC")
else:
    print("AGC")

Buggy submission (verdict: Runtime Error):
R = int(input())
if R < 1200:
    print("ABC")
elif: R < 2800:
    print("ARC")
else:
    print("AGC")
Problem p03319 (python)

Fixed submission:
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
print(math.ceil((N-1)/(K-1)))

Buggy submission (verdict: Runtime Error):
N = int(input())
def su(n):
    s = 0
    for i in range(1,n+1):
        s += i
    return s

if N == 1:
    print(1)

else:
    for i in range(N):
        if su(i) >= N:
            M = i
            break
    print(M)

    now = N-M
    
    for i in range(1,M):
        if now - (M-i) >=(M-i):
            now -= M-i
            print(M-i)
        else:
            print(M-i)
            print(now-(M-i))
            break