Buggy python submission (verdict: Runtime Error):

n = int(input())
li = list(map(int,input().split()))

dp = [[-1 for i in range(1100)] for j in range(1100)]
ans = [100000]*n
ans[0] = 0
def solve(a,b,dp,li):
    # print(f"{a,b}")
    if dp[a][b] !=-1 :
        # print(f"結果{dp[a][b]}")
        return dp[a][b]
    else:
        dp[a][b] = abs(li[a]-li[b])
        # print(f"結果{a,b,dp[a][b]}")
        return dp[a][b]

for i in range(2,n+1):
    # print(i)
    if i == 2:
        dp[1][0] = abs(li[1]-li[0])
        ans[i-1] = dp[1][0]
    else:
        # print(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])
        # print(solve(i-1,i-2,dp,li),solve(i-1,i-3,dp,li))
        # print(ans[i-2],ans[i-3])
        # print(li[i-1],li[i-3])
        ans[i-1] = min(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])

print(ans[-1])
# print(dp)

Fixed submission:

n = int(input())
li = list(map(int,input().split()))

# dp = [[-1 for i in range(1100)] for j in range(1100)]
ans = [0]*n
ans[0] = 0
# def solve(a,b,dp,li):
#     if dp[a][b] !=-1 :
#         return dp[a][b]
#     else:
#         dp[a][b] = abs(li[a]-li[b])
#         return dp[a][b]

for i in range(2,n+1):
    if i == 2:
        ans[i-1]= abs(li[1]-li[0])
    else:
        ans[i-1] = min(abs(li[i-1]-li[i-2])+ans[i-2],abs(li[i-1]-li[i-3])+ans[i-3])

print(ans[-1])

Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
li = list(map(int,input().split()))

dp = [[-1 for i in range(10000)] for j in range(10000)]
ans = [100000]*n
ans[0] = 0
def solve(a,b,dp,li):
    # print(f"{a,b}")
    if dp[a][b] !=-1 :
        # print(f"結果{dp[a][b]}")
        return dp[a][b]
    else:
        dp[a][b] = abs(li[a]-li[b])
        # print(f"結果{a,b,dp[a][b]}")
        return dp[a][b]

for i in range(2,n+1):
    # print(i)
    if i == 2:
        dp[1][0] = abs(li[1]-li[0])
        ans[i-1] = dp[1][0]
    else:
        # print(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])
        # print(solve(i-1,i-2,dp,li),solve(i-1,i-3,dp,li))
        # print(ans[i-2],ans[i-3])
        # print(li[i-1],li[i-3])
        ans[i-1] = min(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])

print(ans[-1])
# print(dp)

Fixed submission:

n = int(input())
li = list(map(int,input().split()))

# dp = [[-1 for i in range(1100)] for j in range(1100)]
ans = [0]*n
ans[0] = 0
# def solve(a,b,dp,li):
#     if dp[a][b] !=-1 :
#         return dp[a][b]
#     else:
#         dp[a][b] = abs(li[a]-li[b])
#         return dp[a][b]

for i in range(2,n+1):
    if i == 2:
        ans[i-1]= abs(li[1]-li[0])
    else:
        ans[i-1] = min(abs(li[i-1]-li[i-2])+ans[i-2],abs(li[i-1]-li[i-3])+ans[i-3])

print(ans[-1])

Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
li = list(map(int,input().split()))

dp = [[-1 for i in range(10000)] for j in range(10000)]
ans = [100000]*n
ans[0] = 0
def solve(a,b,dp,li):
    # print(f"{a,b}")
    if dp[a][b] !=-1 :
        # print(f"結果{dp[a][b]}")
        return dp[a][b]
    else:
        dp[a][b] = abs(li[a]-li[b])
        # print(f"結果{a,b,dp[a][b]}")
        return dp[a][b]

for i in range(2,n+1):
    # print(i)
    if i == 2:
        dp[1][0] = abs(li[1]-li[0])
        ans[i-1] = dp[1][0]
    else:
        # print(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])
        # print(solve(i-1,i-2,dp,li),solve(i-1,i-3,dp,li))
        # print(ans[i-2],ans[i-3])
        # print(li[i-1],li[i-3])
        ans[i-1] = min(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])

print(ans[-1])
# print(dp)

Fixed submission:

n = int(input())
li = list(map(int,input().split()))

# dp = [[-1 for i in range(1100)] for j in range(1100)]
ans = [0]*n
ans[0] = 0
# def solve(a,b,dp,li):
#     if dp[a][b] !=-1 :
#         return dp[a][b]
#     else:
#         dp[a][b] = abs(li[a]-li[b])
#         return dp[a][b]

for i in range(2,n+1):
    if i == 2:
        ans[i-1]= abs(li[1]-li[0])
    else:
        ans[i-1] = min(abs(li[i-1]-li[i-2])+ans[i-2],abs(li[i-1]-li[i-3])+ans[i-3])

print(ans[-1])

Buggy python submission (verdict: Runtime Error):

n = int(input())
li = list(map(int,input().split()))

dp = [[-1 for i in range(1000)] for j in range(1000)]
ans = [100000]*n
ans[0] = 0
def solve(a,b,dp,li):
    # print(f"{a,b}")
    if dp[a][b] !=-1 :
        # print(f"結果{dp[a][b]}")
        return dp[a][b]
    else:
        dp[a][b] = abs(li[a]-li[b])
        # print(f"結果{a,b,dp[a][b]}")
        return dp[a][b]

for i in range(2,n+1):
    # print(i)
    if i == 2:
        dp[1][0] = abs(li[1]-li[0])
        ans[i-1] = dp[1][0]
    else:
        # print(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])
        # print(solve(i-1,i-2,dp,li),solve(i-1,i-3,dp,li))
        # print(ans[i-2],ans[i-3])
        # print(li[i-1],li[i-3])
        ans[i-1] = min(solve(i-1,i-2,dp,li)+ans[i-2],solve(i-1,i-3,dp,li)+ans[i-3])

print(ans[-1])
# print(dp)


Fixed submission:

n = int(input())
li = list(map(int,input().split()))

# dp = [[-1 for i in range(1100)] for j in range(1100)]
ans = [0]*n
ans[0] = 0
# def solve(a,b,dp,li):
#     if dp[a][b] !=-1 :
#         return dp[a][b]
#     else:
#         dp[a][b] = abs(li[a]-li[b])
#         return dp[a][b]

for i in range(2,n+1):
    if i == 2:
        ans[i-1]= abs(li[1]-li[0])
    else:
        ans[i-1] = min(abs(li[i-1]-li[i-2])+ans[i-2],abs(li[i-1]-li[i-3])+ans[i-3])

print(ans[-1])