output_description: Print the minimum possible total cost incurred.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      h_1 h_2 \ldots h_N
attempt: 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 = [99999999999] * 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 = 99999999999  # 最小の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])
  
problem_description: Statement
  
  There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
  the height of Stone i is h_i.
  
  There is a frog who is initially on Stone 1. He will repeat the following
  action some number of times to reach Stone N:
  
    * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
  
  Find the minimum possible total cost incurred before the frog reaches Stone N.
samples: [{"input": "4\n    10 30 40 20", "output": "30\n    \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n    10 10", "output": "0\n    \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n    30 10 60 10 60 50", "output": "40\n    \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]