atcoder#ARC080B. [ABC069D] Grid Coloring

[ABC069D] Grid Coloring

Score : 400400 points

Problem Statement

We have a grid with HH rows and WW columns of squares. Snuke is painting these squares in colors 11, 22, ......, NN. Here, the following conditions should be satisfied:

  • For each ii (1iN1 \leq i \leq N), there are exactly aia_i squares painted in Color ii. Here, a1+a2+...+aN=HWa_1 + a_2 + ... + a_N = H W.
  • For each ii (1iN1 \leq i \leq N), the squares painted in Color ii are 4-connected. That is, every square painted in Color ii can be reached from every square painted in Color ii by repeatedly traveling to a horizontally or vertically adjacent square painted in Color ii.

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

Constraints

  • 1H,W1001 \leq H, W \leq 100
  • 1NHW1 \leq N \leq H W
  • ai1a_i \geq 1
  • a1+a2+...+aN=HWa_1 + a_2 + ... + a_N = H W

Input

Input is given from Standard Input in the following format:

HH WW

NN

a1a_1 a2a_2 ...... aNa_N

Output

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

c11c_{1 1} ...... c1Wc_{1 W}

::

cH1c_{H 1} ...... cHWc_{H W}

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

2 2
3
2 1 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 11 are not 4-connected.

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