Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []; B = []; C = []
for i in range(N):
    a, b, c = map(int, input().split())
    A.append(a); B.append(b); C.append(c)

dp = [[0,0,0]]*(N+1)
for i in range(N):
    dp[i+1][0] = max(dp[i][1] + A[i], dp[i][2] + A[i])
    dp[i+1][1] = max(dp[i][0] + B[i], dp[i][2] + B[i])
    dp[i+1][2] = max(dp[i][0] + C[i], dp[i][1] + C[i])
    
print(max(dp[N]))


Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        dp[i] = min(abs(h[i] - h[i-1])+dp[i-1], abs(h[i] - h[i-2])+dp[i-2])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N = int(input())
H = list(map(int, input().split()))

def rec(i):
    if i == 1:
        return 0
    if i == 2:
        return abs(H[0]-H[1])

    return min(rec(i-1)+abs(H[i-1]-H[i-2]), rec(i-2)+abs(H[i-1]-H[i-3]))
print(rec(N))


Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        dp[i] = min(abs(h[i] - h[i-1])+dp[i-1], abs(h[i] - h[i-2])+dp[i-2])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N = int(input())
H = list(map(int, input().split()))

def rec(i):
    if i == 1:
        return 0
    if i == 2:
        return abs(H[0]-H[1])

    return min(rec(i-1)+abs(H[i-1]-H[i-2]), rec(i-2)+abs(H[i-1]-H[i-3]))
print(rec(N))


Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        dp[i] = min(abs(h[i] - h[i-1])+dp[i-1], abs(h[i] - h[i-2])+dp[i-2])
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))

dp = [0]*(N+2)
for i in range(N):
    dp[i+1] = min(dp[i+1], dp[i]+abs(H[i+1]-H[i]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(H[i+2]-H[i]))
print(dp[N-1])


Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        dp[i] = min(abs(h[i] - h[i-1])+dp[i-1], abs(h[i] - h[i-2])+dp[i-2])
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [0] + [map(int, input().split())]

dp = [0]*(N+1)
dp[1] = H[1]
for i in range(2, N+1):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
print(dp[N])


Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        dp[i] = min(abs(h[i] - h[i-1])+dp[i-1], abs(h[i] - h[i-2])+dp[i-2])
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
def chmin(a, b):
    if a > b:
        a = b
N = int(input())
h = list(map(int,input().split()))
dp = [10**5] * (N+10)
for i in range(1, N):
    dp[i+1] = chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
    dp[i+2] = chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]))
print(dp[N-1])


Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        dp[i] = min(abs(h[i] - h[i-1])+dp[i-1], abs(h[i] - h[i-2])+dp[i-2])
print(dp[N-1])