let rec solve acc n = function
  | [] -> acc
  | bs ->
      let rec find i hd = function
        | [] -> raise Not_found
        | b :: tl ->
            if n < b then raise Not_found
            else
              if i <> b
              then find (i + 1) (b :: hd) tl
              else
                match solve (b :: acc) (n - 1) (List.rev_append hd tl) with
                | exception Not_found -> find (i + 1) (b :: hd) tl
                | tr -> tr in
      find 1 [] bs
let solve bs = solve [] (List.length bs) bs

let () = Scanf.scanf "%d\n" @@ fun n ->
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  try List.iter (Printf.printf "%d\n") @@ solve @@ Array.to_list bs
  with Not_found -> print_endline "-1"

