Lungani

Time limit: 1s Memory limit: 256MB Input: Output:

In the heart of the village of Lungani, New Year's Eve is more than just a celebration, it is a living tradition. Groups of carollers, known as cete, wander through the snowy streets performing ancient rituals like the Cerb (Deer dance), Capra (Goat dance), and the legendary Bear dance.

The village elders say the magic of the ritual only works if the members of a group stay together. This year, the village council decided to organize all performers in the central square, which can be represented as an n×mn \times m grid of cells. To preserve the tradition, the members of each group must occupy a single connected area.

Task

You are given three integers nn, mm and kk, and a sequence of integers f1,f2,,fkf_1, f_2, \ldots, f_k.

Construct an n×mn \times m matrix using values from the set {1,2,,k}\{1, 2, \ldots, k\} such that:

  1. For every ii (1ik1 \le i \le k), the value ii appears exactly fif_i times in the matrix.
  2. For every ii, the set of cells containing the value ii forms a single connected component under 4-directional adjacency (up, down, left, right).

Input data

The first line contains three integers: nn (number of rows), mm (number of columns), and kk (number of groups).

The second line contains kk integers: f1,f2,,fkf_1, f_2, \ldots, f_k, representing the number of members in each group.

Output data

Print nn lines, each containing mm space-separated integers representing the constructed matrix.

Constraints and clarifications

  • 1n,m10001 \le n, m \le 1\,000
  • 1knm1 \le k \le n \cdot m
  • 1finm1 \le f_i \le n \cdot m
  • i=1kfi=nm\sum_{i=1}^{k} f_i = n \cdot m
  • It is guaranteed that at least one valid solution always exists.
  • If multiple valid matrices exist, you may output any of them.

Example

stdin

2 3 3
2 3 1

stdout

1 1 2
3 2 2

Explanation

Value 11 occupies cells (1,1)(1,1) and (1,2)(1,2), which are adjacent. Value 22 occupies (1,3)(1,3), (2,3)(2,3) and (2,2)(2,2), which form a connected region. Value 33 appears once at (2,1)(2,1).

Log in or sign up to be able to send submissions!