Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    def fr(i):
        memo = [0]*(N+1)
        if i == 1:
            return abs(h[1]-h[0])
        elif i == 0:
            return 0
        else:
            if memo[i] != 0:
                return memo[i]
            memo[i] =  min(fr(i-1)+abs(h[i]-h[i-1]),\
                        fr(i-2)+abs(h[i]-h[i-2]))
            return memo[i]

    print(fr(N-1))

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    dp = [0 for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    cost = h
    for i in range(1,N-1):
        dp[i+1] = min(dp[i]+abs(cost[i+1]-cost[i]),\
            dp[i-1]+abs(cost[i+1]-cost[i-1]))
    print(dp[-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    def fr(i):
        memo = [0]*(N+1)
        if i == 1:
            return abs(h[1]-h[0])
        elif i == 0:
            return 0
        else:
            if memo[i] != 0:
                return memo[i]
            memo[i] =  min(fr(i-1)+abs(h[i]-h[i-1]),\
                        fr(i-2)+abs(h[i]-h[i-2]))
            return memo[i]

    print(fr(N-1))

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    dp = [0 for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    cost = h
    for i in range(1,N-1):
        dp[i+1] = min(dp[i]+abs(cost[i+1]-cost[i]),\
            dp[i-1]+abs(cost[i+1]-cost[i-1]))
    print(dp[-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    def fr(i):
        if i == 1:
            return abs(h[1]-h[0])
        elif i == 0:
            return 0
        else:
            return min(fr(i-1)+abs(h[i]-h[i-1]),\
                    fr(i-2)+abs(h[i]-h[i-2]))

    print(fr(N-1))

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    dp = [0 for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    cost = h
    for i in range(1,N-1):
        dp[i+1] = min(dp[i]+abs(cost[i+1]-cost[i]),\
            dp[i-1]+abs(cost[i+1]-cost[i-1]))
    print(dp[-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    def fr(i):
        if i == 1:
            return abs(h[1]-h[0])
        elif i == 0:
            return 0
        else:
            return min(fr(i-1)+abs(h[i]-h[i-1]),\
                    fr(i-2)+abs(h[i]-h[i-2]))

    print(fr(N-1))

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    h = list(map(int,input().split()))
    dp = [0 for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    cost = h
    for i in range(1,N-1):
        dp[i+1] = min(dp[i]+abs(cost[i+1]-cost[i]),\
            dp[i-1]+abs(cost[i+1]-cost[i-1]))
    print(dp[-1])

if __name__ == "__main__":
    main()