Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)

N = int(input())
memo = [[-1]*(N-1) for i in range(N)]

def frog(h,h2,h1):
    if memo[h2][h1]  != -1:
        return memo[h2][h1]
    elif h1 <= 0:
        if memo[h2][0]  == -1:
            memo[h2][0] = abs(h[h2] - h[0])
        return memo[h2][0]
    else:
        memo[h2][h1] = min(frog(h,h1,h1-1)  + abs(h[h2]-h[h1]),frog(h,h1,h1-2)+abs(h[h2] - h[h1]))
        return memo[h2][h1]
    
   

s = input().split()

h = []
for i in range(N):
    h.append(int(s[i]))
print(min(frog(h,N-1,N-2),frog(h,N-1,N-3)))
#print(memo)

Fixed submission:
N = int(input())
h = list(map(int,input().split()))

if N ==2:
    print(abs(h[1] - h[0]))
else:
    dp = [10**4+1]*N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,N):
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i-2] + abs(h[i-2]-h[i-1]) + abs(h[i-1] - h[i]), dp[i-1]+abs(h[i-1]-h[i]))
        
    print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)

N = int(input())
memo = [[-1]*(N-1) for i in range(N)]

def frog(h,h2,h1):
    if h1 <= 0:
        if memo[h2][0]  == -1:
            memo[h2][0] = abs(h[h2] - h[0])
        return memo[h2][0]
    elif memo[h2][h1] == -1:
        memo[h2][h1] = min(frog(h,h1,h1-1)  + abs(h[h2]-h[h1]),frog(h,h1,h1-2)+abs(h[h2] - h[h1]))
        return memo[h2][h1]
    else:
        return memo[h2][h1]


s = input().split()

h = []
for i in range(N):
    h.append(int(s[i]))
print(min(frog(h,N-1,N-2),frog(h,N-1,N-3)))
#print(memo)

Fixed submission:
N = int(input())
h = list(map(int,input().split()))

if N ==2:
    print(abs(h[1] - h[0]))
else:
    dp = [10**4+1]*N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,N):
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i-2] + abs(h[i-2]-h[i-1]) + abs(h[i-1] - h[i]), dp[i-1]+abs(h[i-1]-h[i]))
        
    print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)
def frog(h,h2,h1):
    if h1 <= 0:
        return abs(h[h2] - h[0])
    else:
        return min(frog(h,h1,h1-1) + abs(h[h2] -  h[h1]),frog(h,h1,h1-2) + abs(h[h2]-h[h1]) ) 

N = int(input())
s = input().split()

h = []
for i in range(N):
    h.append(int(s[i]))

print(min(frog(h,N-1,N-2),frog(h,N-1,N-3)))

Fixed submission:
N = int(input())
h = list(map(int,input().split()))

if N ==2:
    print(abs(h[1] - h[0]))
else:
    dp = [10**4+1]*N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,N):
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i-2] + abs(h[i-2]-h[i-1]) + abs(h[i-1] - h[i]), dp[i-1]+abs(h[i-1]-h[i]))
        
    print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
def frog(h,h2,h1):
    if h1 <= 0:
        return abs(h[h2] - h[0])
    else:
        return min(frog(h,h1,h1-1) + abs(h[h2] -  h[h1]),frog(h,h1,h1-2) + abs(h[h2]-h[h1]) ) 

N = int(input())
s = input().split()
h = []
for i in range(N):
    h.append(int(s[i]))

print(min(frog(h,N-1,N-2),frog(h,N-1,N-3)))

Fixed submission:
N = int(input())
h = list(map(int,input().split()))

if N ==2:
    print(abs(h[1] - h[0]))
else:
    dp = [10**4+1]*N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,N):
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i-2] + abs(h[i-2]-h[i-1]) + abs(h[i-1] - h[i]), dp[i-1]+abs(h[i-1]-h[i]))
        
    print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
def frog(h,h2,h1):
    if h1 <= 0:
        return abs(h[h2] - h[0])
    else:
        return min(frog(h,h1,h1-1) + abs(h[h2] -  h[h1]),frog(h,h1,h1-2) + abs(h[h2]-h[h1]) ) 

N = int(input())
s = input().split()
h = []
for i in range(N):
    h.append(int(s[i]))

print(min(frog(h,N-1,N-2),frog(h,N-1,N-3)))

Fixed submission:
N = int(input())
h = list(map(int,input().split()))

if N ==2:
    print(abs(h[1] - h[0]))
else:
    dp = [10**4+1]*N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,N):
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i-2] + abs(h[i-2]-h[i-1]) + abs(h[i-1] - h[i]), dp[i-1]+abs(h[i-1]-h[i]))
        
    print(dp[N-1])