open Printf
open Scanf

let id x = x
let tuple x y = (x, y)

let print_array w a =
  Array.iter (fun a' ->
              Array.iteri (fun i x ->
                           if i = w-1 then printf "%d\n" x
                           else printf "%d " x)
                          a') a
             
let () =
  let h, w = scanf "%d %d " tuple in
  let a = Array.make_matrix h w 0 in
  let n = scanf "%d " id in
  let rec read x ls =
    if x = 0 then (List.rev ls)
    else let d = scanf "%d " id in read (x-1) (d :: ls) in
  let cs = read n [] in
  let rec replicate x y =
    if x = 0 then []
    else y :: replicate (x-1) y in
  let rec c_ex c = function
      [] -> []
    | h :: t -> replicate h c :: c_ex (c+1) t in
  let cs' = List.concat (c_ex 1 cs) in
  let rec loop i j di cs =
    if i = h then ()
    else if di = 0 && j = w then loop (i+1) (j-1) 1 cs
    else if di = 1 && j = (-1) then loop (i+1) 0 0 cs
    else begin
        a.(i).(j) <- (List.hd cs);
        if di = 0 then loop i (j+1) 0 (List.tl cs) else loop i (j-1) 1 (List.tl cs)
      end
  in
  loop 0 0 0 cs'; print_array w a
