output_description: If there is no sequence satisfying the conditions, print `-1`. Otherwise,
  print the lexicographically smallest sequence satisfying the conditions.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      K
      a_1 a_2 \dots a_K
attempt: import numpy as np
  
  K = input()
  counts = np.array(list(map(int, input().split())))
  
  
  def subtract_count(counts: np.ndarray):
      if counts.max() == 1:
          block = np.ones_like(counts)
      else:
          block = (counts == counts.max()).astype(int) + 1
      return counts - block, block
  
  
  def block_to_str(block):
      arange = np.arange(1, len(block) + 1)
      if block.max() == 1:
          return " ".join(map(str, arange))
      twice = list(arange[block == block.max()])
      once = list(arange[block != block.max()])
      return " ".join(map(str, twice + once + twice))
  
  
  def greedy_solution(counts):
      blocks = []
      while counts.max() > 0:
          counts, block = subtract_count(counts)
          blocks.append(block)
      # print(blocks, counts)
      if counts.min() < 0:
          return -1
      sorted_strs = sorted([block_to_str(block) for block in blocks])
      return " ".join(sorted_strs)
  
  
  def solution(counts):
      candidates = []
      candidates.append(greedy_solution(counts))
      alt = np.ones_like(counts)
      alt[0] = 2
      alts = [alt]
      for alt in alts:
          alt = np.array(alt)
          sol = greedy_solution(counts - alt)
          if sol == -1:
              continue
          candidates.append(block_to_str(alt) + " " + sol)
      return sorted(candidates)[0]
  
  
  print(solution(counts))
  
problem_description: Statement
  
  Given are an integer K and integers a_1,\dots, a_K. Determine whether a
  sequence P satisfying below exists. If it exists, find the lexicographically
  smallest such sequence.
  
    * Every term in P is an integer between 1 and K (inclusive).
    * For each i=1,\dots, K, P contains a_i occurrences of i.
    * For each term in P, there is a contiguous subsequence of length K that contains that term and is a permutation of 1,\dots, K.
samples: [{"input": "3\n    2 4 3", "output": "2 1 3 2 2 3 1 2 3 \n    \n\nFor example, the fifth term, which is 2, is in the subsequence (2, 3, 1)\ncomposed of the fifth, sixth, and seventh terms.\n\n* * *"}, {"input": "4\n    3 2 3 2", "output": "1 2 3 4 1 3 1 2 4 3 \n    \n\n* * *"}, {"input": "5\n    3 1 4 1 5", "output": "-1"}]