Problem:
Score : 400 points

Problem Statement

We have a grid with H rows and W columns of squares.
Snuke is painting these squares in colors 1, 2, ..., N.
Here, the following conditions should be satisfied:

For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W.

For each i (1 ≤ i ≤ N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.

Constraints

1 ≤ H, W ≤ 100

1 ≤ N ≤ H W

a_i ≥ 1

a_1 + a_2 + ... + a_N = H W

Input

Input is given from Standard Input in the following format:

H W
N
a_1 a_2 ... a_N

Output

Print one way to paint the squares that satisfies the conditions.
Output in the following format:

c_{1 1} ... c_{1 W}
:
c_{H 1} ... c_{H W}

Here, c_{i j} is the color of the square at the i-th row from the top and j-th column from the left.

Sample Input 1

2 2
3
2 1 1

Sample Output 1

1 1
2 3

Below is an example of an invalid solution:

1 2
3 1

This is because the squares painted in Color 1 are not 4-connected.

Sample Input 2

3 5
5
1 2 3 4 5

Sample Output 2

1 4 4 4 3
2 5 4 5 3
2 5 5 5 3

Sample Input 3

1 1
1
1

Sample Output 3

1

Solution in OCaml (4.02.3) (judge verdict: Runtime Error)

open Scanf
open Printf
open String;;

(* sscanf (read_line ()) "%d %d" 
   (fun x y -> printf "%d" ((x-1)*(y-1)));; *)



(* let abb s = (sub s 0 1) 
            ^ (string_of_int (length s - 2))
            ^ (sub s (length s - 1) 1);;

sscanf (read_line ()) "%s"
          (fun s -> printf "%s" (abb s));; *)

(*

let judge l =
  let len = List.length l in
  let f l = List.fold_left 
              (fun (x,l') y -> if y mod 4==0 then (x+1,l') else (x,y::l')) (0,[]) l in
  let g l = List.fold_left (fun x y -> x + if y mod 2!=0 then 1 else 0) 0 l in
  let (four, fourl) = f l in
  four >= len/2 || g fourl <= four

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;;

sscanf (read_line ()) "%d" 
   (fun x -> printf "%s" (if judge (usage x) then "Yes" else "No"));;

*)

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))));;