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

Fixed submission:
### coding: UTF-8
 
#import math
#import random as rd
#import numpy as np
 
 
n=int(input())
line=list(map(int,input().split( )))
 
line=sorted(line)
 
#print(line)
 
s=sum([line[-(i+1)] for i in range(n) if i%2==0])-sum([line[-(i+1)] for i in range(n) if i%2!=0])
 
print(s)

Buggy submission (verdict: Runtime Error):
スコード
Copy
### coding: UTF-8
 
#import math
#import random as rd
#import numpy as np
 
 
n=int(input())
line=list(map(int,input().split( )))
 
line=sorted(line)
 
#print(line)
 
s=sum([line[-(i+1)] for i in range(n) if i%2==0])-sum([line[-(i+1)] for i in range(n) if i%2!=0])
 
print(s)
Problem p03471 (python)

Fixed submission:

n,y=map(int,input().split( ))
 
flag=True

def fcn():
    for i in range(n+1):
        for j in range(n-i+1):
            if y==10000*i+5000*j+1000*(n-i-j):
                return [i,j,n-i-j]
    return [-1,-1,-1]

print(' '.join(list(map(str,fcn()))))

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split( ))
 
flag=True
 n,y=map(int,input().split( ))
 
flag=True
 
for i in range(n+1):
    for j in range(n-i+1):
        x=y-10000*i-5000*j
        if x/1000 == n-i-j:
            flag = False
            print(str(i)+' '+str(j)+' '+str(n-i-j-2))
        break
    if not flag:
        break
 
 
if flag:
    print('-1 -1 -1')
Problem p02576 (python)

Fixed submission:
def solve(n, x, t):
    return (n + x - 1) // x * t

n, x, t = map(int, input().split())
print(solve(n, x, t))

Buggy submission (verdict: Runtime Error):
n = input()
n = int(n)
x = input()
x = int(x)
t = input()
t = int(t)

if x == 1:
    count = n
else:
    count = n//x
    if n%x == 0:
        pass
    else:
        count = count + 1

print(t*count)

Buggy submission (verdict: Runtime Error):
n=input()
n = int(n)
x=input()
x = int(x)
t=input()
t=int(t)
if x == 1:
    count = n
else:
    count = n//x 
    if n%x == 0:
        pass
    else:
        count = count + 1

print(t*count)

Buggy submission (verdict: Runtime Error):
n=input()
n = int(n)
x=input()
x = int(x)
t=input()
t=int(t)
if x == 1:
    count = n
else:
    count = n//x 
    if n%x == 0:
        pass
    else:
        count = count + 1

print(t*count)

Buggy submission (verdict: Runtime Error):
n=input()
n = int(n)
x=input()
x = int(x)
t=input()
t=int(t)
if x == 1:
    count = n
else:
    count = n//x 
    if n%x == 0:
        pass
    else:
        count = count + 1

print(t*count)

Buggy submission (verdict: Runtime Error):
n=input()
n = int(n)
x=input()
x = int(x)
t=input()
t=int(t)
if x == 1:
    count = n
else:
    count = n//x 
    if n%x == 0:
        pass
    else:
    　　count = count + 1

print(t*count)

Buggy submission (verdict: Runtime Error):
n=input()
n = int(n)
x=input()
x = int(x)
t=input()
t=int(t)
if x == 1:
    count = n
else:
    count = n//x 
    if n%x == 0:
        pass
    else:
     count = count + 1

print(t*count)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
def kake(b,c):
    return b * c

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

A = 1
for i in range(n):
    kake(A,a[i])

if A>1000000000000000000:
        print(-1)
else:
    print(A)
Problem p02555 (python)

Fixed submission:
from math import factorial
S=int(input())
ans=0
for i in range(S // 3):
  ans+=factorial(S-2*i-3)//factorial(i)//factorial(S-3*i-3)
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
S=int(input())
ans=0
for i in range(S // 3):
  ans+=(math.factorial(S-2*i)%1000000007)//((math.factorial(i)%1000000007)*(math.factorial(S-3*i))%1000000007)%1000000007
print(ans%1000000007)
Problem p02742 (python)

Fixed submission:
a,b = map(int,input().split())
ans = 0
if a == 1 or b == 1:
  print(1)
elif a*b % 2 == 0:
  print(int(a*b/2))
else:
  print(int((a*b-1)/2 + 1))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())
ans = 0
if a*b % 2 == 0:
  print(a*b/2)
else:
  print((a*b-1)/2 + 1)
Problem p03434 (python)

Fixed submission:
input()
l = list(map(int,input().split()))
list.sort(l,reverse=True)
ans = 0
for i in range(len(l)):
  if i % 2 == 0:
    ans += l[i]
  else:
    ans -= l[i]
print(ans)

Buggy submission (verdict: Runtime Error):
input()
l = list(map(int,input().split()))
l.sort(reverse　=　True)
ans = 0
for i in range(len(l)):
  if i % == 0:
    ans += l[i]
  else:
    ans -= l[i]
print(ans)
Problem p02582 (python)

Fixed submission:
s = input()
print("3" if "RRR" in s else "2" if "RR" in s else "1" if "R" in s else "0" )

Buggy submission (verdict: Runtime Error):
s = input()
print("3" if "RRR" in s else "2" if "RR" in s else "1" "R" in s else "0" )
Problem p02613 (python)

Fixed submission:
N = int(input())
a = [input() for i in range(N)]
c0 = a.count("AC")
c1 = a.count("WA")
c2 = a.count("TLE")
c3 = a.count("RE")
print("AC x", c0)
print("WA x", c1)
print("TLE x", c2)
print("RE x", c3)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [input() for i in range(N)]
c0 = a.count("AC")
c1 = a.count("WA")
c2 = a.count("TLE")
c3 = a.count("RE")
print("AC × " + c0)
print("WA × " + c1)
print("TLE × " + c2)
print("RE × " + c3)
Problem p02700 (python)

Fixed submission:
A, B, C, D = map(int, input().split())
print("Yes" if (A+D-1)//D >= (C+B-1)//B else "No")

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
if C/B <= A/D || C/B <= 1:
	print("Yes")
else:    
	print("No")

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
if C/B <= A/D || C/B <= 1:
	print("Yes")
else:    
	print("No")
Problem p02730 (python)

Fixed submission:
s = input()
l = len(s)
a = s[0:(l-1)//2]
b = len(a)
print("Yes" if s == s[::-1] and a == a[::-1] else "No")

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
a = s[:(l-1)/2]
b = len(a)
print("Yes" if s[:(l-1)/2] == s[(l+1)/2:] and a[:(b-1)/2] == a[(b+1)/2:] else "No")
Problem p02778 (python)

Fixed submission:
S = input()
print("x" * len(S))

Buggy submission (verdict: Runtime Error):
S = input()
print("x"*count(S))

Buggy submission (verdict: Runtime Error):
S = input()
print("x"*S.count())
Problem p02812 (python)

Fixed submission:
a = input()
s = input()
print(s.count("ABC"))

Buggy submission (verdict: Runtime Error):
a = input()
s = input()
print(s.count("ABC")
Problem p02817 (python)

Fixed submission:
A, B = input().split()
print(B + A)

Buggy submission (verdict: Runtime Error):
A, B = map(input().split())
print(B + A)
Problem p02898 (python)

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
total=0
for i in h:
  if i >= K:
    total+=1
print(total)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = list(map(int, input().split()))
for i in h:
  if i > K:
    total+=1
print(total)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
h[] = map(int, input().split())
for i in h:
  if i > K:
    total+=1
print(total)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
h[] = int(input().split())
for i in h:
  if i > K:
    total+=1
print(total)
Problem p02922 (python)

Fixed submission:
A, B = map(int, input().split())
import math
c = math.ceil((B - A) / (A - 1))
print(c + 1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
import math
c = math.ceil((B - A) / (B - 1))
print(c + 1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
import math
c = math.ceil((B - A) / (B - 1))
print(c + 1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
c = math.ceil((B - A) / (B - 1))
print(c + 1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(math.ceil((B - A) / (B - 1)) + 1)
Problem p03085 (python)

Fixed submission:
b = input()
print("A" if b=="T" else "T" if b=="A" else "G" if b=="C" else "C")

Buggy submission (verdict: Runtime Error):
b = input()
print("A" if b==T else "T" if b==A else "G" if b==C else "C")
Problem p03109 (python)

Fixed submission:
S = input()
print("TBD" if S[6]>="5" or S[5]>="1" else "Heisei")

Buggy submission (verdict: Runtime Error):
S = input()
print("TBD" if S[6]>=5 or S[5]>=1 else "Heisei")
Problem p03210 (python)

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

Buggy submission (verdict: Runtime Error):
a = int(input())
if a == 3 | a == 5 | a == 7:
  print('YES')
else:
  Print('NO')
Problem p03377 (python)

Fixed submission:
A, B, C = map(int, input().split())
print("YES" if (A<=C and A+B>=C) else "NO")

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print("YES" if (A<=C && B>=C) else "NO")

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print("YES" if A<=C && B>=C else "NO")
Problem p03415 (python)

Fixed submission:
A=input()
B = input()
C = input()
print(A[0] + B[1] + C[2])

Buggy submission (verdict: Runtime Error):
for i in range(3)
	A[i] = input()
print(A[0][0] + A[1][1] + A[2][2])

Buggy submission (verdict: Runtime Error):
for i in range(3)
	A[i] = input()
print(A[0][0] + B[1][1] + C[2][2])

Buggy submission (verdict: Runtime Error):
for i in range(3)
	A, B, C = input()
print(A[0] + B[1] + C[2])

Buggy submission (verdict: Runtime Error):
A, B, C = input() for i in range(3)
print(A[0] + B[1] + C[2])
Problem p03474 (python)

Fixed submission:
a, b = map(int, input().split())
s = input()
print("Yes" if s.count("-") == 1 and s[a] == "-" else "No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
s = input()
print("Yes" if (s.count("-") == 1 and s[a] == "-" and s.count() == a+b+1) else "No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
s = input()
print("Yes" if s.count("-") == 1 and s[a] == "-" and s.count() == a+b+1 else "No")
Problem p03477 (python)

Fixed submission:
A, B, C, D = map(int, input().split())
print("Right" if (A+B) < (C+D) else "Balanced" if (A+B) == (C+D) else "Left")

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input())
print("Right" if (A+B) < (C+D) else "Balanced" if (A+B) == (C+D) else "Left")
Problem p03485 (python)

Fixed submission:
a, b = map(int, input().split())
import math
print(math.ceil((a + b) / 2))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
import math
print(math.ceil((a + b) / 2))
Problem p03543 (python)

Fixed submission:
a, b, c, d, = input()
print("Yes" if a==b==c or b==c==d else "No")

Buggy submission (verdict: Runtime Error):
n = input()
print("Yes" if ["111", "222", "333", "444", "555", "666", "777", "888", "999", "000"] in n else "No")
Problem p03573 (python)

Fixed submission:
a, b, c = map(int, input().split())
print(a if b == c else b if a == c else c)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(a if b == c else b if a == c else c if a == b)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(a if a not in [b, c] else b if b not in [a, c] else c if c not in [a, b])
Problem p03671 (python)

Fixed submission:
a, b, c = sorted(map(int, input().split()))
print(a+b)

Buggy submission (verdict: Runtime Error):
a, b, c = sorted(map(int, input().split()))
print(a+b0
Problem p03738 (python)

Fixed submission:
A = int(input())
B = int(input())
print("GREATER" if A>B else "EQUAL" if A==B else "LESS")

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print("GREATER" if A>B else "EQOUL" if A=B else "LESS")

Buggy submission (verdict: Runtime Error):
A, B = (int(input()) for i in range(2))
print("GREATER" if A>B else "EQOUL" if A=B else "LESS")

Buggy submission (verdict: Runtime Error):
A, B = int(input()) for i in range(2)
print("GREATER" if A>B else "EQOUL" if A=B else "LESS")
Problem p03773 (python)

Fixed submission:
A, B = map(int, input().split())
print((A+B) % 24)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())
print((A+B) % 24)
Problem p03852 (python)

Fixed submission:
c = input()
vowel = ["a", "i", "u", "e", "o"]
print("vowel" if c in vowel else "consonant")

Buggy submission (verdict: Runtime Error):
c = input()
vowel = [a, i, u, e, o]
print("vowel" if c in vowel else "consonant")
Problem p03943 (python)

Fixed submission:
a, b, c = sorted(map(int, input().split()))
print("Yes" if a+b == c else "No")

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

b = a.sort()
print(b)
print("Yes" if b[0]+b[1] == b[2] else "No")
Problem p03962 (python)

Fixed submission:
s = list(input().split())
print(len(set(s)))

Buggy submission (verdict: Runtime Error):
s = list(input().split())
print(len(set(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
print(len(set(s))

Buggy submission (verdict: Runtime Error):
s = list(input().split())
print(len(set(s))
Problem p02713 (python)

Fixed submission:
import math
k=int(input())
l=[]
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    l.append(math.gcd(x,y))

for x in range(len(l)):
  for y in range(1,k+1):
    s+=math.gcd(l[x],y)
print(s)

Buggy submission (verdict: Runtime Error):
import math
k=input()
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    for z in range(1,k+1):
      s+=math.gcd(x,gcd(y,z))
print(s)

Buggy submission (verdict: Runtime Error):
import numpy as np
k=int(input())
s=0
n=range(k+1)
for x,y,z in n:
	s+=np.gcd.reduce([x,y,z])
print(s)
Problem p02741 (python)

Fixed submission:
import sys
i = int(sys.stdin.readline())
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(n[i-1])

Buggy submission (verdict: Runtime Error):
import math
H,W = input().split()
H=int(H)
W=int(W)
if H%2==0:
  ans=(H*W)/2
else:
  ans=((H-1)*W/2)+math.ceil(W/2)
  
print('{:.19g}'.format(ans))
Problem p04045 (python)

Fixed submission:
N, K = [int(x) for x in input().split()]
dislikes = [False] * 10
dislike_nums = [int(x) for x in input().split()]
for x in dislike_nums:
    dislikes[x] = True

for n in range(N, N * 10):
    found = False
    for x in str(n):
        if dislikes[int(x)]:
            found = True
            break
    if not found:
        break
print(n)

Buggy submission (verdict: Runtime Error):
N, L = [int(x) for x in input().split()]
S = []
for s in range(N):
    S.append(input())
print("".join(sorted(S)))

# %% [markdown]
#
# C
#

# %%
N, K = [int(x) for x in input().split()]
dislikes = [False] * 10
dislike_nums = [int(x) for x in input().split()]
for n in dislike_nums:
    dislikes[n] = True

# Add '0' in the beginning of N for carrying up
N = "0" + str(N)

# Create a list of numbers consists N
n_list = []
for n in N:
    n_list.append(int(n))
# Create a list of carrying up numbers
c_list = [0] * len(n_list)

# Create the smallest payment
payment = ""
for i in range(len(n_list) - 1, -1, -1):
    n = n_list[i] + c_list[i]
    if i == 0 and n == 0:
        break
    # Find an equal or larger number than n and not in dislikes
    x = -1
    for m in range(n, 10):
        if not dislikes[m]:
            x = m
            break
    if x >= 0:
        # found a number
        payment = str(m) + payment
        continue

    # Carry a number to the previous (x10) digit
    if i > 0:
        c_list[i - 1] += 1

    # Find a smaller number than n and not in dislikes
    for m in range(0, n):
        if not dislikes[m]:
            payment = str(m) + payment
            break
print(int(payment))
Problem p02952 (python)

Fixed submission:
n = int(input())
if n <= 9:
    print(n)
elif n <= 99:
    print(9)
elif n <= 999:
    print(9 + n - 99)
elif n <= 9999:
    print(909)
elif n <= 99999:
    print(909 + n - 9999 )
else:
    print(90909)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n <= 9:
    print(x)
elif n <= 99:
    print(9)
elif n <= 999:
    print(9 + n - 99)
elif n <= 9999:
    print(909)
elif n <= 99999:
    print(909 + n - 9999 )
else:
    print(90909)
Problem p02953 (python)

Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]

if n == 1:
    print('Yes')
else:
    cnt = 0
    for i in range(1,n):
        if h[n-i] - h[n-i-1] <= -2:
            cnt = 1
            break
        elif h[n-i] - h[n-i-1] == -1:
            h[n-i-1]  -= 1

    if cnt == 0:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(i) for i in input().split()]

if n == 1:
    print('Yes')
else:
    cnt = 0
    for i in range(1,n):
        if h[n-i] - h[n-i-1] <= -2:
            cnt = 1
            break
        elif h[n-i] - h[n-i-1] == -1:
            h[n-i-1]  -= 1

if cnt == 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(i) for i in input().split()]
if n == 1:
    print('Yes')
else:
    cnt = 0
    for i in range(1,n,-1):
        if h[i] - h[i-1] <= -2:
            cnt = 1
            break
        elif h[i] - h[i-1] == -1:
            h[i-1]  -= 1

if cnt == 0:
    print('Yes')
else:
    print('No')
Problem p03060 (python)

Fixed submission:
n = int(input())
v = [int(i) for i in input().split()]
c = [int(j) for j in input().split()]

x = []
 
for i in range(n):
    x.append(int(v[i]-c[i]))
 
x.sort()
 
y = 0
 
i = n-1
 
while x[i] >= 0 and i >= 0 :
    y += x[i]
    i += -1
 
print(y)

Buggy submission (verdict: Runtime Error):
x = []

for i in range(n):
    x.append(int(v[i]-c[i]))

x.sort()

y = 0

i = n-1

while x[i] >= 0 and i >= 0 :
    y += x[i]
    i += -1

print(y)
Problem p03068 (python)

Fixed submission:
n = int(input())
s = input()
k = int(input())
 
a = ""
 
for i in range(n):
  if s[i] == s[k-1]:
    a = a + s[k-1]
  else:
    a = a + "*" 
print(a)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
k = int(input())
 
a = []
 
for i in range(n):
  if s[i] == s[k]:
    a.append(s[k])
  else:
    a.append("*")
 
print(a)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
k = int(input())

a = []

for i in range(n):
  if s[i] == s[k]:
    a.append(s[k])
  else:
    a.append("*")

print(a)
Problem p03146 (python)

Fixed submission:
s = int(input())
a = [s]
i = 1
while True :
    if a[i-1] % 2 == 0:
        t = int((a[i-1])/2)
    else:
        t = int((a[i-1])*3+1)
        
    i +=1 
    
    if t in a:
        print(i)
        break  
    a.append(t)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [int(i) for i in input().split()]
if 2 * max(l) - sum(l) < 0:
    print("Yes")
else:
    print("No")
Problem p03206 (python)

Fixed submission:
d = int(input())
 
if d == 25:
    print("Christmas")
elif d == 24:
    print("Christmas Eve")
elif d == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
d = int(input())

if d == 25:
    pritn("Christmas")
elif d == 24:
    print("hristmas Eve")
elif d == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")
Problem p03385 (python)

Fixed submission:
s = str(input())
if "a" in s and "b" in s and "c" in s:
    print("Yes")
else:
    print("No")

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

if a >= x and a+b <=x:
    print("YES")
else:
    print("NO")
Problem p03407 (python)

Fixed submission:
a,b,c = map(int,input().split())
if a + b >= c:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
x = [int(input()) for i in range(4)]
print(min(x[0],x[1]) + min(x[2],x[3]))
Problem p03544 (python)

Fixed submission:
n = int(input())
l = [2,1]

if n == 1:
    print(1)

else:
    for i in range(2,n+1):
        l.append(int(l[i-1] +l[i-2]))
    print(l[n])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [2,1]

if n == 1:
    print(1)

else:
    for i in range(2,n+1):
        l.append(int(l[i-1] +l[i-2]))
	print(l[n])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [2,1]

if n == 1:
    print(1)

else:
    for i in range(2,n+1):
        l.append(int(l[i-1] +l[i-2]))
	print(l[n])
Problem p03814 (python)

Fixed submission:
s = str(input())

a = 199999
z = 0

for i in range(len(s)):
    if s[i] == "A":
        a = min(a,i)

    elif s[i]  == "Z":
        z = max(z,i)

print(z - a + 1)

Buggy submission (verdict: Runtime Error):
s = str(input())

a = 0
z = 0

for i in range(len(s)):
    if s[i] = "A":
        a = min(a,i)

    elif s[i]  = "Z":
        z = max(z,i)

print(z - a + 1)
Problem p02584 (python)

Fixed submission:
first_place, K, Distance = map(int, input().split())
first_place = abs(first_place)
test = first_place
if first_place - Distance*K > 0:
    print(first_place -Distance*K)
else:
    for i in range(1,K+1):
        test -= Distance
        if test <= 0:
            a = i
            #print(a)
            break
    if (K-a)%2 == 0 or K-a == 0:
        print(abs(first_place - Distance*a))
    else:
        print(abs(first_place - Distance*(a-1)))

Buggy submission (verdict: Runtime Error):
Coodinate, K, Distance = map(int, input().split())

dp = [0]*(K+1)
dp[0] = Coodinate
#dp[1] = min( abs(dp[0]+Coodinate), abs(dp[0]-coodinate) )
count = 0
for i in range(1,K+1):
    dp[i] = min( abs(dp[i-1]+Distance), abs(dp[i-1]-Distance) )
    #if dp.count(dp[i]) == 2:
    #    break
    #else:
    #    count += 1
#print(count)
#print(dp)
print(dp[K])
Problem p03161 (python)

Fixed submission:
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [0 for i in range(number)]
res[1] = abs(scaffolding[1]-scaffolding[0])
#test = [math.inf for k in range(jump)]
#test[0] = 0

for i in range(2, number):
    h=max(0,i-jump)
    res[i]=min(res[k]+abs(scaffolding[i]-scaffolding[k]) for k in range(h,i))   
    #res[i] = min(test)
    

print(res[number-1])

Buggy submission (verdict: Runtime Error):
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [math.inf * number]
res[0] =0 
test = [math.inf * number]
test[0] = 0

for i in range(number):
    for j in range(1,jump+1):
        if i-j < 0:break
        cost = abs(scaffolding[i]-scaffolding[i-j])
        test[j-1] = res[i-j] + cost
    
    res[i] = min(test)
    

print(res[number-1])
Problem p03163 (python)

Fixed submission:
import sys
 
input = sys.stdin.readline
 
 
def main():
    N, W = map(int, input().split())
    wv = [None] * N
    for i in range(N):
        wv[i] = tuple(map(int, input().split()))
 
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i, (w, v) in enumerate(wv, start=1):
        dp_i = dp[i]
        dp_im = dp[i - 1]
        for j in range(1, W + 1):
            if j < w:
                dp_i[j] = dp_im[j]
            else:
                a = dp_im[j - w] + v
                b = dp_im[j]
                if a > b:
                    dp_i[j] = a
                else:
                    dp_i[j] = b
 
    ans = dp[-1][-1]
    print(ans)
 
 
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input =sys.stdin.readline 
number, weight = input().rstrip().split()
number = int(number)
weight = int(weight)

items = (tuple(map(int,input().rstrip().split())) for _ in range(number))
dp = [[0]*(weight+1) for _ in range(number+1)]

for i in range(number):
    for j in range(weight+1):
        if j < items[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-items[i][0]] + items[i][1])

print(dp[number][weight])