output_description: If it is impossible to partition the integers satisfying the condition, print
  `-1`. If it is possible, print N triples in the following format:
  
      
      
      a_1 b_1 c_1
      :
      a_N b_N c_N
      
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
attempt: import numpy as np
  
  n, m = map(int, input().split())
  ro = [[0 for i in range(n)] for i in range(n)]
  lis = np.array([[int(i) for i in input().split(" ")] for i in range(m)])
  lis = lis[lis[:, 0].argsort(), :]
  for i in lis:
      l, r, c = i
      for j in range(i[0] - 1, i[1] - 1):
          for k in range(i[0], i[1]):
              if ro[j][k] == 0:
                  ro[j][k] = i[2]
                  ro[k][j] = i[2]
              else:
                  if ro[j][k] > i[2]:
                      ro[j][k] = i[2]
                      ro[k][j] = i[2]
  
  
  route_list = ro
  
  node_num = len(route_list)  # ノードの数
  
  unsearched_nodes = list(range(node_num))  # 未探索ノード
  distance = [float("inf")] * node_num  # ノードごとの距離のリスト
  previous_nodes = [
      -1
  ] * node_num  # 最短経路でそのノードのひとつ前に到達するノードのリスト
  distance[0] = 0  # 初期のノードの距離は0とする
  
  
  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 = float(
          "inf"
      )  # 最小の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 != 0:
              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  # 　ひとつ前に到達するノードのリストも更新
                  )
  
  if distance[node_num - 1] == float("inf"):
      print(-1)
  else:
      print(distance[node_num - 1])
  
problem_description: Statement
  
  Given are positive integers N and K.
  
  Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N
  triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is
  satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one
  of those triples.
  
    * For every integer i from 1 to N, a_i + b_i \leq c_i holds.
  
  If the answer is yes, construct one such partition.
samples: [{"input": "1 1", "output": "1 2 3\n    \n\n* * *"}, {"input": "3 3", "output": "-1"}]