Buggy python submission (verdict: Runtime Error):
n,k=input().split()
n=int(n)
k=int(k)
s=[int(i) for i in input().split()]
dp=[]
for i in range(n):
    dp.append(10003)
dp[0] = 0
dp[1]=abs(s[0]-s[1])
for i in range(2,n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],(abs(s[i]-s[i-j])+dp[i-j]))
        else:
            break
print(dp[-1])

Fixed submission:
n=int(input())

s=input().split(' ')

s=[int(i) for i in s]

dp = [10001]*100000

dp[0] = 0

dp[1] = abs(s[1] - s[0])

for i in range(2,n):
    
    dp[i] = min(dp[i-1] + abs(s[i]-s[i-1]), dp[i-2] + abs(s[i]-s[i-2]))

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[int(x) for x in input().split(' ')]
#print(s)
t1=[]
t2=[]
for i in range(n-1):
    #t1.append(s[i+1]-s[i])
    if s[i+1] > s[i]:
        t1.append(s[i+1]-s[i])
    else:
        t1.append(s[i]-s[i+1])
    print(t1)
for i in range(n-2):
    #t2.append(s[i+2]-s[i])
    if s[i+2] > s[i]:
        t2.append(s[i+2]-s[i])
    else:
        t2.append(s[i]-s[i+2])
    print(t2)
p=max(len(t1),len(t2))
ct1,ct2=len(t1),len(t2)
sum1=0
for i in range(p):
    if ct1 == 0 or ct2 == 0:
        break
    if t1[i] > t2[i]:
        sum1+=t2[i]
    else:
        sum1+=t1[i]
    ct1-=1
    ct2-=1
print(sum1)

Fixed submission:
n=int(input())

s=input().split(' ')

s=[int(i) for i in s]

dp = [10001]*100000

dp[0] = 0

dp[1] = abs(s[1] - s[0])

for i in range(2,n):
    
    dp[i] = min(dp[i-1] + abs(s[i]-s[i-1]), dp[i-2] + abs(s[i]-s[i-2]))

print(dp[n-1])

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

def jump(k: int, h, res):
    if ( k == 0 ):
        return 0

    if ( res[k] == -1 ):
        res[k] = jump(k - 1, h, res) + abs(h[k] - h[k - 1])
        if k >= 2:
            res[k] = min(res[k], jump(k - 2, h, res) + abs(h[k] - h[k - 2]))

    return res[k]


def main():
    #lines = []
    #for line in sys.stdin:
    #    lines.append([int(i) for i in line.strip().split(' ')])

    #n = int(lines[0][0])
    #h = lines[1]
    n = int(input())
    h = list(map(int, input().split(" ")))

    res = [ -1 ] * len(h)
    print(jump(n-1, h, res))


if __name__ == '__main__':
    main()


Fixed submission:
def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)

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

def jump(k: int, h, res):
    if ( k == 0 ):
        return 0

    if ( res[k] == -1 ):
        res[k] = jump(k - 1, h, res) + abs(h[k] - h[k - 1])
        if k >= 2:
            res[k] = min(res[k], jump(k - 2, h, res) + abs(h[k] - h[k - 2]))

    return res[k]
   

def main():
    #lines = []
    #for line in sys.stdin:
    #    lines.append([int(i) for i in line.strip().split(' ')])

    #n = int(lines[0][0])
    #h = lines[1]
    n = int(input())
    h = list(map(int, input().split(" ")))

    res = [ -1 ] * len(h)
    print(jump(n-1, h, res))


if __name__ == '__main__':
    main()


Fixed submission:
def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)

Buggy python submission (verdict: Runtime Error):
    def calc_cost(h):
        if (len(h) == 0):
            return 0
     
        cost = [None] * len(h)
        cost[0] = 0
        for i in range(1, len(h)):
            cost[i] = cost[i-1] + abs(h[i] - h[i-1])
            if i>1:
                cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))
     
        return cost[len(h)-1]
     
    if __name__ == "__main__":
        n = int(input())
        h = list(map(int, input().split(" ")))
        res = calc_cost(h)
        print(res)

Fixed submission:
def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)

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

def jump(k: int, h, res):
    if ( k == 0 ):
        return 0

    if ( res[k] == -1 ):
        res[k] = jump(k - 1, h, res) + abs(h[k] - h[k - 1])
        if k >= 2:
            res[k] = min(res[k], jump(k - 2, h, res) + abs(h[k] - h[k - 2]))

    return res[k]

def main():
    #lines = []
    #for line in sys.stdin:
    #    lines.append([int(i) for i in line.strip().split(' ')])

    #n = int(lines[0][0])
    #h = lines[1]
    n = int(input())
    h = list(map(int, input().split(" ")))

    res = [ -1 for i in range(n)]
    print(jump(n-1, h, res))


if __name__ == '__main__':
    main()

Fixed submission:
def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)

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

def jump(k: int, h, res):
    if ( k == 0 ):
        return 0

    if ( res[k] == -1 ):
        res[k] = jump(k - 1, h, res) + abs(h[k] - h[k - 1])
        if k >= 2:
            res[k] = min(res[k], jump(k - 2, h, res) + abs(h[k] - h[k - 2]))

    return res[k]

def main():
    lines = []
    for line in sys.stdin:
        lines.append([int(i) for i in line.strip().split(' ')])

    n = int(lines[0][0])
    h = lines[1]
    res = [ -1 for i in range(n)]
    print(jump(n-1, h, res))


if __name__ == '__main__':
    main()

Fixed submission:
def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)

Buggy python submission (verdict: Runtime Error):
## tasks https://atcoder.jp/contests/dp/tasks

def solution():
    # result array for calculation for optimal cost for every stone
    res = [None]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1] + abs(h[i]-h[i-1]), res[i-2] + abs(h[i]-h[i-2]))

    return res[-1]

if __name__ == "__main__":
    n = int(raw_input())

    # global scope actually
    h = list(map(int, raw_input().split(" ")))
    #print("h = {}".format(h))

    print(solution())

Fixed submission:
## tasks https://atcoder.jp/contests/dp/tasks

def solution():
    # result array for calculation for optimal cost for every stone
    res = [None]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1] + abs(h[i]-h[i-1]), res[i-2] + abs(h[i]-h[i-2]))

    return res[-1]

if __name__ == "__main__":
    n = int(input())

    # global scope actually
    h = list(map(int, input().split(" ")))

    print(solution())

Buggy python submission (verdict: Runtime Error):
def solution(k):
    #print("solution({}) = ?".format(k))
    if k == 0:
        return 0

    result = None
    if res[k]:
        result = res[k]
    elif k >= 2:
            result = min(solution(k-1) + abs(h[k]-h[k-1]), solution(k-2) + abs(h[k]-h[k-2]))
    else:
        # the case for k == 1 actually, only one of such
        result = solution(k-1) + abs(h[k]-h[k-1])
    res[k] = result

    #print("solution({}) = {}".format(k, result))
    return result

if __name__ == "__main__":
    n = int(raw_input())

    # global scope actually
    h = list(map(int, raw_input().split(" ")))
    #print("h = {}".format(h))

    # result array for calculation for optimal cost for every stone
    res = [None]*n

    solution(n-1)

    #last element
    print(res[-1])


Fixed submission:
## tasks https://atcoder.jp/contests/dp/tasks

def solution():
    # result array for calculation for optimal cost for every stone
    res = [None]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1] + abs(h[i]-h[i-1]), res[i-2] + abs(h[i]-h[i-2]))

    return res[-1]

if __name__ == "__main__":
    n = int(input())

    # global scope actually
    h = list(map(int, input().split(" ")))

    print(solution())