Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
initial_vals = list(map(int, input().split(" ")))


table = [[None for x in range(n)] for x in range(n)]


def calc(from_stone, to_stone):
    if table[from_stone][to_stone] is not None:
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 1:
        table[from_stone][to_stone] = abs(
            initial_vals[from_stone] - initial_vals[to_stone]
        )
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 2:
        table[from_stone][to_stone] = min(
            abs(initial_vals[from_stone] - initial_vals[to_stone - 1])
            + abs(initial_vals[to_stone - 1] - initial_vals[to_stone]),
            abs(initial_vals[from_stone] - initial_vals[to_stone]),
        )
        return table[from_stone][to_stone]
    else:
        table[from_stone][to_stone] = min(
            calc(from_stone, to_stone - 1) + calc(to_stone - 1, to_stone),
            calc(from_stone, to_stone - 2) + calc(to_stone - 2, to_stone),
        )
        return table[from_stone][to_stone]


print(calc(0, n - 1))


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


# print(calc(0, n - 1))


arr = [0 for x in range(n)]

arr[1] = abs(initial_vals[0] - initial_vals[1])

for i in range(2, len(arr)):
    arr[i] = min(
        arr[i - 1] + abs(initial_vals[i - 1] - initial_vals[i]),
        arr[i - 2] + abs(initial_vals[i - 2] - initial_vals[i]),
    )

print(arr[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
initial_vals = list(map(int, input().split(" ")))


table = [[None for x in range(n)] for x in range(n)]

for i in range(n - 1):
    table[i][i + 1] = abs(initial_vals[i] - initial_vals[i + 1])
    if len(initial_vals) > i + 2:
        table[i][i + 2] = abs(initial_vals[i] - initial_vals[i + 2])


def calc(from_stone, to_stone):
    if table[from_stone][to_stone] is not None:
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 2:
        table[from_stone][to_stone] = min(
            table[from_stone][to_stone],
            table[from_stone][to_stone - 1] + table[to_stone - 1][to_stone],
        )
        return table[from_stone][to_stone]
    else:
        table[from_stone][to_stone] = min(
            calc(from_stone, to_stone - 1) + table[to_stone - 1][to_stone],
            calc(from_stone, to_stone - 2) + table[to_stone - 2][to_stone],
        )
        return table[from_stone][to_stone]


print(calc(0, n - 1))


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


# print(calc(0, n - 1))


arr = [0 for x in range(n)]

arr[1] = abs(initial_vals[0] - initial_vals[1])

for i in range(2, len(arr)):
    arr[i] = min(
        arr[i - 1] + abs(initial_vals[i - 1] - initial_vals[i]),
        arr[i - 2] + abs(initial_vals[i - 2] - initial_vals[i]),
    )

print(arr[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
initial_vals = list(map(int, input().split(" ")))


table = [[None for x in range(n)] for x in range(n)]

for i in range(n - 1):
    table[i][i + 1] = abs(initial_vals[i] - initial_vals[i + 1])
    if len(initial_vals) > i + 2:
        table[i][i + 2] = abs(initial_vals[i] - initial_vals[i + 2])


def calc(from_stone, to_stone):
    if (to_stone - from_stone) == 1:
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 2:
        return min(
            table[from_stone][to_stone],
            table[from_stone][to_stone - 1] + table[to_stone - 1][to_stone],
        )
    else:
        table[from_stone][to_stone] = min(
            calc(from_stone, to_stone - 1) + table[to_stone - 1][to_stone],
            calc(from_stone, to_stone - 2) + table[to_stone - 2][to_stone],
        )
        return table[from_stone][to_stone]


print(calc(0, n - 1))


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


# print(calc(0, n - 1))


arr = [0 for x in range(n)]

arr[1] = abs(initial_vals[0] - initial_vals[1])

for i in range(2, len(arr)):
    arr[i] = min(
        arr[i - 1] + abs(initial_vals[i - 1] - initial_vals[i]),
        arr[i - 2] + abs(initial_vals[i - 2] - initial_vals[i]),
    )

print(arr[n - 1])

Buggy python submission (verdict: Runtime Error):
import pysnooper
import tabulate

n = int(input())
initial_vals = list(map(int, input().split(" ")))


@pysnooper.snoop()
def calculate_paths(vals):

    if len(vals) == 3:
        return min(abs(vals[0] - vals[2]), abs(vals[0] - vals[1]))
    elif len(vals) == 2:
        return abs(vals[0] - vals[1])
    elif len(vals) > 3:
        return min(
            calculate_paths(vals[:-1]) + abs(vals[-2] - vals[-1]),
            calculate_paths(vals[:-2]) + calculate_paths(vals[-3:-1]),
        )
    else:
        print("weird:" + str(vals))


table = [[None for x in range(n)] for x in range(n)]

for i in range(n - 1):
    table[i][i + 1] = abs(initial_vals[i] - initial_vals[i + 1])
    if len(initial_vals) > i + 2:
        table[i][i + 2] = abs(initial_vals[i] - initial_vals[i + 2])


def calc(from_stone, to_stone):
    if (to_stone - from_stone) == 1:
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 2:
        return min(
            table[from_stone][to_stone],
            table[from_stone][to_stone - 1] + table[to_stone - 1][to_stone],
        )
    else:
        table[from_stone][to_stone] = min(
            calc(from_stone, to_stone - 1) + table[to_stone - 1][to_stone],
            calc(from_stone, to_stone - 2) + table[to_stone - 2][to_stone],
        )
        return table[from_stone][to_stone]


print(calc(0, n - 1))


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


# print(calc(0, n - 1))


arr = [0 for x in range(n)]

arr[1] = abs(initial_vals[0] - initial_vals[1])

for i in range(2, len(arr)):
    arr[i] = min(
        arr[i - 1] + abs(initial_vals[i - 1] - initial_vals[i]),
        arr[i - 2] + abs(initial_vals[i - 2] - initial_vals[i]),
    )

print(arr[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):


n = int(input())
initial_vals = list(map(int, input().split(" ")))

table = [[None for x in range(n)] for x in range(n)]

for i in range(n - 1):
    table[i][i + 1] = abs(initial_vals[i] - initial_vals[i + 1])

for i in range(n - 2):
    table[i][i + 2] = abs(initial_vals[i] - initial_vals[i + 2])


def calc(from_stone, to_stone):
    if (to_stone - from_stone) == 1:
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 2:
        return min(
            table[from_stone][to_stone],
            table[from_stone][to_stone - 1] + table[to_stone - 1][to_stone],
        )
    else:
        table[from_stone][to_stone] = min(
            calc(from_stone, to_stone - 1) + table[to_stone - 1][to_stone],
            calc(from_stone, to_stone - 2) + table[to_stone - 2][to_stone],
        )
        return table[from_stone][to_stone]


print(calc(0, n - 1))


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


# print(calc(0, n - 1))


arr = [0 for x in range(n)]

arr[1] = abs(initial_vals[0] - initial_vals[1])

for i in range(2, len(arr)):
    arr[i] = min(
        arr[i - 1] + abs(initial_vals[i - 1] - initial_vals[i]),
        arr[i - 2] + abs(initial_vals[i - 2] - initial_vals[i]),
    )

print(arr[n - 1])

Buggy python submission (verdict: Runtime Error):
import fileinput


def frog(stones, jump_range):
    stone_cost = [0]
    for i in range(1, len(stones)):
        stone_cost.append(min(
            stone_cost[i - curr_jmp] + abs(stones[i] - stones[i - curr_jmp])
            for curr_jmp in range(1, min(i, jump_range) + 1)
        ))
    return stone_cost[-1]


inp = fileinput.input()
jump_range = [int(v) for v in inp.readline().split(" ")][1]
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones, jump_range))

Fixed submission:
import fileinput
    
def frog(stones):
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))
    
    return stone_cost[-1]
    
    
inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones))

Buggy python submission (verdict: Runtime Error):
import fileinput


def frog(stones, jump_range):
    stone_cost = [0]
    for i in range(1, len(stones)):
        stone_cost.append(min(
            stone_cost[i - curr_jmp] + abs(stones[i] - stones[i - curr_jmp])
            for curr_jmp in range(1, min(i, jump_range) + 1)
        ))
    return stone_cost[-1]


inp = fileinput.input()
jump_range = [int(v) for v in inp.readline().split(" ")][1]
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones, jump_range))

Fixed submission:
import fileinput
    
def frog(stones):
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))
    
    return stone_cost[-1]
    
    
inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones))

Buggy python submission (verdict: Runtime Error):
import typing as tp
import fileinput
    
def frog(stones):
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))
    
    return stone_cost[-1]
    
    
inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ") if v != "\n"]
print(frog(stones))

Fixed submission:
import fileinput
    
def frog(stones):
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))
    
    return stone_cost[-1]
    
    
inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones))

Buggy python submission (verdict: Runtime Error):
import typing as tp
import fileinput
    
def frog(stones):
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))
    
    return stone_cost[-1]
    
    
inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones))

Fixed submission:
import fileinput
    
def frog(stones):
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))
    
    return stone_cost[-1]
    
    
inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones))

Buggy python submission (verdict: Runtime Error):
import typing as tp
import fileinput

def frog(stones: tp.List[int]) -> int:
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))

    return stone_cost[-1]
    

inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ")]
frog(stones)


Fixed submission:
import fileinput
    
def frog(stones):
    stone_cost = [0]
    for i in range(1, len(stones)):
        single_step_cost = abs(stones[i] - stones[i - 1])
        if i == 1:
            stone_cost.append(single_step_cost)
        else:
            double_step_cost = abs(stones[i] - stones[i - 2])
            stone_cost.append(min(single_step_cost + stone_cost[-1], double_step_cost + stone_cost[-2]))
    
    return stone_cost[-1]
    
    
inp = fileinput.input()
inp.readline()
stones = [int(v) for v in inp.readline().split(" ")]
print(frog(stones))