Problem p03160 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)
N = int(input())
h = [int(i) for i in input().split()]
cost = [-1]*N
def jump_min(n):
    if n == 1:
        v = 0
    elif n == 2:
        v = abs(h[1]-h[0])
    else:
        if cost[n-1] != -1:
            v = cost[n-1]
        else:
            x = jump_min(n-2)+abs(h[n-1]-h[n-3])
            y = jump_min(n-1)+abs(h[n-1]-h[n-2])
            v = min(x,y)
    cost[n-1] = v
    return v
print(jump_min(N))

Buggy submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]
def jump_min(n):
    if n == 1:
        v = 0
    elif n == 2:
        v = abs(h[1]-h[0])
    else:
        x = jump_min(n-2)+abs(h[n-1]-h[n-3])
        y = jump_min(n-1)+abs(h[n-1]-h[n-2])
        v = min(x,y)
    return v
print(jump_min(N))

Buggy submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]
cost = [-1]*N
def jump_min(n):
    global cost
    if n == 1:
        v = 0
    elif n == 2:
        v = abs(h[1]-h[0])
    else:
        if cost[n-1] != -1:
            v = cost[n-1]
        else:
            x = jump_min(n-2)+abs(h[n-1]-h[n-3])
            y = jump_min(n-1)+abs(h[n-1]-h[n-2])
            v = min(x,y)
    cost[n-1] = v
    return v
print(jump_min(N))

Buggy submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]
cost = [-1]*N
func_count = 0
def jump_min(n):
    global func_count,cost
    func_count += 1
    if n == 1:
        v = 0
    elif n == 2:
        v = abs(h[1]-h[0])
    else:
        if cost[n-1] != -1:
            v = cost[n-1]
        else:
            x = jump_min(n-2)+abs(h[n-1]-h[n-3])
            y = jump_min(n-1)+abs(h[n-1]-h[n-2])
            v = min(x,y)
    cost[n-1] = v
    return v
print(jump_min(N))
print(func_count)

Buggy submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]
cost = [-1]*N
def jump_min(n):
    if n == 1:
        v = 0
    elif n == 2:
        v = abs(h[1]-h[0])
    else:
        if cost[n-1] != -1:
            v = cost[n-1]
        else:
            x = jump_min(n-2)+abs(h[n-1]-h[n-3])
            y = jump_min(n-1)+abs(h[n-1]-h[n-2])
            v = min(x,y)
    cost[n-1] = v
    return v
print(jump_min(N))

Buggy submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]
cost = [-1]*N
def jump_min(n):
    if n == 1:
        v = 0
    elif n == 2:
        v = abs(h[1]-h[0])
    else:
        if cost[n-1] != -1:
            v = cost[n-1]
        else:
            x = jump_min(n-2)+abs(h[n-1]-h[n-3])
            y = jump_min(n-1)+abs(h[n-1]-h[n-2])
            v = min(x,y)
    cost[n-1] = v
    return v
print(jump_min(N))

Buggy submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]
cost = [-1]*(N+1)
def jump_min(n):
    if n == 1:
        v = 0
    elif n == 2:
        v = abs(h[1]-h[0])
    else:
        if cost[n-1] != -1:
            v = cost[n-1]
        else:
            x = jump_min(n-2)+abs(h[n-1]-h[n-3])
            y = jump_min(n-1)+abs(h[n-1]-h[n-2])
            v = min(x,y)
    cost[n-1] = v
    return v
print(jump_min(N))