Buggy python submission (verdict: Runtime Error):
import sys
import math

def dp(costs, K):
    table = [0]
    for i in range(1, len(costs)):
        min_cost = table[i-1] + abs(costs[i-1] - costs[i])
        for j in range(2, K + 1):
            jump = i - j
            if(jump >= 0):
                step = table[jump] + abs(costs[jump] - costs[i])
                min_cost = min([min_cost, step])
            else: 
                break
        table.append(min_cost)
    return table[-1]
        
def main():
    for index in range(2):
        line = input()
        if index == 0:
            K = int(line.split(" ")[1])
            continue
        costs = [int(s) for s in line.split(" ")]
        print(dp(costs, K))

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def dp(costs):
    table = [0]
    for i in range(1, len(costs)):
        if i == 1:
            table.append(table[0] + abs(costs[0] - costs[1]))
            continue
        one_step = table[i-1] + abs(costs[i-1] - costs[i])
        two_step = table[i-2] + abs(costs[i-2] - costs[i])
        table.append(min([one_step, two_step]))
    return table[-1]
        
def main():
    for index, line in enumerate(sys.stdin):
        if index == 0:
            continue
        costs = [int(s) for s in line.split(" ")]
        print(dp(costs))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import typing 
import sys

def dp(costs: typing.List[int]) -> int:
    table = [0]
    for i in range(1, len(costs)):
        if i == 1:
            table.append(table[0] + abs(costs[0] - costs[1]))
            continue
        one_step = table[i-1] + abs(costs[i-1] - costs[i])
        two_step = table[i-2] + abs(costs[i-2] - costs[i])
        table.append(min([one_step, two_step]))
    return table[-1]
        
def main():
    for index, line in enumerate(sys.stdin):
        if index == 0:
            continue
        costs = [int(s) for s in line.split(" ")]
        print(dp(costs))

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def dp(costs):
    table = [0]
    for i in range(1, len(costs)):
        if i == 1:
            table.append(table[0] + abs(costs[0] - costs[1]))
            continue
        one_step = table[i-1] + abs(costs[i-1] - costs[i])
        two_step = table[i-2] + abs(costs[i-2] - costs[i])
        table.append(min([one_step, two_step]))
    return table[-1]
        
def main():
    for index, line in enumerate(sys.stdin):
        if index == 0:
            continue
        costs = [int(s) for s in line.split(" ")]
        print(dp(costs))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import math

def dp(costs, K):
    table = [0]
    for i in range(1, len(costs)):
        min_cost = table[i-1] + abs(costs[i-1] - costs[i])
        for j in range(2, K + 1):
            jump = i - j
            if(jump >= 0):
                step = table[jump] + abs(costs[jump] - costs[i])
                min_cost = min([min_cost, step])
            else: 
                break
        table.append(min_cost)
    return table[-1]
        
def main():
    for index in range(2):
        line = input()
        if index == 0:
            K = int(line.split(" ")[1])
            continue
        costs = [int(s) for s in line.split(" ")]
        print(dp(costs, K))

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def dp(costs):
    table = [0]
    for i in range(1, len(costs)):
        if i == 1:
            table.append(table[0] + abs(costs[0] - costs[1]))
            continue
        one_step = table[i-1] + abs(costs[i-1] - costs[i])
        two_step = table[i-2] + abs(costs[i-2] - costs[i])
        table.append(min([one_step, two_step]))
    return table[-1]
        
def main():
    for index, line in enumerate(sys.stdin):
        if index == 0:
            continue
        costs = [int(s) for s in line.split(" ")]
        print(dp(costs))

if __name__ == "__main__":
    main()