Buggy python submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
import sys
sys.setrecursionlimit(1000000000)
node_num = int(input())
nodes=input().split()




route_list=np.zeros((node_num,node_num))


mi_count=0
for i in range(node_num-1):
    if i+2<node_num:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.000000001
        route_list[i][i+2]=abs(int(nodes[i+2])-int(nodes[i])) if abs(int(nodes[i+2])-int(nodes[i])) != 0 else 0.000000001
    else:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.000000001


route_list = csr_matrix(route_list)
#print(route_list)
dist_matrix= dijkstra(csgraph=route_list, directed=False, indices=0, return_predecessors=False)

dis=dist_matrix[-1]

print(int(dis))

Fixed submission:
N = int(input())
H = [0] + [int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i - 1] - H[i]), dp[i - 2] + abs(H[i - 2] - H[i]))

print(dp[N])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
node_num = int(input())
nodes=input().split()




route_list=np.zeros((node_num,node_num))


mi_count=0
for i in range(node_num-1):
    if i+2<node_num:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001
        route_list[i][i+2]=abs(int(nodes[i+2])-int(nodes[i])) if abs(int(nodes[i+2])-int(nodes[i])) != 0 else 0.0000001
    else:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001


route_list = csr_matrix(route_list)
#print(route_list)
dist_matrix= dijkstra(csgraph=route_list, directed=False, indices=0, return_predecessors=False)

dis=dist_matrix[-1]

print(int(dis))

Fixed submission:
N = int(input())
H = [0] + [int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i - 1] - H[i]), dp[i - 2] + abs(H[i - 2] - H[i]))

print(dp[N])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

node_num = int(input())
nodes=input().split()



for _ in range(node_num):
    route_list=[ 99999 for _ in range(node_num)]


mi_count=0
for i in range(node_num-1):
    if i+2<node_num:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001
        route_list[i][i+2]=abs(int(nodes[i+2])-int(nodes[i])) if abs(int(nodes[i+2])-int(nodes[i])) != 0 else 0.0000001
    else:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001


route_list = csr_matrix(route_list)
#print(route_list)
dist_matrix= dijkstra(csgraph=route_list, directed=False, indices=0, return_predecessors=False)

dis=dist_matrix[-1]

print(int(dis))

Fixed submission:
N = int(input())
H = [0] + [int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i - 1] - H[i]), dp[i - 2] + abs(H[i - 2] - H[i]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

node_num = int(input())
nodes=input().split()

route_list=[]

for _ in range(node_num):
    route_list.append([ 99999 for _ in range(node_num)])


mi_count=0
for i in range(node_num-1):
    if i+2<node_num:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001
        route_list[i][i+2]=abs(int(nodes[i+2])-int(nodes[i])) if abs(int(nodes[i+2])-int(nodes[i])) != 0 else 0.0000001
    else:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001


route_list = csr_matrix(route_list)
#print(route_list)
dist_matrix= dijkstra(csgraph=route_list, directed=False, indices=0, return_predecessors=False)

dis=dist_matrix[-1]

print(int(dis))

Fixed submission:
N = int(input())
H = [0] + [int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i - 1] - H[i]), dp[i - 2] + abs(H[i - 2] - H[i]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

node_num = int(input())
nodes=input().split()

route_list=[]

for _ in range(node_num):
    route_list.append([ 99999 for _ in range(node_num)])

zero_node=[]
mi_count=0
for i in range(node_num-1):
    if i+2<node_num:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001
        route_list[i][i+2]=abs(int(nodes[i+2])-int(nodes[i])) if abs(int(nodes[i+2])-int(nodes[i])) != 0 else 0.0000001
        if route_list[i][i+1]==1 or route_list[i][i+2]==0.0000001:
            zero_node.append(i)
    else:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i])) if abs(int(nodes[i+1])-int(nodes[i])) != 0 else 0.0000001
        if route_list[ i ][ i + 1 ] == 0.0000001:
            zero_node.append(i)

route_list = csr_matrix(route_list)
#print(route_list)
dist_matrix, predecessors = dijkstra(csgraph=route_list, directed=False, indices=0, return_predecessors=True)

dis=dist_matrix[-1]

print(int(dis))

Fixed submission:
N = int(input())
H = [0] + [int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i - 1] - H[i]), dp[i - 2] + abs(H[i - 2] - H[i]))

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
import math

route_list = [[0, 50, 80, 0, 0], [0, 0, 20, 15, 0 ], [0, 0, 0, 10, 15], [0, 0, 0, 0, 30], [0, 0, 0, 0, 0]] # 初期のノード間の距離のリスト

node_num = int(input())
nodes=input().split()

route_list=[]

for _ in range(node_num):
    route_list.append([ -1 for _ in range(node_num)])

for i in range(node_num-1):
    if i+2<node_num:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i]))
        route_list[i][i+2]=abs(int(nodes[i+2])-int(nodes[i]))
    else:
        route_list[i][i+1]=abs(int(nodes[i+1])-int(nodes[i]))

#print(route_list)


unsearched_nodes = list(range(node_num)) # 未探索ノード
distance = [100000000] * node_num # ノードごとの距離のリスト
previous_nodes = [-1] * node_num # 最短経路でそのノードのひとつ前に到達するノードのリスト
distance[0] = 0 # 初期のノードの距離は0とする

# @GDaigo さんのコメントより関数の追加 2017/03/18
def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1

while(len(unsearched_nodes) != 0): #未探索ノードがなくなるまで繰り返す
    # まず未探索ノードのうちdistanceが最小のものを選択する
    posible_min_distance = 100000000# 最小のdistanceを見つけるための一時的なdistance。初期値は inf に設定。
    for node_index in unsearched_nodes: # 未探索のノードのループ
        if posible_min_distance > distance[node_index]: 
            posible_min_distance = distance[node_index] # より小さい値が見つかれば更新
    target_min_index = get_target_min_index(posible_min_distance, distance, unsearched_nodes) # 未探索ノードのうちで最小のindex番号を取得
    unsearched_nodes.remove(target_min_index) # ここで探索するので未探索リストから除去

    target_edge = route_list[target_min_index] # ターゲットになるノードからのびるエッジのリスト
    for index, route_dis in enumerate(target_edge):
        if route_dis != -1:
            if distance[index] > (distance[ target_min_index] + route_dis):
                distance[index] = distance[ target_min_index] + route_dis # 過去に設定されたdistanceよりも小さい場合はdistanceを更新
                previous_nodes[index] =  target_min_index #　ひとつ前に到達するノードのリストも更新

# 以下で結果の表示
"""
print("-----経路-----")
previous_node = node_num - 1
while previous_node != -1:
    if previous_node !=0:
        print(str(previous_node + 1) + " <- ", end='')
    else:
        print(str(previous_node + 1))
    previous_node = previous_nodes[previous_node]

print("-----距離-----")
"""
print(distance[node_num - 1])

Fixed submission:
N = int(input())
H = [0] + [int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i - 1] - H[i]), dp[i - 2] + abs(H[i - 2] - H[i]))

print(dp[N])