
let usage n = 
  let list = ref [] in
  for i = 1 to n do
    list := (scanf (if i < n then "%d " else "%d") (fun x -> x))::!list
  done; List.rev !list;;

let rec print_list = function
    [x] -> print_endline (string_of_int x)
  | x::xs -> print_string ((string_of_int x) ^ " "); print_list xs

and print_ll = function
    [] -> ()
  | x::xs -> print_list x; print_ll xs;;

let rec make_list ini = function
    0 -> []
  | n -> ini :: make_list ini (n-1);;

let make_line l =
  let rec make col = function
      [] -> []
    | x::xs -> make_list col x :: make (col+1) xs
  in List.concat (make 1 l);;

let rec take n = function
    [] -> []
  | x :: rest when n = 0  -> [] 
  | x :: rest -> x :: take (n-1) rest;;

let rec drop n = function
    [] -> []
  | x :: rest when n <= 0 -> x :: drop (n-1) rest 
  | x :: rest -> drop (n-1) rest;;

let rec proc m n = function
  _ when n <= 0 || m <= 0 -> []
  | [] -> []
  | l when m mod 2 = 0 -> List.rev (take n l) :: proc (m-1) n (drop n l)
  | l when m mod 2 = 1 -> take n l :: proc (m-1) n (drop n l);;

sscanf (read_line ()) "%d %d" (fun m n ->
         scanf "%d" (fun x -> print_ll (proc m n (usage x))));;