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

Fixed submission:
first_input = list(map(int, input().split()))
number = first_input[0]
steps = first_input[1]

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

start_cost = scaffolds[0]

costs = []

for i in range(number):
    next_step = i
    next_scaffold = scaffolds[next_step]
    target_cost = -1
    for j in range(steps):
        
        last_step = next_step - (j + 1)
        if -1 < last_step:
            cost = abs(scaffolds[next_step] - scaffolds[last_step]) + costs[last_step]
            if target_cost == -1 or cost < target_cost:
                target_cost = cost

    if 0 < target_cost:
        next_cost = target_cost
    else:
        next_cost = scaffolds[next_step]

    
    costs.append(next_cost)

print(costs[number - 1] - start_cost)

Buggy submission (verdict: Runtime Error):
first_input = list(map(int, input().split()))
number = first_input[0]
steps = first_input[1]

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

start_cost = scaffolds[0]

costs = [start_cost for i in range(number)]

for i in range(number):
    next_step = i
    next_scaffold = scaffolds[next_step]
    target_cost = -1
    for j in range(steps):
        
        last_step = next_step - (j + 1)
        if -1 < last_step:
            cost = abs(scaffolds[next_step] - scaffolds[last_step]) + costs[last_step]
            if target_cost < cost
            target_cost = cost

    if 0 < len(target_cost):
        next_cost = target_cost
    else:
        next_cost = scaffolds[next_step]

    if -1 < next_cost:
        costs[i] = next_cost

print(costs[number - 1] - start_cost)
Problem p03163 (python)

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy submission (verdict: Runtime Error):
def solve(N, W, weightValues):
    dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
    for i in range(1, N + 1):
        w, v = weightValues[i]
        for j in range(1, W + 1):
            if j < w: # you cant take it
                dp[i][j] = dp[i - 1][j]
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
    print(dp[N][W])

def iln(): return list(map(int, input().split()))


N, W = iln()
w_v = []
for i in range(N):
    w_v.append(iln())

solve(N, W, w_v)

Buggy submission (verdict: Runtime Error):
def solve(N, W, weightValues):
    dp = [0] * (W + 1)
    s = 0
    for w, v in weightValues:
        s += w # why ?
        for i in range(min(W, s), w - 1, -1): # why min(W, s)
	    	dp[i] = max(dp[i], dp[i - w] + v)

    print(max(dp))

def iln(): return list(map(int, input().split()))

N, W = iln()
w_v = []
for i in range(N):
  w_v.append(iln())
  
solve(N, W, w_v)

Buggy submission (verdict: Runtime Error):
def solve(N, W, weightValues):
    dp = [0] * (W + 1)
    s = 0
    for w, v in weightValues:
        s += w # why ?
        for i in range(min(W, s), w - 1, -1): # why min(W, s)
	    	dp[i] = max(dp[i], dp[i - w] + v)

    print(max(dp))

def iln(): return list(map(int, input().split()))

N, W = iln()
w_v = []
for i in range(N):
  w_v.append(iln())
  
solve(N, W, w_v)
Problem p03161 (python)

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

def get_cost(arr, n, k, dp):
  min_ = -1
  for i in range(2, n):
    dp[i] = min([(abs(arr[s] - arr[i]) + dp[s]) for s in range(max(0, i-k), i)])
  return dp[-1]
    

N, K = input().split()
N = int(N)
K = int(K)
arr = [int(num) for num in input().split()]

dp = [0]*N
dp[1] = abs(arr[1] - arr[0])
print(get_cost(arr, N, K, dp))

Buggy submission (verdict: Runtime Error):
def get_cost(arr, n, k, dp):
  if dp[n] is not None:
    return dp[n]
  elif k >= n-1:
    return abs(arr[-1] - arr[0])
  elif n == 0:
    dp[0] = 0
    return dp[0]
  elif n == 1:
    dp[1] = abs(arr[1] - arr[0])
    return dp[1]

N, K = input().split()
N = int(N)
K = int(K)

dp = [None]*N
print(get_cost(arr, N-1, K, dp)
Problem p03160 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000000)

n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    if j >= n:
        return 0
    return abs(h[i] - h[j])

def get_min_cost_from_postion(i):
    if i >= n-1:
        return 0
    if i in memo:
        return memo[i]
    k = min(2, (n-1)-i)
    ans = min(
        get_cost(i, i+x) + get_min_cost_from_postion(i+x) for x in range(1,k+1))

    memo[i] = ans
    return ans

ans = get_min_cost_from_postion(0)

print ans

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

n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    if j >= n:
        return 0
    return abs(h[i] - h[j])

def get_min_cost_from_postion(i):
    if i >= n-1:
        return 0
    if i in memo:
        return memo[i]
    k = min(2, (N-1)-i)
    ans = min(
        get_cost(i, i+x) + get_min_cost_from_postion(i+x) for x in range(1,k+1))

    memo[i] = ans
    return ans

ans = get_min_cost_from_postion(0)

print ans

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    return abs(h[i] - h[j])

def get_min_cost_for_postion(i):
    if i >= n-1:
        return 0
    if i == n - 2:
        return get_cost(n-2, n-1)
    if i == n - 3:
        return min(get_cost(n-3, n-2), get_cost(n-3, n-1))

    if i in memo:
        return memo[i]

    ans = min(
        get_cost(i, i+1) + get_min_cost_for_postion(i+1),
        get_cost(i, i+2) + get_min_cost_for_postion(i+2))

    memo[i] = ans
    return ans

ans = get_min_cost_for_postion(0)

print ans
Problem p03175 (python)

Fixed submission:
from collections import defaultdict
import random

import sys
sys.setrecursionlimit(100000000)

# N, W = 100, 20000
# W_V = [[random.randint(1,1000000), random.randint(1,1000)] for i in range(N)]
N = int(raw_input())
ADG_VERTICES= defaultdict(list)
panting_cache = {}
for i in range(N-1):
    u, v = map(int, raw_input().split())
    ADG_VERTICES[u].append(v)
    ADG_VERTICES[v].append(u)

BLACK_COLOR = 1
WHITE_COLOR = 0
MOD_VAL = int(1e9 + 7)
def get_ways_to_paint_vertices(parent_color, parent_vertex, vertex):
    if ADG_VERTICES[vertex] == [parent_vertex]:
        if parent_color == BLACK_COLOR:
            return 1
        else:
            return 2

    if (parent_color,  parent_vertex, vertex) in panting_cache:
        return panting_cache[parent_color,  parent_vertex, vertex]
    ans1 = 1
    ans2 = 0
    for adg_vertex in ADG_VERTICES[vertex]:
        if adg_vertex != parent_vertex:
            ans1 = (ans1 * get_ways_to_paint_vertices(WHITE_COLOR, vertex, adg_vertex)) % MOD_VAL
    if parent_color != BLACK_COLOR:
        ans2 = 1
        for adg_vertex in ADG_VERTICES[vertex]:
            if adg_vertex != parent_vertex:
                ans2 = (ans2 * get_ways_to_paint_vertices(BLACK_COLOR, vertex, adg_vertex)) % MOD_VAL

    ans = ans1 + ans2
    if ans >= MOD_VAL:
        ans -= MOD_VAL
    panting_cache[parent_color, parent_vertex, vertex] = ans

    return ans


print get_ways_to_paint_vertices(None, 0, 1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import random

import sys
sys.setrecursionlimit(100000000)

# N, W = 100, 20000
# W_V = [[random.randint(1,1000000), random.randint(1,1000)] for i in range(N)]
N = int(raw_input())
ADG_VERTICES= defaultdict(list)
panting_cache = {}
for i in range(N-1):
    u, v = map(int, raw_input().split())
    ADG_VERTICES[u].append(v)
    ADG_VERTICES[v].append(u)

BLACK_COLOR = 1
WHITE_COLOR = 0
MOD_VAL = int(1e9 + 7)
def get_ways_to_paint_vertices(parent_color, parent_vertex, vertex):
    if ADG_VERTICES[vertex] == [parent_vertex]:
        if parent_color == BLACK_COLOR:
            return 1
        else:
            return 2

    if (parent_color,  parent_vertex, vertex) in panting_cache:
        return panting_cache[parent_color,  parent_vertex, vertex]
    ans1 = 1
    ans2 = 0
    for adg_vertex in ADG_VERTICES[vertex]:
        if adg_vertex != parent_vertex:
            ans1 = (ans * get_ways_to_paint_vertices(WHITE_COLOR, vertex, adg_vertex)) % MOD_VAL
    if parent_color != BLACK_COLOR:
        ans2 = 1
        for adg_vertex in ADG_VERTICES[vertex]:
            if adg_vertex != parent_vertex:
                ans2 = (ans2 * get_ways_to_paint_vertices(BLACK_COLOR, vertex, adg_vertex)) % MOD_VAL

    ans = ans1 + ans2
    if ans >= MOD_VAL:
        ans -= MOD_VAL
    panting_cache[parent_color, parent_vertex, vertex] = ans

    return ans


print get_ways_to_paint_vertices(None, 0, 1)
Problem p03160 (python)

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

cost = [0] * n
cost[0] = 0
cost[1] = abs(heigt[1] - heigt[0])
if n == 2:
    print(cost[1])
else:
    cost[2] = abs(heigt[2] - heigt[0])
    if n == 3:
        print(cost[2])
    else:
        for i in range(3,n):
            cost[i] = min(cost[i-1] + abs(heigt[i] - heigt[i-1]),cost[i-2] + abs(heigt[i] - heigt[i-2]))

        print(cost[n-1])

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

cost = [0] * n
cost[0] = 0
cost[1] = abs(heigt[1] - heigt[0])
cost[2] = abs(heigt[2] - heigt[0])

for i in range(3,n):
    cost[i] = min(cost[i-1] + abs(heigt[i] - heigt[i-1]),cost[i-2] + abs(heigt[i] - heigt[i-2]))

print(cost[n-1])
Problem p03862 (python)

Fixed submission:
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1):
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)

Buggy submission (verdict: Runtime Error):
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1)
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)
Problem p03160 (python)

Fixed submission:
a = int(input())


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

if a == 1:
  print(0)
  exit()
dp = [0]* len(hs)


dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

for i in range(2, a):
  dp[i] = min(abs(hs[i-1]- hs[i]) + dp[i-1], abs(hs[i-2]- hs[i]) + dp[i-2] )
  
print(dp[-1])

Buggy submission (verdict: Runtime Error):
    a = input()
    hs = [int(x) for x in input().split()]
    
    if a== 1:
      return 0
    dp = [1000000000]* len(hs)
     
    if len(hs) == 1:
      print(hs[0])
      exit()
     
    dp[0] = 0
    dp[1] = abs(hs[1] - hs[0])
     
    if len(hs) == 2:
      print(dp[1])
      exit()
     
    for i in range(len(hs)-2):
      
      if i + 1 < len(hs):
      	dp[i+1] = min(abs(hs[i+1]- hs[i]), dp[i+1]) 
      if(i+2 < len(hs)):
      	dp[i+2] = min(abs(hs[i+2]- hs[i]), dp[i+2]) 
     
    print(dp[-1])

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

dp = [1000000000]* len(hs)

if len(hs) == 1:
  print(hs[0])
  exit()

dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

if len(hs) == 2:
  print(dp[1])
  exit()

for i in range(min(a-2, len(hs)-2)):
  
  if i + 1 < len(hs):
  	dp[i+1] = min(abs(hs[i+1]- hs[i]), dp[i+1]) 
  if(i+2 < len(hs)):
  	dp[i+2] = min(abs(hs[i+2]- hs[i]), dp[i+2]) 

print(dp[-1])

Buggy submission (verdict: Runtime Error):
a = raw_input()
print(a)

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
hs = raw_input()
print("20")

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
hs = [int(x) for x in raw_input().split()]
print(hs[-1])
return
if n == 1:
  return hs[0]
dp = [0]*n
dp[0] = hs[0]
dp[1] = abs(hs[1] - hs[0])
if n == 2:
  return dp[1]

for i in range(2, n):
  dp[i] = min(dp[i-1] - hs[i], dp[i-2] - hs[i])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
hs = [int(x) for x in raw_input().split()]
if n == 1:
  return hs[0]
dp = [0]*n
dp[0] = hs[0]
dp[1] = abs(hs[1] - hs[0])
if n == 2:
  return dp[1]

for i in range(2, n):
  dp[i] = min(dp[i-1] - hs[i], dp[i-2] - hs[i])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
print(123)
return 0
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
ans = 'Even' if (a * b) % 2 == 0 else 'Odd'
print(ans)

Buggy submission (verdict: Runtime Error):
3 4a, b = map(int, input().split())
ans = 'Even' if (a * b) % 2 == 0 else 'Odd'
print(ans)
Problem p03471 (python)

Fixed submission:
def solve():
    N, Y = map(int, input().split())

    for x in range(N + 1):
        for y in range(N + 1 - x):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"

if __name__=='__main__':
  print(solve())

Buggy submission (verdict: Runtime Error):
dev solve():
  n, y = map(int, input().split())
  y //= 1000
  
  for nogu in range(n + 1):
    for higu in range(n + 1 - nogu):
      yuki = n - nogu - higu
      if nogu + higu * 5 + yuki * 10 == y:
        print(yuki, higu, nogu)
        return
  print("-1 -1 -1")
  
if __name__=='__main__':
  solve()

Buggy submission (verdict: Runtime Error):

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

    for x in range(N):
        for y in range(N):
            z = N - x - y
            if z < 0:
                break

            if 10000 * x + 5000 * y + 1000 * z == Y:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"
Problem p03163 (python)

Fixed submission:
def knapsack1(weight_value, w):
    cur = [0] * (w + 1)
    nxt = [0] * (w + 1)

    for weight, value in weight_value:
        for i in range(1, weight):
            nxt[i] = cur[i]
        for i in range(weight, w + 1):
            nxt[i] = max(cur[i], cur[i - weight] + value)
        cur, nxt = nxt, cur
    return cur[w]


def main():
    n, w = [int(x) for x in input().split()]
    weight_value = [None] * n
    for i in range(n):
        weight_value[i] = [int(x) for x in input().split()]
    return knapsack1(weight_value, w)


print(main())

Buggy submission (verdict: Runtime Error):
def knapsack1(weight_value, w):
    cur = [0] * (w + 1)
    nxt = cur.copy()

    for weight, value in weight_value:
        for i in range(1, weight):
            nxt[i] = cur[i]
        for i in range(weight, w + 1):
            nxt[i] = max(cur[i], cur[i - weight] + value)
        cur, nxt = nxt, cur
    return cur[w]


def main():
    n, w = [int(x) for x in input().split()]
    weight_value = [None] * n
    for i in range(n):
        weight_value[i] = [int(x) for x in input().split()]
    return knapsack1(weight_value, w)


print(main())

Buggy submission (verdict: Runtime Error):
def knapsack1(weight_value, w):
    cur = [0] * (w + 1)
    nxt = cur.copy()

    for weight, value in weight_value:
        for i in range(1, weight):
            nxt[i] = cur[i]
        for i in range(weight, w + 1):
            nxt[i] = max(cur[i], cur[i - weight] + value)
        cur, nxt = nxt, cur
    return cur[w]


def main():
    n, w = [int(x) for x in input().split()]
    weight_value = [None] * n
    for i in range(n):
        weight_value[i] = [int(x) for x in input().split()]
    return knapsack1(weight_value, w)


print(main())
Problem p03166 (python)

Fixed submission:
from collections import defaultdict, deque


def longest_path(n, edges):
    adj_list = defaultdict(list)
    for x, y in edges:  # x -> y
        adj_list[y].append(x)

    state = [0] * n
    distances = [0] * n
    stack = deque(range(n))

    while stack:
        x = stack.pop()
        if state[x] == 0:
            state[x] = 1
            stack.append(x)
            stack.extend(adj_list[x])
        elif state[x] == 1:
            state[x] = 2
            if adj_list[x]:
                distances[x] = max(distances[y] for y in adj_list[x]) + 1

    return max(distances)


def main():
    n, m = [int(x) for x in input().split()]
    edges = [None] * m
    for i in range(m):
        edges[i] = [int(x) - 1 for x in input().split()]

    return longest_path(n, edges)


print(main())

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


def longest_path(n, edges):
    adj_list = defaultdict(list)
    for x, y in edges:  # x -> y
        adj_list[y].append(x)

    distances = [None] * n

    def dfs(x):
        if distances[x] is None:
            if adj_list[x]:
                for y in adj_list[x]:
                    dfs(y)
                distances[x] = max((distances[y] + 1 for y in adj_list[x]))
            else:
                distances[x] = 0

    for x in range(n):
        dfs(x)

    return max(distances)


def main():
    n, m = [int(x) for x in input().split()]
    edges = [None] * m
    for i in range(m):
        edges[i] = [int(x) - 1 for x in input().split()]

    return longest_path(n, edges)


print(main())

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


def longest_path(n, edges):
    adj_list = defaultdict(list)
    for x, y in edges:  # x -> y
        adj_list[y].append(x)

    distances = [None] * n

    def dfs(x):
        if distances[x] is None:
            for y in adj_list[x]:
                dfs(y)
            distances[x] = max((distances[y] + 1 for y in adj_list[x]), default=0)

    for x in range(n):
        dfs(x)

    return max(distances)


def main():
    n, m = [int(x) for x in input().split()]
    edges = [None] * m
    for i in range(m):
        edges[i] = [int(x) - 1 for x in input().split()]

    return longest_path(n, edges)


print(main())
Problem p03160 (python)

Fixed submission:
n=int(input())
c=list(map(int,input().split()))
dp=[0]
if n>1:
    dp.append(abs(c[1]-c[0]))
    for i in range(2,n):
        dp.append(min(dp[-1]+abs(c[i-1]-c[i]),dp[-2]+abs(c[i-2]-c[i])))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]
if n>1:
    dp.append(abs(c[1]-c[0]))
    for i in range(2,n):
        m=10**9+1
        for j in range(1,k+1):
            if j<n:
                m=min(m,dp[max(n-k-1,0)]+abs(c[i]-c[max(0,i-j)]))
        dp.append(m)
print(dp[-1])

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

def mincost(n,cost,dp):
    if not dp.__contains__(n):
        if n==0:
            return 0
        elif n==1:
            dp[n]=abs(cost[1]-cost[0])
            return dp[n]
        else:
            dp[n]=min(abs(cost[n]-cost[n-1])+mincost(n-1,cost,dp),abs(cost[n]-cost[n-2])+mincost(n-2,cost,dp))
            return dp[n]
    else:
        return dp[n]
    
print(mincost(N-1,L,dict()))
Problem p03161 (python)

Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]
if n>1:
    dp.append(abs(c[1]-c[0]))
    for i in range(2,n):
        m=10**9+1
        for j in range(1,k+1):
            m=min(m,dp[max(n-k-1,0)]+abs(c[i]-c[max(0,i-j)]))
        dp.append(m)
print(dp[-1])
Problem p03160 (python)

Fixed submission:
n=int(input())
k=2

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

if n<3:
    print(abs(a[0]-a[-1]))
    exit()

c=[0]*n
c[-1]=0
mini=1000000

for i in reversed(range(n-k, n-1)):
    # print(i)
    c[i]=abs(a[i]-a[n-1])
    mini=min(mini, c[i])


for i in reversed(range(n-k)):
    c[i]=min([c[t]+abs(a[i]-a[t]) for t in range(i+1, i+k+1)])

# print("?", c)

print(c[0])

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

z=[[0,0,0] for _ in range(n)]
z[0]=[a[0], b[0], c[0]]
for i in range(1, n):
    z[i][0]=max(a[i]+z[i-1][1], a[i]+z[i-1][2])
    z[i][1]=max(b[i]+z[i-1][0], b[i]+z[i-1][2])
    z[i][2]=max(c[i]+z[i-1][0], c[i]+z[i-1][1])

print(max(z[-1]))
Problem p03163 (python)

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

cf=[(0, 0)]*(n+1)

for i in range(1, n+1):
    cf[i] = tuple( map(int, input().split()) )

dp=[[0]*(we+1) for _ in range(n+1)]

best=0

for i in range(1, n+1):
    for j in range(cf[i][0]):
        dp[i][j]=dp[i-1][j]
    for j in range(cf[i][0], we+1):
        dp[i][j]=max( dp[i][j-1], dp[i-1][j], dp[i-1][j-cf[i][0]]+ cf[i][1] )
    best=max(best, dp[i][we])


print(best)

# for i in range(1, n+1): print( dp[i], '\n' )

Buggy submission (verdict: Runtime Error):
import sys

n, we = map(int, input().split())

cf=[(0, 0)]*n

cf = sorted( [[int(x) for x in sys.stdin.readline().split())] for _ in range(n)] )

dp=[0]*(we+1)

best=0
cnt=1
lim=0

for w,c in cf:
    cnt=cnt+w
    lim=min(cnt, we-w)
    for j in range(lim, -1, -1):
        if dp[j+w]<(dp[j] + c) : dp[j+w]=dp[j] + c

print(max(dp))
Problem p03167 (python)

Fixed submission:
a, b = list(map(int, input().split()))
grid = list()
grid.append([-1 for _ in range(b + 2)])
for t in range(0, a):
    grid.append([-1])
    line = list(input())
    for k in range(len(line)):
        if line[k] == '#':
            grid[t + 1] += [-1]
        else:
            grid[t + 1] += [0]
    grid[t + 1] += [-1]
grid.append([-1 for _ in range(b + 2)])
grid[1][1] = 1
for x in range(1, a + 1):
    for y in range(1, b + 1):
        if grid[x][y] > 0:
            if grid[x + 1][y] != -1:
                grid[x + 1][y] += grid[x][y]
            if grid[x][y + 1] != -1:
                grid[x][y + 1] += grid[x][y]
print(grid[-2][-2] % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
a, b = list(map(int, input().split()))
grid = list()
grid.append([-1 for _ in range(b + 2)])
for t in range(0, a):
    grid.append([-1])
    line = list(input())
    for k in range(len(line)):
        if line[k] == '#':
            grid[t + 1] += [-1]
        else:
            grid[t + 1] += [0]
    grid[t + 1] +=[-1]
grid.append([-1 for _ in range(b + 2)])
grid[1][1] = 1
for y in range(1, a + 1):
    for x in range(1, b + 1):
        if grid[x][y] > 0:
            if grid[x + 1][y] != -1:
                grid[x + 1][y] += grid[x][y]
            if grid[x][y + 1] != -1:
                grid[x][y + 1] += grid[x][y]
print(grid[-2][-2])
Problem p03160 (python)

Fixed submission:
from functools import lru_cache
import sys

sys.setrecursionlimit(10**6)

N = int(input())
h = list(map(int, input().split()))

@lru_cache(maxsize=None)
def recur(i):
    if i == N - 1:
        return 0
    return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))

print(recur(0))

# dp = [0]*(N + 1)
# for i in range(N):

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
import sys

sys.setrecursionlimit(10**5)

N = int(input())
h = list(map(int, input().split()))

@lru_cache(maxsize=None)
def recur(i):
    if i == N - 1:
        return 0
    return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))

print(recur(0))

# dp = [0]*(N + 1)
# for i in range(N):

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

N = int(input())
h = list(map(int, input().split()))

@lru_cache(maxsize=None)
def recur(i):
    if i == N - 1:
        return 0
    return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))

print(recur(0))

# dp = [0]*(N + 1)
# for i in range(N):