Problem p03160 (python)

Fixed submission:
import sys

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

dp = [sys.maxsize] * n
dp[0] = 0
for i in range(n):
    for j in (i + 1, i + 2):
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]))
print(dp[n - 1], end="")

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

dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
	for j in (i+1,i+2):
         if j < n:
         	dp[j] = min(dp[j], dp[i]+abs(dp[i]-dp[j]))
print(dp[n-1],end="")

Buggy submission (verdict: Runtime Error):
def start():
    n = int(input())
    string = input()
    while string[-1] == " ":
        string = string[:-1]
    arr = [int(v) for v in string.split(" ")]
    def frog_1(i):
        if i == n - 1:
            return 0
        if i >= n:
            return float("inf")
        left = abs(arr[i] - arr[i + 1]) + frog_1(i + 1)
        right = float("inf")
        if i+2 < n:
            right = abs(arr[i] - arr[i + 2]) + frog_1(i + 2)
        return min(left, right)
    print(frog_1(0), end="")



start()

# frog_1([10,10])

Buggy submission (verdict: Runtime Error):
def start():
    n = int(input())
    arr = [int(v) for v in input().split(" ")]
    def frog_1(i):
        if i == n - 1:
            return 0
        if i >= n:
            return float("inf")
        left = abs(arr[i] - arr[i + 1]) + frog_1(i + 1)
        right = float("inf")
        if i+2 < n:
            right = abs(arr[i] - arr[i + 2]) + frog_1(i + 2)
        return min(left, right)
    print(frog_1(0), end="")



start()

# frog_1([10,10])

Buggy submission (verdict: Runtime Error):
def start():
    n = int(input())
    arr = [int(v) for v in input().split(" ")]
    dp = [-1] * (n*n)
    def frog_1(i):
        if i == n - 1:
            return 0
        if i >= n:
            return float("inf")
        if dp[i] != -1:
            return dp[i]
        left = abs(arr[i] - arr[i + 1]) + frog_1(i + 1)
        right = float("inf")
        if i+2 < n:
            right = abs(arr[i] - arr[i + 2]) + frog_1(i + 2)
        dp[i] = min(left, right)
        return min(left, right)
    print(frog_1(0), end="")



start()

# frog_1([10,10])

Buggy submission (verdict: Runtime Error):
def start():
    n = int(input())
    arr = [int(v) for v in input().split(" ")]
    dp = [-1] * 100005
    def frog_1(i):
        if i == n - 1:
            return 0
        if i >= n:
            return float("inf")
        if dp[i] != -1:
            return dp[i]
        left = abs(arr[i] - arr[i + 1]) + frog_1(i + 1)
        right = float("inf")
        if i+2 < n:
            right = abs(arr[i] - arr[i + 2]) + frog_1(i + 2)
        dp[i] = min(left, right)
        return min(left, right)
    print(frog_1(0), end="")

start()

Buggy submission (verdict: Runtime Error):
def start():
    n = int(input())
    arr = [int(v) for v in input().split(" ")]
    dp = [-1] * 100005
    def frog_1(i, arr):
        if i == n - 1:
            return 0
        if dp[i] != -1:
            return dp[i]
        left = abs(arr[i] - arr[i + 1]) + frog_1(i + 1, arr)
        right = float("inf")
        if i+2 < n:
            right = abs(arr[i] - arr[i + 2]) + frog_1(i + 2, arr)
        dp[i] = min(left, right)
        return dp[i]
    print(frog_1(0,arr), end="")



start()

# frog_1([10,10])

Buggy submission (verdict: Runtime Error):
def start():
    n = int(input())
    arr = [int(v) for v in input().split(" ")]
    dp = [-1] * n
    def frog_1(i, arr):
        if i == n - 1:
            return 0
        if dp[i] != -1:
            return dp[i]
        left = abs(arr[i] - arr[i + 1]) + frog_1(i + 1, arr)
        right = float("inf")
        if i+2 < n:
            right = abs(arr[i] - arr[i + 2]) + frog_1(i + 2, arr)
        dp[i] = min(left, right)
        return dp[i]
    print(frog_1(0,arr), end="")



start()

# frog_1([10,10])