Buggy python submission (verdict: Runtime Error):
def solve(ashiba, N, K):
    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(1, len(ashiba)):
        paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]
        dp[i] = min(paths)
    return dp[-1]


N, K = map(int, input().split())
ashiba = [int(i) for i in input().split()]
ans = solve(ashiba, N, K)
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
"""
https://atcoder.jp/contests/dp/tasks/dp_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, ashiba):
    dp = [0] * N
    for i in range(1, N):
        dp[i] = min(dp[i-1] + abs(ashiba[i] - ashiba[i-1]), dp[i-2] + abs(ashiba[i] - ashiba[max(i-2, 0)]))
    return dp[-1]


def main(args):
    N = int(input())
    ashiba = [int(a) for a in input().split()]
    ans = solve(N, ashiba)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
AC
"""
import sys
from sys import stdin


def solve(ashiba, N, K):
    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(1, len(ashiba)):
        paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]
        dp[i] = min(paths)
    return dp[-1]


def main(args):
    N, K = map(int, input().split())
    ashiba = [int(i) for i in input().split()]
    ans = solve(ashiba, N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
https://atcoder.jp/contests/dp/tasks/dp_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, ashiba):
    dp = [0] * N
    for i in range(1, N):
        dp[i] = min(dp[i-1] + abs(ashiba[i] - ashiba[i-1]), dp[i-2] + abs(ashiba[i] - ashiba[max(i-2, 0)]))
    return dp[-1]


def main(args):
    N = int(input())
    ashiba = [int(a) for a in input().split()]
    ans = solve(N, ashiba)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
https://atcoder.jp/contests/dp/tasks/dp_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, ashiba):
    dp = [0] * N
    for i in range(1, N):
        dp[i] = min(dp[i-1] + abs(ashiba[i] - ashiba[i-1]), dp[i-2] + abs(ashiba[i] - ashiba[max(i-2, 0)]))
    return dp[-1]


import numpy as np

def main(args):
    N = int(input())
    ashiba = [int(a) for a in input().split()]
    if N <= 50000:
        ans = solve(N, ashiba)
    else:
        route_list=np.zeros((N, N))
        ans = 0
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
https://atcoder.jp/contests/dp/tasks/dp_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, ashiba):
    dp = [0] * N
    for i in range(1, N):
        dp[i] = min(dp[i-1] + abs(ashiba[i] - ashiba[i-1]), dp[i-2] + abs(ashiba[i] - ashiba[max(i-2, 0)]))
    return dp[-1]


def main(args):
    N = int(input())
    ashiba = [int(a) for a in input().split()]
    ans = solve(N, ashiba)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])