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

Fixed submission:
import  itertools
import numpy as np

N,M,X = map(int, input().split())
A = []
for i in range(N):
    A.append(np.array(list(map(int, input().split()))))

#print(A)
l = [1, 0]
ll = list(itertools.product(l, repeat=N))
#print(ll)
ans = float("inf")
for i in ll:
    jdg = np.array([0] * (M+1))
    for k in range(N):
        if i[k] == 1:
             jdg = jdg + A[k]
    #print(jdg)
    if min(jdg[1:]) >= X:
        ans = min(ans,jdg[0])
    #print(min(jdg[1:]))
if ans != float("inf"):
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import  itertools
import numpy as np

N,M,X = map(int, input().split())
A = []
for i in range(N):
    A.append(np.array(list(map(int, input().split()))))

#print(A)
l = [1, 0]
ll = list(itertools.product(l, repeat=N))
#print(ll)
ans = float("inf")
for i in ll:
    jdg = np.array([0] * (M+1))
    for k in range(N):
        if i[k] == 1:
             jdg = jdg + A[k]
    #print(jdg)
    if min(jdg[1:]) >= X:
        ans = min(ans,jdg[0])
    #print(min(jdg[1:]))
if ans != float("inf"):
    print(ans)
else:
    print(-1)
Problem p02691 (python)

Fixed submission:
import collections

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

for i in range(N):
    B[i-A[i]] += 1 
    C[i+A[i]] += 1
#print(B)
#print(C)
ans = 0
for i in B:
    #print(i) i=Key
    if i in C:
        ans += B[i]*C[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline


N = int(input())

a = list(map(int, input().split()))
A = np.array([a for i in range(N)])
B = np.array([[a[i]] * N for i in range(N)])
C = A + B
d = [i for i in range(N)]
D = np.array([d for i in range(N)])
E = np.array([[i] * N for i in range(N)])

#print(D)
#print(E)
ind = D - E
#print(ind)
ans = C - ind
#print(ans)
#cnt = np.count_nonzero(ans == 0)
print(cnt)
Problem p02702 (python)

Fixed submission:
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
cnt = [0] * 2019
cnt[0] = 1
p = 1
dp = 0

for i in reversed(range(N)):
    dp = (dp + A[i]*p) % 2019
    cnt[dp] += 1
    p = 10 * p % 2019
ans = 0

for i in cnt:
    ans += i*(i-1)//2

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
dp = [0] * 2019
cnt = [0] * 2019
cnt[0] = 1
p = 1

for i in reversed(range(N)):
    dp[i] = (dp[i+1] + A[i]*p) % 2019
    cnt[dp[i]] += 1
    p = 10 * p % 2019
ans = 0

for i in cnt:
    ans += i*(i-1)//2

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
dp = [0] * 2019
cnt = [0] * 2019
cnt[0] = 1
p = 1

for i in reversed(range(N)):
    dp[i] = (dp[i+1] + A[i]*p) % 2019
    cnt[dp[i]] += 1
    p = 10 * p % 2019 

ans = 0
for i in cnt:
    ans += i*(i-1)//2

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
dp = [0] * 2019
cnt = [0] * 2019
cnt[0] = 1

for i in reversed(range(N)):
    dp[i] = (dp[i+1] + (A[i]*(10**(N-i))%2019)) % 2019
    cnt[dp[i]] += 1

ans = 0
for i in cnt:
    ans += i*(i-1)//2

print(ans)
Problem p02718 (python)

Fixed submission:
N,M =map(int, input().split())
A =list(map(int, input().split()))
B = sorted(A, reverse = True)
if B[M-1] >= sum(B)/4/M:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

N,M =map(int, input().split())
A =list(map(int, input().split()))
B = sorted(A, reverse = True)
if B[M] >= sum(B)//4//M:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

N,M =map(int, input().split())
A =list(map(int, input().split()))
B = sorted(A, reverse = True)
if B[M] >= sum(B)/4/M:
    print("Yes")
else:
    print("No")
Problem p02720 (python)

Fixed submission:
from collections import deque

K=int(input())

def bfs(k):
    queue = deque()
    for i in range(1, 10):#1~9までをqueueに追加しておく
        queue.append(i)
    cnt = 1
    
    while queue:
        x = queue.popleft()#左から取り出すと、自動的に小さい順から取り出せる
        if cnt == k:
            return x
        cnt += 1 #これまでのルンルン数の数
        last = x%10 #末尾の数字
        if last > 0:
            queue.append(x*10+last-1)#x-1⇒x⇒x+1の順にを末尾に追加すると順番になる。0と9に注意
        queue.append(x*10+last)
        if last < 9:
            queue.append(x*10+last+1)
            
print(bfs(K))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**10)

k = int(input())
l = len(str(k))+4
A = [str(i+1) for i in range(9)]
B = ["0"] + A
ans = []
#print(l)

def dfs(num,l):
    if len(num) >= l:
        ans.append(int(num))
    else:
        ans.append(int(num))
        for i in B:
            if abs(int(num[-1])-int(i)) < 2:
                dfs(num + i,l)
if k <= 9:
    print(k)
else:
    for i in A:
        dfs(i,l)
    ans = sorted(ans)
    #print(ans)
    print(ans[k-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

k = int(input())
l = len(str(k))+4
A = [str(i+1) for i in range(9)]
B = ["0"] + A
ans = []
#print(l)

def dfs(num,l):
    if len(num) >= l:
        ans.append(int(num))
    else:
        ans.append(int(num))
        for i in B:
            if abs(int(num[-1])-int(i)) < 2:
                dfs(num + i,l)
if k <= 9:
    print(k)
else:
    for i in A:
        dfs(i,l)
    ans = sorted(ans)
    #print(ans)
    print(ans[k-1])

Buggy submission (verdict: Runtime Error):
k = int(input())
l = len(str(k))
A = [str(i) for i in range(10)]
ans = [i+1 for i in range(9)]

def dfs(num,l):
    if len(num) >= l:
        ans.append(int(num))
    else:
        for i in A:
            if abs(int(num[-1])-int(i)) < 2:
                dfs(num + i,l)
for i in A:
    dfs(i,l)
ans = sorted(ans)
#print(ans)
print(ans[k+1])
Problem p02724 (python)

Fixed submission:
#!/usr/bin/env python3

X = int(input())
ans = 0

while X >= 500:
    X -= 500
    ans += 1000
while X >= 5:
    X -= 5
    ans += 5
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

#!/usr/bin/env python3

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
cnt = 0

def dist(X,i,j):
    dist = 0
    for k in range(D):
        dist += (X[i][k] - X[j][k]) **2
    dist = dist ** 0.5
    return dist.is_integer()

for i in range(N):
    for j in range(N):
        if i >= j :
            continue
        else:
            if dist(X,i,j):
                cnt += 1

print(cnt)
Problem p02732 (python)

Fixed submission:
N = int(input())
L = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for i in L:
    C[i-1] += 1
res = 0

for i in range(N):
    res += C[i]*(C[i]-1)//2
# 合計最初に出す
for i in range(N):
    j = L[i]-1
    print(res - C[j]*(C[j]-1)//2 + (C[j]-1)*(C[j]-2)//2)

Buggy submission (verdict: Runtime Error):
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
L = list(map(int, input().split()))
M = set(L)
K = collections.Counter(L)
ans = 0

for i in M:
    ans += combinations_count(K[i], 2) 

for i in range(N):
    B = K[L[i]]    
    if B == 2:
        print(ans - 1)
    elif B > 2:
        print(ans -combinations_count(B,2) +combinations_count(B-1,2))
    else:
        print(ans)

Buggy submission (verdict: Runtime Error):
import collections
import math
import sys
input = sys.stdin.readline

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
L = list(map(int, input().split()))
M = set(L)
K = collections.Counter(L)
ans = 0

for i in M:
    ans += combinations_count(K[i], 2) 

for i in range(N):
    B = K[L[i]]    
    if B == 2:
        print(ans - 1)
    elif B > 2:
        print(ans -combinations_count(B,2) +combinations_count(B-1,2))
    else:
        print(ans)
Problem p02768 (python)

Fixed submission:
def comb(n,r,mod=10**9+7):
    cnt = 1
    for i in range(1, r+1): #nCr = n*(n-1)*...(n-r+1)/r!で分母 = cnt
        cnt *= (n-i+1)*pow(i,mod-2,mod) #逆元法 X*Y**(mod-2)%mod。繰り返し2乗法powを使う
        cnt %= mod #値が大きくなるので全てmodで計算
    return cnt

n, a, b = map(int, input().split())
mod = 10**9+7

ans = (pow(2,n,mod)-1-comb(n,a)-comb(n,b)) % mod #値が大きくなるので全てmodで計算
print(ans)

Buggy submission (verdict: Runtime Error):
def comb(n,r,mod=10**9+7):
    return((n(n-1)//2 - r(r-1)//2)%mod)

n, a, b = map(int, input().split())
mod = 10**9+7

ans = (pow(2,n,mod)-1-comb(n,a)-comb(n,b)) % mod #値が大きくなるので全てmodで計算
print(ans)
Problem p02811 (python)

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

if 500*A >= B:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import fractions
import functools
import math
N, M = map(int, input().split())
A = [int(x)//2 for x in input().split()]
#------------------------------------------------
#リスト内の最小公倍数
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
all_lcm = functools.reduce(lcm, A)  
#------------------------------------------------
# Aの最小値が2で割り切れる回数
cnt = 0
min_a = min(A)
while True:
    if min_a % 2 != 0:
        break
    min_a //= 2
    cnt += 1
# Aのすべての数が2でcnt回割り切れる
cond1 = all({i % (2**cnt) == 0 for i in A})
# cnt回割った後、さらに2で割り切れる数は存在しない
cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    print(math.ceil(M/all_lcm/2))
else:
    print(0)
Problem p02837 (python)

Fixed submission:
#ABC 147 C 「Honest or Unkind」

n=int(input())
ans=0
A=[[] for _ in range(n)]

for i in range(n):
    a=int(input())
    for j in range(a):
        A[i].append(tuple(map(int,input().split())))
        
#-------------------------------------------------------------iをn桁２進数表記（[2:]で0bを切って、zfill()で左揃えへ）
for i in range(2**n):
    ii=str(bin(i))[2:].zfill(n)
#-------------------------------------------------------------#i個目の場合が証言をみたすか調べる：2**n個の組み合わせ
    chk=True
    cur=0
 
    for j in range(n):                                        #j個目の証言を満たすか調べる        
        if ii[j]=="0":
            continue
        else:
            cur+=1                                            #Count up 
            for x,y in A[j]:                                  #turpleで(x,y)を指定する
                if y==1 and ii[x-1]=="0":                     #Aとiiを比較
                    chk=False                                 #違っていたらFalseへ
                elif y==0 and ii[x-1]=="1":
                    chk=False
    if chk:                                                   #もしChk = Trueのままだったらn個全ての証言をみたすので、これまでのマックスと比べる
        ans=max(ans,cur)
print(ans)

Buggy submission (verdict: Runtime Error):
#ABC 147 C 「Honest or Unkind」

n=int(input())
ans=0
A=[[] for _ in range(n)]

for i in range(n):
    a=int(input())
    for j in range(a):
        A[i].append(tuple(map(int,input().split())))
        
#-------------------------------------------------------------iをn桁２進数表記（[2:]で0bを切って、zfill()で左揃えへ）
for i in range(2**n):
    ii=str(bin(i))[2:].zfill(n)
#-------------------------------------------------------------#i個目の場合が証言をみたすか調べる：2**n個の組み合わせ
    chk=True
    cur=0
 
    for j in range(n):　　　　　　　　　　　　　　　　　　　　　  #j個目の証言を満たすか調べる
        if ii[j]=="0":
            continue
        else:
            cur+=1　　　　　　　　　　　　　　　　　　　　　　　  #Count up 
            for x,y in A[j]:                                  #turpleで(x,y)を指定する
                if y==1 and ii[x-1]=="0":                     #Aとiiを比較
                    chk=False                                 #違っていたらFalseへ
                elif y==0 and ii[x-1]=="1":
                    chk=False
    if chk:　　　　　　　　　　　　　　　　　　　　　　　　　　　　#もしChk = Trueのままだったらn個全ての証言をみたすので、これまでのマックスと比べる
        ans=max(ans,cur)
print(ans)
Problem p02923 (python)

Fixed submission:
N = int(input())
H = [int(x) for x in input().split()]
count = 0
A =[]

for i in range(N-1):
    if H[i] >= H[i+1]:
        count = count +1
        A. append(count)
    if H[i] < H[i+1]:
        count = 0
        A. append(count)

if N >1:
    print(max(A))
if N ==1:
    print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = [int(x) for x in input().split()]
count = 0
A =[]

for i in range(N-1):
    if H[i] >= H[i+1]:
        count = count +1
        A. append(count)
    if H[i] < H[i+1]:
        count = 0
        A. append(count)

print(max(A))
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
L_mod = L % 2019
R_mod = R % 2019

if R - L >= 2019:
    Ans = 0
elif R_mod < L_mod:
    Ans = 0
elif R_mod > L_mod:
    Ans = 2019
    for i in range(L_mod, R_mod):
        for k in range(L_mod+1,R_mod+1):
            Ans = min(Ans,i*k % 2019)
        
print(Ans)

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

if R - L >= 2019:
    Ans = 0
elif R_mod < L_mod:
    Ans = 0
elif R_mod > L_mod:
    for i in range(L_mod, R_mod-1):
        Ans = 2019
        Ans = min(Ans,i*(i+1) % 2019)
        
print(Ans)
Problem p02995 (python)

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

ans =(B-A+1)-(B//(C)-(A-1)//C+B//(D)-(A-1)//D-B//lcm(C,D)+(A-1)//lcm(C,D))
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D =map(int,input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

N_C = (B-A) // C
N_D = (B-A) // D
N_CD = (B-A) // lcm(C,D)

if C == 1:
    ans == 0
elif D == 1:
    ans == 0
else:
    ans = (B-A)-N_C-N_D+N_CD
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D =map(int,input().split())

import math

N_C = (B-A) // C
N_D = (B-A) // D
N_CD = (B-A) // (C*D//math.gcd(C, D))

ans = (B-A)-N_C-N_D+N_CD
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D =map(int,input().split())

N_list = list(range(A, B+1))

ans = 0
for i in range(len(N_list)):
    if N_list[i] % C == 0:
        ans = ans
    elif N_list[i] % D == 0:
        ans = ans
    else:
        ans = ans +1

print(ans)
Problem p03035 (python)

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

if A >= 13:
    print(B)
if A >=6 and A <= 12:
    print(math.floor(B/2))
if A <= 5:
    print("0")

Buggy submission (verdict: Runtime Error):
N, M= map(int, input().split())
L1, R1= map(int, input().split())
Ans = set(range(L1, R1+1))

for x in range(M-1):
    L, R = map(int, input().split())
    List = set(range(L, R+1))
    Ans = (Ans) & (List)

print(len(Ans))
Problem p03059 (python)

Fixed submission:
A, B, T = map(int, input().split())
ans = ((T + 0.5) // A ) * B
print(round(ans))

Buggy submission (verdict: Runtime Error):
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = fractions.gcd(L[i-1], A[i-1])
    R[-i-1] = fractions.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = fractions.gcd(L[i], R[i])

print(max(ans))
Problem p03061 (python)

Fixed submission:
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = fractions.gcd(L[i-1], A[i-1])
    R[-i-1] = fractions.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = fractions.gcd(L[i], R[i])

print(max(ans))

Buggy submission (verdict: Runtime Error):
import math
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i-1])
    R[-i-1] = math.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = math.gcd(L[i], R[i])

print(max(ans))

Buggy submission (verdict: Runtime Error):
import math
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i-1])
    R[-i-1] = math.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = math. gcd(L[i], R[i])

print(max(ans))

Buggy submission (verdict: Runtime Error):
import fractions
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i-1])
    R[-i-1] = math.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = math. gcd(L[i], R[i])

print(max(ans))
Problem p03076 (python)

Fixed submission:
A = input()
B = input()
C = input()
D = input()
E = input()

AA = int(A)
BB = int(B)
CC = int(C)
DD = int(D)
EE = int(E)

a = A[-1]
b = B[-1]
c = C[-1]
d = D[-1]
e = E[-1]

aa = int(a)
bb = int(b)
cc = int(c)
dd = int(d)
ee = int(e)

data = [aa ,bb, cc, dd, ee]
def func(x):
    if(x==0): return False
    else: return True
    
filtered = filter(func, data)

if aa==bb==cc==dd==ee==0:
    kk =int(10)
else:
    kk = min (filtered)

n = int(0)

if aa == 0 :
    n = n+AA
else:
    n = n+AA+10-aa
if bb == 0 :
    n = n+BB
else:
    n = n+BB+10-bb
if cc == 0 :
    n = n+CC
else:
    n = n+CC+10-cc
if dd == 0 :
    n = n+DD
else:
    n = n+DD+10-dd
if ee == 0 :
    n = n+EE
else:
    n = n+EE+10-ee
print(n+kk-10)

Buggy submission (verdict: Runtime Error):
A = input()
B = input()
C = input()
D = input()
E = input()

AA = int(A)
BB = int(B)
CC = int(C)
DD = int(D)
EE = int(E)

a = A[-1]
b = B[-1]
c = C[-1]
d = D[-1]
e = E[-1]

aa = int(a)
bb = int(b)
cc = int(c)
dd = int(d)
ee = int(e)

data = [aa ,bb, cc, dd, ee]
def func(x):
    if(x==0): return False
    else: return True
    
filtered = filter(func, data)

kk =min (filtered)
n = int(0)

if aa == 0 :
    n = n+AA
else:
    n = n+AA+10-aa
if bb == 0 :
    n = n+BB
else:
    n = n+BB+10-bb
if cc == 0 :
    n = n+CC
else:
    n = n+CC+10-cc
if dd == 0 :
    n = n+DD
else:
    n = n+DD+10-dd
if ee == 0 :
    n = n+EE
else:
    n = n+EE+10-ee
print(n+kk-10)

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

AA = int(A)
BB = int(B)
CC = int(C)
DD = int(D)
EE = int(E)

a = A[-1]
b = B[-1]
c = C[-1]
d = D[-1]
e = E[-1]

aa = int(a)
bb = int(b)
cc = int(c)
dd = int(d)
ee = int(e)

data = [aa ,bb, cc, dd, ee]
def func(x):
    if(x==0): return False
    else: return True
    
filtered = filter(func, data)

kk =min (filtered)
n = int(0)

if aa == 0 :
    n = n+AA
else:
    n = n+AA+10-aa
if bb == 0 :
    n = n+BB
else:
    n = n+BB+10-bb
if cc == 0 :
    n = n+CC
else:
    n = n+CC+10-cc
if dd == 0 :
    n = n+DD
else:
    n = n+DD+10-dd
if ee == 0 :
    n = n+EE
else:
    n = n+EE+10-ee
print(n+kk-10)
Problem p03079 (python)

Fixed submission:
A, B, C = map(int, input().split())
if A == B == C:
    print("Yes")
else:
    print("No")

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

S = str.count("R")
if S > N//2 :
    print("Yes")
else:
    print("No")

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

S = str.count("R")
if S > N//2 :
    print("Yes")
else:
    print("No")
Problem p03087 (python)

Fixed submission:
N ,Q = map(int, input().split())
S = list(input())
ans = [0]*N
jdg = S[0]
cnt = 0
for i in range(1,N):
    if jdg == "A" and S[i] == "C":
        cnt += 1
        ans[i] = cnt
        jdg = S[i]
    else:
        jdg = S[i]
        ans[i] = cnt

for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r-1]-ans[l-1])

Buggy submission (verdict: Runtime Error):
N ,Q = map(int, input().split())
S = list(input())
ans = [0]*N
jdg = S[0]
cnt = 0
for i in range(1,N):
    if jdg == "A" and S[i] == "C":
        cnt += 1
        ans[i] = cnt
        jdg[i] = S[i]
    else:
        jdg = S[i]
        ans[i] = cnt

for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r-1]-ans[l-1])
Problem p03111 (python)

Fixed submission:
n, A, B, C = map(int,input().split())
l = [int(input()) for i in range(n)]

inf = 10**9

def dfs(cur, a, b, c):
    if cur == n:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else inf#-30は最初に選んだもの
    ret0 = dfs(cur + 1, a, b, c)#何も使わない
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10#Aに使うために合成するとして
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10#Bに使うために合成するとして
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10#Cに使うために合成するとして
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))

Buggy submission (verdict: Runtime Error):
n, a, b, c = map(int,input().split())
l = [int(input() for i in range(n))]

inf = 10**9

def dfs(cut, a, b, c):
    if cur == n:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else inf#-30は最初に選んだもの
    ret0 = dfs(cur + 1, a, b, c)#何も使わない
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10#Aに使うために合成するとして
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10#Bに使うために合成するとして
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10#Cに使うために合成するとして
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))
Problem p03160 (python)

Fixed submission:
#　最小値を求めるDP　
#　Atcoder DP まとめコンテスト「A.Frog」　https://atcoder.jp/contests/dp/tasks/dp_a

N = int(input())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0]) #　1、２の初期値を設定

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(2, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N - 1])

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

A = [0] * (N + 1)
B = [0] * (N + 1)
C = [0] * (N + 1)

for i in range(1, N + 1):
    A[i], B[i], C[i] = map(int, input().split())

dp = [[0] * 3 for _ in range(N + 1)]#N+1
for i in range(1, N + 1):
    dp[i][0] = A[i] + max(dp[i-1][1], dp[i-1][2])#dp[i][0]=i日目でaを選んだ時の最大値＝i-1日目でbかcを選んだ時の最大値+ai
    dp[i][1] = B[i] + max(dp[i-1][2], dp[i-1][0])
    dp[i][2] = C[i] + max(dp[i-1][0], dp[i-1][1])

print(max(dp[N]))#Nの時の最大

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

inf = float('inf')
dp = [inf] * N

dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(1, N):
    for k in range(1, K+1):
        if i-k <0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k])) 

print(dp[N - 1])

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

inf = float("inf")
dp = [inf] * N

dp[0] = 0
dp[1] = h[1] - h[0]
for i in range(2 , N):
    dp[i] = min(abs(h[i] - h[i - 2]) + dp[i - 2], abs(h[i - 1] - h[i]) + dp[i - 1])
#print(dp)
print(dp[N])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def f(x):#dpは
    if dp[x]!=-1:
        return dp[x]#すでに値が決まっていたらそれをかえす
    ans=0
    for e in d[x]:#すべての枝について
        ans=max(ans,1+f(e))
    dp[x]=ans
    return ans

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

d={}
dp=[-1]
for i in range(1,n+1):
    d[i]=[]#dは初期値を[]
    dp.append(-1)#dpは初期値-1

for _ in range(m):
    a,b = map(int, input().split())
    d[a].append(b)#有向グラフをdictで
    
ans=0
for i in range(1,n+1):
    ans=max(ans,f(i))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def f(x):#dpは
    if dp[x]!=-1:
        return dp[x]#すでに値が決まっていたらそれをかえす
    ans=0
    for e in d[x]:#すべての枝について
        ans=max(ans,1+f(e))
    dp[x]=ans
    return ans

n,m = list(map(int, input().split()))
d = {}
dp = [[-1] for i in range(n+1)]#初期値を全て-1に設定
    
for _ in range(m):
    a,b = list(map(int, input().split()))
    d[a].append(b)#有向グラフ
    
ans=0
for i in range(1,n+1):
    ans=max(ans,f(i))
print(ans)