Problem p03160 (python)

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy submission (verdict: Runtime Error):
import time
from memory_profiler import profile

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

suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
#@profile
def netMain():
    for e in range(2, N):
        suml[e] = min(
            abs(h[e]-h[e-1]) + suml[e-1],
            abs(h[e]-h[e-2]) + suml[e-2],
        )
 
netMain()
print(suml[N-1])

Buggy submission (verdict: Runtime Error):
import time
from memory_profiler import profile

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

suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
#@profile
def netMain():
    for e in range(2, N):
        suml[e] = min(
            abs(h[e]-h[e-1]) + suml[e-1],
            abs(h[e]-h[e-2]) + suml[e-2],
        )
 
netMain()
print(suml[N-1])

Buggy submission (verdict: Runtime Error):

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

def calc(rl, ns):
    v = rl[len(rl)-1]
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 1:
        return ns
    if lrl == 2:
        v1 = rl[len(rl)-2]
        return ns+abs(v-v1)
    if lrl == 3:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        return min(calc(rl[:len(rl)-1],ns+abs(v-v1),True),calc(rl[:len(rl)-2],ns+abs(v-v2),False))

print(calc(l,0))

Buggy submission (verdict: Runtime Error):
import copy
n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl[len(rl)-1]
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 1:
        return ns
    if lrl == 2:
        v1 = rl[len(rl)-2]
        return ns+abs(v-v1)
    if lrl == 3:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        return min(calc(rl[:len(rl)-1],ns+abs(v-v1),True),calc(rl[:len(rl)-2],ns+abs(v-v2),False))

print(calc(l,0,False))

Buggy submission (verdict: Runtime Error):
import copy

n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl[len(rl)-1]
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-2]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        return min(calc(rl[:len(rl)-1],ns+abs(v-v1),True),calc(rl[:len(rl)-2],ns+abs(v-v2),False))

print(calc(l,0,False))

Buggy submission (verdict: Runtime Error):
import copy

n = int(input())
l = list(map(int, input().split()))
#n = int(input())
#inputs = input().split(" ")
#l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl.pop(len(rl)-1)
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-1]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-1]
        v2 = rl[len(rl)-2]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        # print("lrl 2:",v1,v2,ns1,ns2,ns)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-1]
        c1 = -1
        if skip == False:
            crl = copy.copy(rl)
            c1 = calc(crl,ns+abs(v-v1),True)
        v2 = rl[len(rl)-2]
        rl.pop(len(rl)-1)
        c2 = calc(rl,ns+abs(v-v2),False)
        if (c1 == -1):
            return c2
        else:
            return min(c1,c2)

print(calc(l,0,False))

Buggy submission (verdict: Runtime Error):
import copy

n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl.pop(len(rl)-1)
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-1]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-1]
        v2 = rl[len(rl)-2]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        # print("lrl 2:",v1,v2,ns1,ns2,ns)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-1]
        c1 = -1
        if skip == False:
            crl = copy.copy(rl)
            c1 = calc(crl,ns+abs(v-v1),True)
        v2 = rl[len(rl)-2]
        rl.pop(len(rl)-1)
        c2 = calc(rl,ns+abs(v-v2),False)
        if (c1 == -1):
            return c2
        else:
            return min(c1,c2)

print(calc(l,0,False))

Buggy submission (verdict: Runtime Error):
import copy

n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns):
    v = rl.pop(len(rl)-1)
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-1]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-1]
        v2 = rl[len(rl)-2]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        # print("lrl 2:",v1,v2,ns1,ns2,ns)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-1]
        crl = copy.copy(rl)
        c1 = calc(crl,ns+abs(v-v1))
        v2 = rl[len(rl)-2]
        rl.pop(len(rl)-1)
        c2 = calc(rl,ns+abs(v-v2))
        return min(c1,c2)

print(calc(l,0))