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

Fixed submission:
##E
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

psum = 0

for i in range(X):
        r.append(p[i])
for i in range(Y):
        r.append(q[i])
        
r.sort(reverse=True)
ans = 0

for i in range(X+Y):
		ans += r[i]

        
print(ans)

Buggy submission (verdict: Runtime Error):
##E
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

psum = 0
plist = []

for i in range(X):
        plist.append(p[i])
for i in range(Y):
        plist.append(q[i])
        
plist.sort()
        
for i in range(C):
    if r[i] > plist[0]:
        plist.pop(i)
        plist.append(r[i])
    else:
        break
        
print(sum(plist))

Buggy submission (verdict: Runtime Error):
##E
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

psum = 0
plist = []

for i in range(X):
        plist.append(p[i])
for i in range(Y):
        plist.append(q[i])
        
plist.sort()
        
for i in range(C):
    if r[i] > plist[0]:
        plist.pop(i)
        plist.append(r[i])
        
print(sum(plist))

Buggy submission (verdict: Runtime Error):
##E
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

psum = 0

for i in range(X):
    if p[i] > r[0]:
        psum += p[i]
    else:
        psum += rsort[0]
        r.pop(0)
for i in range(Y):
    if q[i] > r[0]:
        psum += q[i]
    else:
        psum += r[0]
        r.pop(0)
print(psum)
Problem p02802 (python)

Fixed submission:
n,m = map(int,input().split())
a = [input().split() for i in range(m)]
p = [int(i[0]) for i in a]
q = [j[1] for j in a]

ac = 0
wa = 0
wa_c = [0]*n
ac_c = [False]*n

for t in range(m):
    if ac_c[p[t]-1]:
        continue
    if q[t] == "AC":
        ac += 1
        ac_c[p[t]-1] = True
        wa += wa_c[p[t]-1]
    else:
        wa_c[p[t]-1] += 1
print(ac,wa)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = [input().split() for i in rabge(m)]
p = [int(i[0]) for i in a]
q = [j[1] for j in a]

ac = 0
wa = 0
wa_c = [0]*n
ac_c = [False]*n

for t in range(m):
    if ac_c[p[t]-1]:
        continue
    if q[t] == "AC":
        ac += 1
        ac_c[p[t]-1] = True
        wa += wa_c[p[t]-1]
    else:
        wa_c[p[t]-1] += 1
print(ac,wa)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
p = [0]*M
s = [a]*M
for i in range(M):
    p[i],s[i] = map(str,input().split())
pans = 0
sans = 0

for j in range(N):
    for k,val in enumerate(p):
        if val == str(j+1) and s[k] == "WA":
            sans += 1
        elif val == str(j+1) and s[k] == "AC":
            pans += 1
            break
print(pans,sans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
p = [0]*M
s = [a]*M
for i in range(M):
    p[i],s[i] = map(str,input().split())
pans = 0
sans = 0

for j in range(N):
    for k,val in enumerate(p):
        if val == str(j+1) and s[k] == "WA":
            sans += 1
        elif val == str(j+1) and s[k] == "AC":
            pans += 1
            break
print(int(pans),int(sans))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
p = [0]*M
s = [a]*M
for i in range(M):
    p[i],s[i] = map(str,input().split())
pans = 0
sans = 0

for j in range(N):
    for k,val in enumerate(p):
        if val == str(j+1) and s[k] == "WA":
            sans += 1
        elif val == str(j+1) and s[k] == "AC":
            pans += 1
            break
print(pans,sans)
Problem p02817 (python)

Fixed submission:
##149
##A
S,T = map(str,input().split())

print(T+S)

Buggy submission (verdict: Runtime Error):
##149
##A
S = input()
T = input()

print(T+S)
Problem p02882 (python)

Fixed submission:
##D
a,b,x = map(int,input().split())

import math
if x >= a*a*b/2:
    y = 2*(a*a*b-x)/(a*a)
    if y == 0:
        atan1 = 0
    else:
        atan1 = 90-math.degrees(math.atan(a/y))
else:
    y = 2*x/(a*b)
    if y == 0:
        atan1 = 0
    else:
        atan1 = math.degrees(math.atan(b/y))
print(atan1)

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

import math
if x >= a*a*b/2:
    y = 2*(a*a*b-x)/(a*a) 
    atan1 = 90-math.degrees(math.atan(a/y))
else:
    y = 2*x/(a*b)
    atan1 = math.degrees(math.atan(b/y))
print(atan1)
Problem p04029 (python)

Fixed submission:
x = 0
n = int(input())
for i in range(n+1):
  x += i
print(x)

Buggy submission (verdict: Runtime Error):
x = 0
for i in (input()+1):
  x += i
print(x)

Buggy submission (verdict: Runtime Error):
for i in (input()+1):
  x += i
print(x)
Problem p04030 (python)

Fixed submission:
s = [str(i) for i in list(str(input()))]
x = list()
for i in s:
    if i == "0" or i == "1":
      x.append(i)
    elif i== "B" and x != []:
        x.pop(-1)
print(','.join(x).replace(",",""))

Buggy submission (verdict: Runtime Error):
s = [str(i) for i in list(str(input()))]
x = list()
for i in s:
    if i == "0" or i == "1":
      x.append(i)
    else:
        x.pop(-1)
print(x)
Problem p02548 (python)

Fixed submission:
def make_divisors(n):
    cnt = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            cnt += 1
            if i != n // i:
                cnt += 1
        i += 1
    return cnt
numbers = [1,10, 100, 1000, 10000, 100000, 150000,200000, 250000,300000,350000, 400000,450000, 500000,550000,600000,630000,675000,700000,720000,750000,800000,825000,850000,875000,900000,912500,925000,950000,975000,987500,1000000]
datas = [0,23,473,7053,93643,1166714, 1810893, 2472071, 3145923, 3829761, 4522005,5221424,5927120,6638407,7354651,8075420,8509899,9164377,9529244,9821778,10261678,10997400,11366472,11736253,12106789,12478098,12664043,12850013,13222660,13595947,13782871,13969985]

N = int(input())
ttl = 0
numPin = 0

for i in range(len(numbers)):
    if N == 1000000:
        numPin = len(numbers) - 1
        break
    if numbers[i] <= N < numbers[i+1]:
        numPin = i
        break

if numPin != len(numbers)-1:
    if N - numbers[numPin] < numbers[numPin + 1] - N:
        for i in range(numbers[numPin], N):
            ttl += make_divisors(i)
        print(ttl + datas[numPin])
    else:
        for i in range(N,numbers[numPin+1]):
            ttl -= make_divisors(i)
        print(ttl + datas[numPin + 1])
else:
    print(datas[numPin])

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    cnt = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            cnt += 1
            if i != n // i:
                cnt += 1
        i += 1
    return cnt
numbers = [1,10, 100, 1000, 10000, 100000, 200000, 250000,300000,350000, 400000,450000, 500000,750000,1000000]
datas = [0,23,473,7053,93643,1166714, 2472071, 3145923, 3829761, 4522005,5221424,5927120,6638407,10261678,13969985]

N = int(input())
ttl = 0
numPin = 0

for i in range(len(numbers)):
    if numbers[i] <= N < numbers[i+1]:
        numPin = i
        break

if numPin != len(numbers)-1:
    if N - numbers[numPin] < numbers[numPin + 1] - N:
        for i in range(numbers[numPin], N):
            ttl += make_divisors(i)
        print(ttl + datas[numPin])
    else:
        for i in range(N,numbers[numPin+1]):
            ttl -= make_divisors(i)
        print(ttl + datas[numPin + 1])
else:
    print(datas[numPin])

Buggy submission (verdict: Runtime Error):
import sympy,math

N = int(input())
ttl = 0
tempNum = 0
count = 0

for i in range(1,N):
    tempNum = N - i
    count = len(sympy.divisors(tempNum))
    ttl += count

print(ttl)
Problem p02582 (python)

Fixed submission:
S = list(input())
cnt = 0
maxCnt = 0

for i in range(3):
    if S[i] == "R":
        cnt += 1
    else:
        cnt = 0
    if maxCnt < cnt:
        maxCnt = cnt

print(maxCnt)

Buggy submission (verdict: Runtime Error):
import itertools

def chkTrg(a,b,c):
    if (a + b > c and b + c > a and c + a > b) and (a != b and b != c and c != a):
        return True
    else:
        return False

N = int(input())
bars = [int(i) for i in input().split(" ")]

cnt = 0

for bar in itertools.combinations(bars, 3):
    if chkTrg(bar[0],bar[1],bar[2]):
        cnt += 1

print(cnt)
Problem p02583 (python)

Fixed submission:
import itertools

def chkTrg(a,b,c):
    if (a + b > c and b + c > a and c + a > b) and (a != b and b != c and c != a):
        return True
    else:
        return False

N = int(input())
bars = [int(i) for i in input().split(" ")]

cnt = 0

for bar in itertools.combinations(bars, 3):
    if chkTrg(bar[0],bar[1],bar[2]):
        cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import itertools

def chkTrg(a,b,c):
    if (a + b > c and b + c > a and c + a > b) and (a != b and b != c and c != a):
        return True
    else:
        return False

N = int(input())
bars = [int(i) for i in input().split(" ")]

cnt = 0

for bar in itertools.combinations(bars, 3):
    if chkTrg(bar[0],bar[1],bar[2]):
        cnt += 1

print(cnt)import itertools

def chkTrg(a,b,c):
    if (a + b > c and b + c > a and c + a > b) and (a != b and b != c and c != a):
        return True
    else:
        return False

N = int(input())
bars = [int(i) for i in input().split(" ")]

cnt = 0

for bar in itertools.combinations(bars, 3):
    if chkTrg(bar[0],bar[1],bar[2]):
        cnt += 1

print(cnt)
Problem p02687 (python)

Fixed submission:
S = input()

if S == 'ABC' :
    print('ARC')
else:
    print('ABC')

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

snk_sweets = []

for i in range(K):
    sweets = int(input())
    snk_sweets = snk_sweets + input().split()

len_snk = len(snk_sweets)
print(N - len_snk)
Problem p02705 (python)

Fixed submission:
import math
R = int(input())
print(2 * math.pi * R)

Buggy submission (verdict: Runtime Error):
import math
R = range(1,100)
def Circle(R):
    return 2 * math.pi * R
  
Circle(R)
Problem p02717 (python)

Fixed submission:
X,Y,Z = list(map(int,input().split()))
print(Z,X,Y)

Buggy submission (verdict: Runtime Error):
box = [input(),input(),input()]
X,Y,Z = box
print(Y,Z,X)

Buggy submission (verdict: Runtime Error):
box = [input(),input(),input()]
X,Y,Z = box
print(Y,Z,X)
Problem p02678 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
bridge = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    bridge[a - 1].append(b - 1)
    bridge[b - 1].append(a - 1)
queue = deque([0])
ans = [[] for i in range(n)]
ans[0].append('god')
while queue:
    now = queue.popleft()
    for factor in bridge[now]:
        if not (ans[factor]):
            ans[factor].append(now)
            queue.append(factor)
print('Yes')
for i in range(1, len(ans)):
    print(ans[i][0]+1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    A = a - 1
    B = b - 1
    L[A].append(B)
    L[B].append(A)
BFS = list()
BFS.append([0])
ans = [[] for i in range(n - 1)]
while [] in ans:
    BFS.append([])
    for i in BFS[-2]:
        if L[i]:
            for j in L[i]:
                BFS[-1].append(j)
                ans[j - 1].append(i + 1)
                L[j].remove(i)
print('Yes')
for k in range(len(ans)):
    print(ans[k][0])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    A = a - 1
    B = b - 1
    L[A].append(B)
    L[B].append(A)
BFS = list()
BFS.append([0])
ans = [[] for i in range(n - 1)]
while [] in ans:
    BFS.append([])
    for i in BFS[-2]:
        for j in L[i]:
            BFS[-1].append(j)
            ans[j - 1].append(i + 1)
            L[j].remove(i)
print('Yes')
for k in range(len(ans)):
    print(ans[k][0])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    A = a - 1
    B = b - 1
    L[A].append(B)
    L[B].append(A)
BFS = list()
BFS.append([0])
ans = [[] for i in range(n - 1)]
while [] in ans:
    BFS.append([])
    for i in BFS[-2]:
        for j in L[i]:
            BFS[-1].append(j)
            ans[j - 1].append(i + 1)
            L[j].remove(i)
for k in range(len(ans)):
    print(ans[k][0])
Problem p02681 (python)

Fixed submission:
s=input()
t=input()
if t[0:len(t)-1]==s:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
C=list()
A=list()
for i in range(n):
    c=list(map(int,input().split()))
    C.append(c[0])
    A.append(c[1:m+1])
L=[0]*m
for i in range(n):
    for j in range(m):
        L[j]+=A[i][j]
if min(L)<x:
    print(-1)
else:
    import itertools
    v=list(itertools.permutations([i for i in range(n)]))
    l=[0]*len(v)
    for i in range(len(v)):
        z=v[i]
        r=[0]*m
        for j in range(n):
            l[i]+=C[z[j]]
            for k in range(m):
                r[k]+=A[z[j]][k]
            if min(r)>=x:
                break
    print(min(l))
Problem p02690 (python)

Fixed submission:
x = int(input())
a = 0
if x == 0:
    print(0, 0)
else:
    while a ** 5 - (a - 1) ** 5 <= x:
        a += 1
        b = a
        while a ** 5 - b ** 5 < x:
            b -= 1
            if a ** 5 - b ** 5 == x:
                break
        else:
            continue
        break
    print(a, b)

Buggy submission (verdict: Runtime Error):
x = int(input())
a = 0
if x == 0:
    print(0, 0)
else:
    while a ** 5 - (a - 1) ** 5 < x:
        a += 1
        b = a
        while a ** 5 - b ** 5 < x:
            b -= 1
            if a ** 5 - b ** 5 == x:
                break
        else:
            continue
        break
    print(a, b)

Buggy submission (verdict: Runtime Error):
x = int(input())
a = 0
while a ** 5 - (a - 1) ** 5 < x:
    a += 1
    b = a
    while a ** 5 - b ** 5 < x:
        b -= 1
        if a ** 5 - b ** 5 == x:
            break
    else:
        continue
    break
print(a, b)

Buggy submission (verdict: Runtime Error):
x = int(input())
i = -1
while (i + 1) ** 5 - i ** 5 < x:
    i += 1
    j = i
    while i ** 5 - j ** 5 < x:
        j -= 1
        #print(i, j)
        if i ** 5 - j ** 5 == 0:
            break
    else:
        continue
    break
print(i, j)
Problem p02722 (python)

Fixed submission:
N = int(input())


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


L1 = factorization(N - 1)
s = 1
# print(L1)
for [a, b] in L1:
    s *= (b + 1)
# print(s)


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


for i in set(make_divisors(N))-{1}:
    temp = N
    while temp % i == 0:
        temp //= i
    if (temp-1) % i == 0:
        s += 1
s -= 1
if N == 2:
    print(1)
else:
    print(s)

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


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


L1 = factorization(N - 1)
s = 1
# print(L1)
for [a, b] in L1:
    s *= (b + 1)
# print(s)
# print(set(sympy.divisors(N))-{1})
for i in set(sympy.divisors(N))-{1}:
    temp = N
    while temp % i == 0:
        temp //= i
    if (temp-1) % i == 0:
        s += 1
s -= 1
print(s)

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


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


L1 = factorization(N - 1)
s = 1
# print(L1)
for [a, b] in L1:
    s *= (b + 1)
# print(s)
# print(set(sympy.divisors(N))-{1})
for i in set(sympy.divisors(N))-{1}:
    temp = N
    while temp % i == 0:
        temp //= i
    if (temp-1) % i == 0:
        s += 1
s -= 1
print(s)
Problem p02755 (python)

Fixed submission:
a,b=map(int,input().split())
x=100*a/8
y=100/8*(a+1)
z=10*b
w=10*(b+1)
import math
if max(math.ceil(z),math.ceil(x))<min(y,w) :
    print(math.ceil(max(z,x)))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
x=100*a/8
y=100/8*(a+1)
z=10*b
w=10*(b+1)
import math
if max(math.ceil(z),math.ceil(x))<min(y,w)1 3 :
    print(math.ceil(max(z,x)))
else:
    print(-1)
Problem p02756 (python)

Fixed submission:
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

rev = 0
for_s = ''
rev_s = ''

out = ''
for q in q_list:
    if q[0] == '1':
        rev = 1 - rev
    elif q[1] == '1':
        if rev == 0:
            rev_s += q[2]
        else:
            for_s += q[2]
    else:
        if rev == 0:
            for_s += q[2]
        else:
            rev_s += q[2]

if rev == 0:
    out = rev_s[::-1] + s + for_s
else:
    out = for_s[::-1] + s[::-1] + rev_s
print(out)

Buggy submission (verdict: Runtime Error):
import pandas as pd

s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]
df = pd.DataFrame( columns=['S', 'N'] )
df = df.append(pd.Series([s, 0], index=df.columns), ignore_index=True)
out = ''

for q in q_list:
    if q[0] == '1':
        df['N'] = len(df) - 1 - df['N']
    elif q[1] == '1':
        df['N'] = df['N'] + 1
        df = df.append(pd.Series([q[2], 0], index=df.columns), ignore_index=True)
    else:
        df = df.append(pd.Series([q[2], len(df) ], index=df.columns), ignore_index=True)

df_s = df.sort_values('N')
for x in df_s['S']:
    out += x
print(out)
Problem p02780 (python)

Fixed submission:
a, b = map(int, input().split())
num_list = list(map(int, input().split()))
k_sum = sum(num_list[0:b])
max_sum = k_sum
for i, j in zip(num_list[0:], num_list[b:]):
    k_sum -= i
    k_sum += j
    max_sum = max(max_sum, k_sum)
out = (max_sum + b) / 2
print(out)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
num_list = list(map(int, input().split()))
k_sum = sum(num_list[0:b])
max_sum = k_sum
for i, j in zip(num_list[0:], num_list[k:]):
    k_sum -= i
    k_sum += j
    max_sum = max(max_sum, k_sum)
out = (max_sum + b) / 2
print(out)
Problem p02789 (python)

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

Buggy submission (verdict: Runtime Error):
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    if array[i] == min(array[0:i+1]):
        out = out + 1
print(out)
Problem p02791 (python)

Fixed submission:
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)

Buggy submission (verdict: Runtime Error):
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    out = out + 1 if array[i] == min(array[0:i+1])
print(out)
Problem p03607 (python)

Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    counter = Counter(a)
    ans = 0
    for key, value in counter.items():
        if value % 2 == 1:
            ans += 1
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
from collections import Counter


def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    counter = Counter(a)
    ans: int = 0
    for key, value in counter.items():
        if value % 2 == 1:
            ans += 1
    print(ans)


main()
Problem p02787 (python)

Fixed submission:
H, N = map(int, input().split())
da, cost = [0] * N, [0] * N
for i in range(N):
    da[i],cost[i]=map(int, input().split())

max_da=max(da) 
dp = [float("inf") for i in range(H+max_da)]
dp[0]=0

for i in range(H+max_da):
    for j in range(N):
        if i-da[j]>=0:
            dp[i]=min(dp[i],dp[i-da[j]]+cost[j])

print(min(dp[H:]))

Buggy submission (verdict: Runtime Error):
from mypulp import *

model = Model('aaa')
a=[int(i) for i in input().split()]
b=[input().split() for i in range(a[1])]
x={}
for j in range(1,a[1]+1):
    x[j]=model.addVar(vtype='I',name=f'x({j})')
model.update()
model.addConstr(quicksum(int(b[j-1][0])*x[j] for j in range(1,a[1]+1))>=a[0])
a=quicksum(int(b[j-1][1])*x[j] for j in range(1,a[1]+1))
model.setObjective(a, GRB.MINIMIZE )
model.optimize()
print(int(model.ObjVal))
Problem p03160 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))

# nの足場までいく最小コストを a_n とする。
# a_1のコストは0,  a_2のコストは(h_1からの１通りなので)\h_1-h_2\
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print(dp[-1])

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

dp=[0]
for i in range(1,n): # dp[i]の最小を決めていく。
    dpi=float('inf')
    for j in range(1,k+1):
        if i<j:
            break
        else:
            dpi=min(dp[i-j]+abs(h[i]-h[i-j]),dpi)
    dp.append(dpi)
print(dp[-1])
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

V = sum(v)
# dp[i][j]:i番目までの品物から価値がj以上になるよう選んだときの重さの総和の最小値
dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]

dp[0][0] = 0
for i in range(N):
	for j in range(V + 1):
		# i+1番目を選ぶ場合
		if j - v[i] >= 0:
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
		# i+1番目を選ばない場合
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

# dp[N][j]がW以下であるようなjの最大値が答えになる
ans = 0
for j in range(V + 1):
	if dp[N][j] <= W:
		ans = j

print(ans)

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W+1):
        if j-w[i]>=0:
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])