AtCoder Regular Contest 080 - Grid Coloring

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.

Examples

Input

2 2
3
2 1 1


Output

1 1
2 3


Input

3 5
5
1 2 3 4 5


Output

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


Input

1 1
1
1


Output

1

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
p = list()
for i in range(n):
	p.extend([i + 1 for j in range(a[i])])
for i in range(h):
	if i % 2 == 0:
		print(*p[i * w:i * w + w])
	else:
		print(*p[i * w:i * w + w][::-1])


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
S = []
for k in range(N):
	for l in range(A[k]):
		S.append(k + 1)
for i in range(H):
	if i % 2 == 0:
		print(*S[i * W:i * W + W])
	elif i % 2 == 1:
		print(*S[i * W + W - 1:i * W - 1:-1])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
cam = []
for i in range(n):
	cam.extend([str(i + 1)] * a[i])
for i in range(h):
	if i % 2 == 0:
		print(*cam[i * w:(i + 1) * w])
	else:
		print(*cam[(i + 1) * w - 1:i * w - 1:-1])


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
M = [[0 for _ in range(W)] for _ in range(H)]
i = 0
j = 0
dj = 1
k = 0
l = 0
while l < H * W:
	if A[k] == 0:
		k += 1
	M[i][j] = k + 1
	A[k] -= 1
	j += dj
	if j > W - 1:
		j = W - 1
		dj = -1
		i += 1
	elif j < 0:
		j = 0
		dj = 1
		i += 1
	l += 1
for m in M:
	print(*m)


(h, w) = map(int, input().split())
n = int(input())
alist = list(map(int, input().split()))
cmap = [[-1 for _ in range(w)] for _ in range(h)]
i = 0
for (ai, a) in enumerate(alist):
	ai += 1
	for _a in range(a):
		if (i + _a) // w % 2 == 0:
			cmap[(i + _a) // w][(i + _a) % w] = ai
		else:
			cmap[(i + _a) // w][-((i + _a) % w + 1)] = ai
	i += a
for cm in cmap:
	print(*cm, sep=' ')


(h, w) = map(int, input().split())
n = int(input())
L = list(map(int, input().split()))
li = []
for i in range(n):
	for j in range(L[i]):
		li.append(i + 1)
l = h * w - len(li)
li = li + [0] * l
ans = []
for i in range(h):
	ans.append(li[i * w:(i + 1) * w])
for i in range(h - 1):
	if ans[i][-1] == ans[i + 1][0]:
		ans[i + 1] = ans[i + 1][::-1]
for i in range(h):
	print(*ans[i])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
p = 1
k = 0
s = 0
for i in range(h):
	c = ''
	for j in range(w):
		if i % 2 == 1:
			c = str(p) + ' ' + c
		else:
			c += str(p) + ' '
		k += 1
		if a[p - 1] == k:
			p += 1
			k = 0
	else:
		print(c[:-1])


(h, w, n, *a) = map(int, open(0).read().split())
b = []
for i in range(n):
	b += [i + 1] * a[i]
for i in range(0, h * w, w):
	if i // w % 2 == 1:
		print(*b[i:i + w])
	else:
		print(*b[i:i + w][::-1])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = []
c = 0
cnt = 0
flg = True
for i in range(h):
	t = []
	for j in range(w):
		if a[c] <= cnt:
			c += 1
			cnt = 0
		if flg:
			t.append(c + 1)
		else:
			t.insert(0, c + 1)
		cnt += 1
	flg = not flg
	ans.append(t)
for i in ans:
	print(' '.join(list(map(str, i))))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
maze = [[0] * w for i in range(h)]
for i in range(h):
	for j in range(w):
		maze[i][j] = n
		a[n - 1] -= 1
		if a[n - 1] == 0:
			a.pop(-1)
			n -= 1
for i in range(h):
	if i % 2 == 1:
		print(*maze[i][::-1])
	else:
		print(*maze[i])


(h, w) = map(int, input().split())
n = int(input())
lis = list(map(int, input().split()))
ans = []
cnt = 0
s = ''
hh = 0
for i in range(n):
	for j in range(lis[i]):
		if hh == 0:
			s = s + str(i + 1) + ' '
		else:
			s = str(i + 1) + ' ' + s
		cnt += 1
		if cnt == w:
			ans.append(s)
			s = ''
			cnt = 0
			hh = (hh + 1) % 2
for i in range(h):
	print(ans[i])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = []
for (i, ai) in enumerate(a, 1):
	ans += [i] * ai
for i in range(h):
	tmp = ans[i * w:(i + 1) * w]
	if i % 2 == 0:
		print(' '.join(map(str, tmp)))
	else:
		print(' '.join(map(str, tmp[::-1])))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
i = 0
ans = [[0 for _ in range(w)] for _ in range(h)]
for j in range(n):
	for _ in range(a[j]):
		hi = i // w
		if hi % 2 == 0:
			ans[hi][i % w] = j + 1
		else:
			ans[hi][w - 1 - i % w] = j + 1
		i += 1
for ansi in ans:
	for j in range(w - 1):
		print(ansi[j], end=' ')
	print(ansi[w - 1])


from collections import Counter
(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
c = [[0 for _ in range(W)] for _ in range(H)]
b = []
for (i, num) in enumerate(a):
	b += num * [i + 1]
for i in range(H):
	for j in range(W):
		if i % 2 == 0:
			c[i][j] = b[W * i + j]
		else:
			c[i][j] = b[W * (i + 1) - 1 - j]
	print(*c[i])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	ans += [i + 1] * a[i]
for hi in range(h):
	if hi % 2 == 0:
		print(*ans[hi * w:hi * w + w])
	else:
		print(*ans[hi * w:hi * w + w][::-1])


(h, w) = map(int, input().split())
n = int(input())
a = [int(i) for i in input().split()]
c = [0 for _ in range(h * w)]
x = 0
for i in range(1, n + 1):
	c[x:x + a[i - 1]] = [i] * a[i - 1]
	x += a[i - 1]
for i in range(0, h):
	if i % 2 == 0:
		for j in range(w * i, w * (i + 1)):
			print(c[j], end=' ')
	else:
		for j in range(w * (i + 1) - 1, w * i - 1, -1):
			print(c[j], end=' ')
	print()


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = [[0] * w for _ in range(h)]
ai = 0
for i in range(h):
	(f, e, s) = (0, w, 1)
	if i % 2:
		(f, e, s) = (w - 1, -1, -1)
	for j in range(f, e, s):
		ai += a[ai] <= 0
		a[ai] -= 1
		c[i][j] = ai + 1
for l in c:
	print(*l)


(h, w) = map(int, input().split())
n = int(input())
alst = list(map(int, input().split()))
c = [[0 for _ in range(w)] for _ in range(h)]
num = 0
apos = 0
for pos in range(h * w):
	x = pos // w
	y = pos % w
	if x % 2 == 1:
		y = w - y - 1
	c[x][y] = apos + 1
	num += 1
	if alst[apos] == num:
		apos += 1
		num = 0
for lst in c:
	print(*lst)


(H, W) = list(map(int, input().split()))
N = int(input())
A = list(map(int, input().split()))
b = []
for (idx, a) in enumerate(A):
	for i in range(a):
		b += [idx + 1]
for i in range(H):
	subset = b[i * W:(i + 1) * W]
	if i % 2 == 1:
		subset = list(reversed(subset))
	string = ' '.join(list(map(str, subset)))
	print(string.strip())


(H, W, N, *A) = map(int, open(0).read().split())
C = []
for (i, a) in enumerate(A, 1):
	C += [i] * a
for (i, r) in enumerate(zip(*[iter(C)] * W)):
	print(*r[::1 - 2 * (i % 2)])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
l = []
for (i, m) in enumerate(a, 1):
	l += [i] * m
for i in range(h):
	k = l[:w]
	l = l[w:]
	if i & 1:
		k.reverse()
	print(*k)


from collections import deque
(H, W) = map(int, input().split())
N = int(input())
tmp = 0
rlt = []
h = deque([])
As = list(map(int, input().split()))
for (k, i) in enumerate(As):
	for _ in range(i):
		tmp += 1
		if (tmp - 1) // W % 2 == 0:
			h.append(k + 1)
		else:
			h.appendleft(k + 1)
		if tmp % W == 0:
			rlt.append(h)
			h = deque([])
for q in rlt:
	print(' '.join(map(str, q)))


(H, W) = map(int, input().split())
N = int(input())
(*A,) = map(int, input().split())
C = []
for (i, a) in enumerate(A, 1):
	C += [i] * a
for i in range(H):
	if i % 2 == 0:
		print(*C[i * W:i * W + W])
	else:
		print(*C[i * W:i * W + W][::-1])


(H, W, N, *a) = map(int, open(0).read().split())
O = [[0] * W for _ in range(H)]
i = 0
for j in range(N):
	for k in range(a[j]):
		w = i % W if i // W % 2 else W - 1 - i % W
		O[i // W][w] = str(j + 1)
		i += 1
for i in range(H):
	print(' '.join(O[i]))


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
a = [[0] * W for i in range(H)]
(r, c) = (0, 0)
x = 1
for i in range(H * W):
	a[r][c] = x
	A[x - 1] -= 1
	if A[x - 1] == 0:
		x += 1
	if (r % 2 == 0 and c == W - 1 or (r % 2 == 1 and c == 0)) and r < H - 1:
		r += 1
	elif r % 2 == 0:
		c += 1
	else:
		c -= 1
for l in a:
	print(' '.join(map(str, l)))


(h, w, n, *A) = map(int, open(0).read().split())
c = []
for i in range(n):
	c += [i + 1] * A[i]
for i in range(h):
	print(*c[i * w:-~i * w][::(-1) ** i])


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
C = [[0] * w for _ in range(h)]
idx = 0
for _h in range(h):
	if _h % 2 == 0:
		loop = list(range(w))
	else:
		loop = list(range(w - 1, -1, -1))
	for _w in loop:
		C[_h][_w] = idx + 1
		A[idx] -= 1
		if A[idx] == 0:
			idx += 1
for c in C:
	print(' '.join([str(_c) for _c in c]))


import itertools
(H, W) = map(int, input().split())
N = int(input())
a = itertools.chain(*(itertools.repeat(i + 1, cnt) for (i, cnt) in enumerate(map(int, input().split()))))
for h in range(H):
	it = map(str, itertools.islice(a, W))
	if h % 2 == 1:
		it = reversed(list(it))
	print(' '.join(it))


(H, W, N, *a) = map(int, open(0).read().split())
O = []
for i in range(N):
	O += [i + 1] * a[i]
for i in range(H):
	print(*O[W * i:W * -~i][::(-1) ** i])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0] * w for _ in range(h)]
color = 0
cnt = 0
for i in range(h):
	for j in range(w):
		if i % 2 == 0:
			cnt += 1
			ans[i][j] = color + 1
		else:
			cnt += 1
			ans[i][w - j - 1] = color + 1
		if cnt == a[color]:
			color += 1
			cnt = 0
for ans_i in ans:
	print(*ans_i)


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [[0] * W for k in range(H)]
c = []
for k in range(N):
	c += [k + 1] * a[k]
now = 0
for k in range(H):
	if k % 2 == 0:
		for l in range(W):
			ans[k][l] = c[now]
			now += 1
	else:
		for l in range(W - 1, -1, -1):
			ans[k][l] = c[now]
			now += 1
for e in ans:
	print(*e)


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = [[0] * w for i in range(h)]
num = a.pop(0)
color = 1
for i in range(h):
	for j in range(w):
		if num == 0:
			num = a.pop(0)
			color += 1
		c[i][j] = color
		num -= 1
for i in range(h):
	temp = c[i]
	if i % 2 == 1:
		temp = temp[::-1]
	print(*temp)


(H, W) = map(int, input().split())
N = int(input())
A = [int(x) for x in input().split()]
q = []
for (i, a) in enumerate(A, 1):
	q += [str(i)] * a
for h in range(H):
	row = []
	for _ in range(W):
		row.append(q.pop(0))
	if h % 2 != 0:
		row.reverse()
	print(' '.join((x for x in row)))


(H, W) = map(int, input().split())
N = int(input())
i = 0
buf = [0] * W
k = 1
for (x, ai) in zip(range(1, N + 1), map(int, input().split())):
	for _ in range(ai):
		buf[i] = x
		i += 1
		if i >= W:
			print(' '.join(map(str, buf[::k])))
			i = 0
			k = -k


(h, w) = map(int, input().split())
n = int(input())
li = list(map(int, input().split()))
all_ans = []
for (i, l) in enumerate(li):
	bangou = i + 1
	all_ans += [bangou] * l
last = -1
for k in range(h):
	target = all_ans[last + 1:last + 1 + w]
	if k % 2 == 1:
		target.reverse()
	print(*target)
	last = last + w


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = [0] * w * h
an = [[] for i in range(h)]
j = 0
for i in range(n):
	for _ in range(a[i]):
		c[j] = i + 1
		j += 1
for i in range(h):
	c[i] = c[i * w:(i + 1) * w]
	if i % 2 == 0:
		print(*c[i])
	else:
		print(*c[i][::-1])


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
G = [[0 for _ in range(W)] for _ in range(H)]
(h, w) = (0, 0)
flag = 0
for (j, a) in enumerate(A):
	for i in range(a):
		if w == W:
			h += 1
			w -= 1
			flag = 1
		if w == -1:
			h += 1
			w += 1
			flag = 0
		if flag == 0:
			G[h][w] = j + 1
			w += 1
		else:
			G[h][w] = j + 1
			w -= 1
for g in G:
	print(*g)


(H, W) = [int(_) for _ in input().split()]
N = int(input())
A = [int(_) for _ in input().split()]
B = []
for i in range(N):
	B += [i + 1] * A[i]
for j in range(H):
	print(' '.join(map(str, B[j * W:(j + 1) * W][::(-1) ** (1 & j)])))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0 for _ in range(w)] for _ in range(h)]
c = 0
cnt_c = 0
for i in range(h):
	for j in range(w):
		if i % 2 == 0:
			ans[i][j] = str(c + 1)
		else:
			ans[i][w - 1 - j] = str(c + 1)
		cnt_c += 1
		if cnt_c == a[c]:
			c += 1
			cnt_c = 0
for i in range(h):
	print(' '.join(ans[i]))


from functools import *
(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans_list = [[i + 1] * a[i] for i in range(N)]
ans_list = reduce(lambda a, b: a + b, ans_list)
for i in range(H):
	ans = ans_list[i * W:i * W + W] if i % 2 == 0 else ans_list[i * W + W - 1:i * W - 1:-1]
	print(*ans)


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
	for _ in range(a[i]):
		ans.append(i + 1)
for i in range(H):
	if i % 2:
		print(*list(reversed(ans[i * W:(i + 1) * W])))
	else:
		print(*ans[i * W:(i + 1) * W])


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans_lis = []
for i in range(N):
	ans_lis = ans_lis + [i + 1] * a[i]
for i in range(H):
	if i % 2 == 0:
		k = 1
	else:
		k = -1
	ans = ans_lis[i * W:(i + 1) * W][::k]
	ans = list(map(str, ans))
	print(' '.join(ans))


(h, w) = (int(x) for x in input().split())
n = int(input())
A = list((int(x) for x in input().split()))
B = []
for (i, a) in enumerate(A, start=1):
	B += [i] * a
for i in range(h):
	(start, end) = (i * w, i * w + w)
	if i % 2 == 0:
		print(*B[start:end])
	else:
		print(*B[start:end][::-1])


(h, w) = map(int, input().split())
n = int(input())
a = [int(s) for s in input().split()]
ans = []
for x in range(n):
	for iter in range(a[x]):
		ans.append(str(x + 1))
for y in range(h):
	inp = ans[w * y:w * (y + 1)]
	if y % 2 == 0:
		inp.reverse()
	print(' '.join(inp))


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(N):
	for j in range(A[i]):
		ans.append(i + 1)
for y in range(H):
	x = ans[y * W:y * W + W]
	if y % 2 != 0:
		x.reverse()
	print(*x)


(H, W) = map(int, input().split())
N = int(input())
A = [int(x) for x in input().split()]
board = [[0] * W for _ in range(H)]
colors = [i + 1 for i in range(N) for _ in range(A[i])]
for i in range(H):
	if i % 2 == 0:
		for j in range(W):
			board[i][j] = colors[i * W + j]
	else:
		for j in range(W):
			board[i][W - j - 1] = colors[i * W + j]
for row in board:
	print(*row)


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [0] * (h * w)
index = 0
for i in range(n):
	for j in range(index, index + a[i]):
		ans[j] = i + 1
		index += 1
for i in range(h):
	row = ans[i * w:(i + 1) * w]
	if i % 2 == 1:
		row = row[::-1]
	for x in row:
		print(x, end=' ')
	print()


(H, W) = map(int, input().split())
N = int(input())
L = list(map(int, input().split()))
A = []
for i in range(N):
	a = [str(i + 1)] * L[i]
	A = A + a
for i in range(H):
	p = A[W * i:W * (i + 1)]
	if i % 2 != 0:
		p = list(reversed(p))
	ans = ' '.join(p)
	print(ans)


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N):
	b += [i + 1] * a[i]
for i in range(H):
	c = b[i * W:i * W + W]
	if i % 2 == 1:
		c = c[::-1]
	print(' '.join(map(str, c)))


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
c = []
for (n, a) in enumerate(A, 1):
	c += [n] * a
for i in range(H):
	if i % 2 == 0:
		print(*c[i * W:(i + 1) * W])
	else:
		print(*c[(i + 1) * W - 1:i * W - 1:-1])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(1, n + 1):
	for j in range(a[i - 1]):
		s.append(str(i))
b = []
for i in range(h):
	if i % 2 == 0:
		b.append(s[:w])
	else:
		t = s[:w]
		b.append(t[::-1])
	s = s[w:]
for i in range(h):
	print(*b[i])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
	c += [i + 1] * a[i]
ans = []
for h_ in range(h):
	a = c[h_ * w:w + h_ * w]
	if h_ % 2 == 0:
		ans.append(a)
	else:
		ans.append(a[::-1])
for i in ans:
	print(*i)


(H, W) = list(map(int, input().split()))
N = int(input())
a = list(map(int, input().split()))
from itertools import chain
b = list(chain.from_iterable([[i + 1] * a[i] for i in range(N)]))
c = [b[i * W:(i + 1) * W] if i % 2 == 0 else b[i * W:(i + 1) * W][::-1] for i in range(H)]
for i in range(H):
	print(' '.join(map(str, c[i])))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
grid = [[' '] * w for i in range(h)]
ci = 0
for i in range(h):
	for j in range(w):
		if not a[ci]:
			ci += 1
		if i % 2 == 0:
			grid[i][j] = ci + 1
		else:
			grid[i][~j] = ci + 1
		a[ci] -= 1
for row in grid:
	print(*row)


(h, w) = [int(i) for i in input().split()]
n = int(input())
a = [int(i) for i in input().split()]
c = [[0] * w for _ in range(h)]
(i, j) = (0, 0)
for (k, l) in enumerate(a):
	for _ in range(l):
		c[i][j] = str(k + 1)
		j += 1
		if j == w:
			j = 0
			i += 1
for i in range(h):
	if i % 2 == 1:
		c[i] = list(reversed(c[i]))
for i in c:
	print(' '.join(i))


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
L = []
for i in range(n):
	L += [i + 1] * A[i]
for i in range(h):
	l = L[i * w:(i + 1) * w]
	if i % 2 == 1:
		l.reverse()
	print(*l)


(h, w) = map(int, input().split())
n = int(input())
d = list(map(int, input().split()))
c = []
for i in range(len(d)):
	for _ in range(d[i]):
		c.append(i + 1)
for i in range(h):
	res = ''
	for j in range(w):
		if i % 2 == 0:
			res = res + str(c.pop()) + ' '
		else:
			res = str(c.pop()) + ' ' + res
	print(res)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
col = []
for (i, a) in enumerate(A, start=1):
	col.extend([i] * a)
grid = []
for h in range(H):
	x = col[h * W:(h + 1) * W]
	if h % 2 == 0:
		x.reverse()
	grid.append(x)
for g in grid:
	print(*g)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
k = 1
L = []
for i in range(N):
	for j in range(A[i]):
		L.append(k)
	k = k + 1
k = 0
c = 1
for j in range(H):
	if c == -1:
		tmp = L[k:k + W]
		ans = tmp[::-1]
	else:
		ans = L[k:k + W]
	for i in ans:
		print(i, end=' ')
	print()
	k += W
	c = -1 * c


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
tmp = []
for i in range(len(a)):
	for _ in range(a[i]):
		tmp.append(i + 1)
ans = []
for i in range(h):
	if i % 2 == 0:
		print(*tmp[i * w:i * w + w])
	else:
		print(*list(reversed(tmp[i * w:i * w + w])))


from collections import deque
(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
res = []
for i in range(n):
	res += [i + 1] * a[i]
res = deque(res)
for i in range(h):
	tmp = []
	for j in range(w):
		tmp.append(res.popleft())
	if i % 2:
		print(*tmp[::-1])
	else:
		print(*tmp)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = [[0 for i in range(W)] for j in range(H)]
cnt = 0
indexA = 0
for i in range(H * W):
	x = i // W
	y = i % W
	if cnt == 0:
		cnt = A[indexA] - 1
		indexA += 1
	else:
		cnt -= 1
	if x % 2 == 0:
		ans[x][y] = indexA
	else:
		ans[x][-y - 1] = indexA
for c in ans:
	print(*c)


(h, w) = map(int, input().split())
n = input()
v = []
for (i, a) in enumerate(list(map(int, input().split()))):
	v += [i + 1] * a
for j in range(h):
	if j % 2 == 0:
		u = v[w * j:w * (j + 1)]
	else:
		u = v[w * (j + 1) - 1:w * j - 1:-1]
	print(' '.join(map(str, u)))


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = []
for (i, a) in enumerate(A, start=1):
	ans += [i] * a
for i in range(H):
	if i % 2:
		print(*ans[i * W:(i + 1) * W][::-1])
	else:
		print(*ans[i * W:(i + 1) * W])


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
c = []
for n in range(N):
	c += [n + 1] * a[n]
ans = []
for h in range(H):
	a = c[h * W:W + h * W]
	if h % 2 == 0:
		ans.append(a)
	else:
		ans.append(a[::-1])
for i in ans:
	print(*i)


import queue
(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
b = queue.Queue()
for (i, j) in enumerate(a):
	for _ in range(j):
		b.put(i + 1)
for i in range(h):
	ans = []
	for j in range(w):
		ans += [b.get()]
	if i % 2 == 1:
		ans = list(reversed(ans))
	print(*ans)


(H, W, N, *a) = map(int, open(0).read().split())
ans = []
for i in range(N):
	ans.extend([i + 1 for _ in range(a[i])])
ans = [ans[i:i + W] for i in range(0, H * W, W)]
for i in range(1, H, 2):
	ans[i] = reversed(ans[i])
for r in ans:
	print(' '.join(map(str, r)))


(h, w) = map(int, input().split())
n = int(input())
li = list(map(int, input().split()))
line = 1
L = []
for (i, a) in enumerate(li, 1):
	while a > 0:
		L.append(i)
		a -= 1
		if len(L) == w:
			if line % 2:
				print(*L)
			else:
				print(*reversed(L))
			L = []
			line += 1


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
G = [[0] * W for k in range(H)]
i = 0
for k in range(H):
	for l in range(W):
		if a[i] != 0:
			G[k][l] = i + 1
			a[i] -= 1
		else:
			i += 1
			G[k][l] = i + 1
			a[i] -= 1
for k in range(H):
	if k % 2 == 0:
		print(*G[k])
	else:
		print(*G[k][::-1])


(h, w) = map(int, input().split())
n = int(input())
a = [0] + list(map(int, input().split()))
ans = [[] for _ in range(h)]
k = 1
for i in range(h):
	row = []
	for j in range(w):
		if not a[k]:
			k += 1
		row.append(k)
		a[k] -= 1
	if i % 2 == 1:
		ans[i] = list(reversed(row))
	else:
		ans[i] = row
for i in range(h):
	print(*ans[i])


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
A = [0] + A
from collections import deque
i = 1
for h in range(H):
	C = deque([])
	for w in range(W):
		if h % 2 == 0:
			C.append(str(i))
		else:
			C.appendleft(str(i))
		A[i] -= 1
		if A[i] == 0:
			i += 1
	print(' '.join(C))


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
l = []
for i in range(N):
	l += [i + 1] * a[i]
for i in range(H):
	row = l[W * i:W * i + W]
	if i % 2:
		row = row[::-1]
	for v in row:
		print(v, end=' ')
	print()


import itertools
(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
one_line = []
for i in range(N):
	s = str(i + 1)
	one_line.append([s] * A[i])
li = list(itertools.chain.from_iterable(one_line))
for i in range(0, H):
	tmp = li[i * W:i * W + W]
	if i % 2 != 0:
		tmp = tmp[::-1]
	print(' '.join(list(tmp)))


def main():
	(H, W) = (int(_) for _ in input().split())
	N = int(input())
	A = [int(_) for _ in input().split()]
	lst = []
	for (i, a) in enumerate(A, 1):
		lst += [i] * a
	for i in range(H):
		x = lst[i * W:(i + 1) * W] if i % 2 == 0 else lst[i * W:(i + 1) * W][::-1]
		print(*x)
	return
main()


import sys
read = sys.stdin.read
readline = sys.stdin.readline
(h, w, n, *a) = map(int, read().split())
res = []
for i in range(n):
	res += [i + 1] * a[i]
ans = [[0] * w for _ in range(h)]
for (x, i) in zip(range(h * w), res):
	(q, r) = (x // w, x % w)
	if q % 2:
		ans[q][-1 - r] = i
	else:
		ans[q][r] = i
for i in ans:
	print(*i)


(h, w) = map(int, input().split())
lis = []
ans = []
nu = 0
nn = int(input())
li = list(map(int, input().split()))
for i in range(nn):
	for j in range(li[i]):
		if nu % 2 == 0:
			lis.append(str(i + 1))
		else:
			lis.insert(0, str(i + 1))
		if len(lis) == w:
			ans.append(str(' '.join(lis)))
			lis = []
			nu += 1
for i in range(h):
	print(ans[i])


from collections import deque
(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
p = 1
d = deque()
for i in range(n):
	for j in range(a[i]):
		if len(d) == w:
			print(*d)
			d = deque()
			p *= -1
		if p == 1:
			d.append(i + 1)
		elif p == -1:
			d.appendleft(i + 1)
if len(d) != 0:
	print(*d)


(H, W) = map(int, input().split())
N = int(input())
As = list(map(int, input().split()))
li = []
for (i, a) in enumerate(As):
	li += [i + 1] * a
fields = []
for i in range(H):
	ind_s = i * W
	ind_y = (i + 1) * W
	if i % 2 == 1:
		fields.append(li[ind_s:ind_y][::-1])
	else:
		fields.append(li[ind_s:ind_y])
for r in fields:
	print(*r)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
C = [[0] * W for _ in range(H)]
x = -1
for (c, i) in enumerate(A, 1):
	for _ in range(i):
		x += 1
		row = x // W
		column = x % W
		C[row][column] = c
for i in range(H):
	if i % 2 == 0:
		print(*C[i])
	else:
		print(*C[i][::-1])


(H, W) = (int(i) for i in input().split())
N = int(input())
A = [int(i) for i in input().split()]
C = []
for i in range(N):
	for j in range(A[i]):
		C.append(i + 1)
ans = [[0] * W for i in range(H)]
for i in range(H * W):
	y = i // W
	if y % 2 == 0:
		x = i % W
	else:
		x = W - 1 - i % W
	ans[y][x] = C[i]
for i in range(H):
	ans[i] = [str(a) for a in ans[i]]
	print(' '.join(ans[i]))


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
grid = []
for (i, num) in enumerate(A, 1):
	grid += [i] * num

def split_list(l, n):
	for i in range(0, len(l), n):
		yield l[i:i + n]
ans = list(split_list(grid, w))
for i in range(h):
	if i % 2 == 0:
		print(*ans[i])
	else:
		print(*ans[i][::-1])


(height, wide) = map(int, input().split())
n = int(input())
anslist = []
a = list(map(int, input().split()))
for (i, j) in enumerate(a):
	for l in range(j):
		anslist.append(i + 1)
for k in range(height):
	t = anslist[k * wide:(k + 1) * wide]
	if k % 2 == 1:
		t.reverse()
	print(' '.join(map(str, t)))


(H, W) = map(int, input().split())
N = int(input())
L = list(map(int, input().split()))
M = [[] for i in range(H)]
c = 0
x = 0
y = 0
for i in range(N):
	while c < L[i]:
		if x != W:
			M[y].append(i + 1)
			c += 1
			x += 1
		else:
			y += 1
			x = 1
			M[y].append(i + 1)
			c += 1
	c = 0
for i in range(H):
	if i % 2 != 0:
		M[i].reverse()
for j in range(H):
	print(' '.join(map(str, M[j])))


(H, W) = map(int, input().split())
N = int(input())
L = list(map(int, input().split()))
ans = []
for i in range(N):
	for j in range(L[i]):
		ans.append(i + 1)
for i in range(H):
	if i % 2 == 0:
		print(*ans[i * W:(i + 1) * W])
	elif i % 2 == 1:
		tmp = ans[i * W:(i + 1) * W]
		print(*tmp[::-1])


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
C = [[0 for w in range(W)] for h in range(H)]
i = 1
for h in range(H):
	for w in range(W) if h % 2 == 0 else range(W - 1, -1, -1):
		C[h][w] = i
		A[i - 1] -= 1
		if not A[i - 1]:
			i += 1
for c in C:
	c = list(map(str, c))
	print(' '.join(c))


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
q = []
for i in range(n):
	q += [i + 1] * A[i]
c = [[0] * w for _ in range(h)]
for i in range(h):
	if i % 2 == 0:
		for j in range(w):
			c[i][j] = q.pop(0)
	else:
		for j in range(w - 1, -1, -1):
			c[i][j] = q.pop(0)
for i in c:
	print(' '.join(map(str, i)))


(H, W) = list(map(int, input().split()))
N = int(input().split()[0])
a_list = list(map(int, input().split()))
c_list = []
for (i, a) in enumerate(a_list):
	c_list += [i + 1] * a
for i in range(H):
	w_list = c_list[W * i:W * (i + 1)]
	if i % 2 == 1:
		w_list = reversed(w_list)
	print(' '.join([str(w) for w in w_list]))


(H, W) = map(int, input().split())
N = int(input())
al = list(map(int, input().split()))
ans = []
num = 1
for i in range(N):
	for _ in range(al[i]):
		ans.append(i + 1)
left = 0
for i in range(H):
	if i % 2 == 0:
		row = ans[left:left + W]
	else:
		row = ans[left:left + W][::-1]
	print(*row)
	left += W


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
l = []
for i in range(N):
	l += [i + 1] * A[i]
for i in range(H):
	if i % 2 == 0:
		print(*l[0:W])
		del l[:W]
	else:
		print(*l[0:W][::-1])
		del l[:W]


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
lst = []
for i in range(1, n + 1):
	for j in range(a[i - 1]):
		lst.append(str(i))
lst.reverse()
ans = [[0] * w for i in range(h)]
for i in range(h):
	if i % 2 == 0:
		for j in range(w):
			ans[i][j] = lst.pop()
	else:
		for j in range(w - 1, -1, -1):
			ans[i][j] = lst.pop()
for i in ans:
	print(' '.join(i))


(h, w) = map(int, input().split())
n = int(input())
A = [int(i) for i in input().split()]
AA = []
for i in range(n):
	ai = A[i]
	for j in range(ai):
		AA.append(i + 1)
for i in range(h):
	AAA = AA[i * w:(i + 1) * w]
	if i % 2 != 0:
		AAA = AAA[::-1]
	print(*AAA)


import random
(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
i = 0
for y in range(h):
	row = []
	for _ in range(w):
		row += [i + 1]
		a[i] -= 1
		if a[i] == 0:
			i += 1
	if y % 2 == 1:
		row = reversed(row)
	print(*row)


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
color = []
for i in range(n):
	color += [i + 1] * a[i]
tmp = []
tmp = [[0] * w for i in range(h)]
for (i, aa) in enumerate(color):
	tmp[i // w][i % w] = color[i]
ans = []
for (i, t) in enumerate(tmp):
	if i % 2 == 0:
		ans.append(t)
	else:
		t.sort(reverse=True)
		ans.append(t)
for aa in ans:
	print(*aa)


import sys
input = sys.stdin.readline
(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
res = [[0] * W for _ in range(H)]
s = []
for i in range(N):
	s += [i + 1] * a[i]
for i in range(H):
	if i % 2:
		for j in range(W - 1, -1, -1):
			res[i][j] = s.pop()
	else:
		for j in range(W):
			res[i][j] = s.pop()
for r in res:
	print(*r)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = [[None] * W for _ in range(H)]
(x, y) = (0, 0)
d = 1
for (c, a) in enumerate(A):
	c += 1
	for i in range(a):
		if x < 0 or x >= W:
			y += 1
			d = -d
			x += d
		ans[y][x] = c
		x += d
for a in ans:
	print(' '.join(map(str, a)))


(r, c) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
x = 0
grid = [[] for i in range(r)]
for i in range(r):
	while x < n and len(grid[i]) + a[x] <= c:
		grid[i].extend([x + 1] * a[x])
		x += 1
	if x < n:
		a[x] -= c - len(grid[i])
		grid[i].extend([x + 1] * (c - len(grid[i])))
for i in range(1, r, 2):
	grid[i] = grid[i][::-1]
for row in grid:
	print(*row)


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
colors = []
for color in range(1, N + 1):
	for j in range(a[color - 1]):
		colors.append(str(color))
canvas = []
for i in range(H):
	if i % 2 == 0:
		canvas.append(colors[i * W:i * W + W])
	else:
		canvas.append(colors[i * W + W - 1:i * W - 1:-1])
for line in canvas:
	print(' '.join(line))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
g = []
for (i, v) in enumerate(a):
	g.extend([i + 1] * v)
k = 0
for i in range(h):
	l = []
	for j in range(w):
		l.append(g[k])
		k += 1
	if i % 2:
		print(*l[::-1])
	else:
		print(*l)


(h, w) = map(int, input().split())
n = int(input())
arr = [0] + list(map(int, input().split()))
res = []
for i in range(1, n + 1):
	res.extend([i] * arr[i])
tmp = 0
for i in range(h):
	s = res[tmp:tmp + w]
	if i % 2 == 1:
		s.reverse()
	print(*s)
	tmp += w


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = [[0] * W for _ in range(H)]
b = [0] * (H * W)
now = 0
for i in range(N):
	for j in range(A[i]):
		b[now + j] = i + 1
	now += A[i]
for h in range(H):
	for w in range(W):
		if h % 2 == 0:
			ans[h][w] = b[W * h + w]
		else:
			ans[h][w] = b[W * (h + 1) - w - 1]
for a in ans:
	print(*a)


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in range(n):
	for j in range(a[i]):
		b.append(i + 1)
for i in range(h):
	c.append(b[w * i:w * (i + 1)])
for i in range(h):
	if i % 2 == 0:
		print(*c[i])
	else:
		print(*c[i][::-1])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
hw = []
for i in range(n):
	hw += [str(i + 1)] * a[i]
flag = False
for i in range(h):
	bgn = i * w
	end = bgn + w
	res = hw[bgn:end]
	if flag:
		res = res[::-1]
		flag = False
	else:
		flag = True
	print(*res)


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
l = []
for (color, m) in enumerate(a, 1):
	l += [color] * m
for i in range(H):
	k = l[:W]
	l = l[W:]
	if i % 2 != 0:
		k.reverse()
	print(*k)


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
	ans.extend([i + 1 for _ in range(a[i])])
ans = [ans[i:i + W] for i in range(0, H * W, W)]
for i in range(1, H, 2):
	ans[i] = ans[i][::-1]
for r in ans:
	print(' '.join(map(str, r)))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0] * w for _ in range(h)]
num = 0
for x in range(n):
	for y in range(a[x]):
		i = num // w
		if i % 2:
			j = w - 1 - num % w
		else:
			j = num % w
		ans[i][j] = x + 1
		num += 1
for i in range(h):
	print(*ans[i])


(H, W, N, *A) = map(int, open(0).read().split())
(h, w) = (0, 0)
D = [[0] * W for i in range(H)]
for i in range(N):
	c = 0
	while c < A[i]:
		D[h][w] = i + 1
		if h % 2 == 0:
			w += 1
		else:
			w -= 1
		if w < 0 or w >= W:
			h += 1
			w = 0 if h % 2 == 0 else W - 1
		c += 1
for d in D:
	print(*d)


(h, w) = map(int, input().split())
n = int(input())
aa = list(map(int, input().split()))
ans = [[0] * w for _ in range(h)]
nums = []
for i in range(n):
	for j in range(aa[i]):
		nums.append(i + 1)
for i in range(len(nums)):
	ans[i // w][i % w] = nums[i]
for hi in range(h):
	if hi % 2 == 1:
		print(' '.join(map(str, list(reversed(ans[hi])))))
	else:
		print(' '.join(map(str, ans[hi])))


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
check = []
for (i, v) in enumerate(A):
	check += [i + 1] * v
for i in range(H):
	if i % 2 == 0:
		print(*check[i * W:(i + 1) * W])
	else:
		print(*check[i * W:(i + 1) * W][::-1])


(H, W) = map(int, input().split())
N = int(input())
A = [int(i) for i in input().split()]
align = [i + 1 for (i, a) in enumerate(A) for _ in range(a)]
count = 0
ans = []
for i in range(H):
	tmp = align[W * i:W * (i + 1)]
	if i % 2 != 0:
		tmp = tmp[::-1]
	print(*tmp)


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
	num = a[i]
	while num > 0:
		l.append(i + 1)
		num -= 1
s = []
cnt = 0
for i in range(0, h * w, w):
	if cnt % 2 == 0:
		print(*l[i:i + w])
	else:
		print(*l[i + w - 1:i - 1:-1])
	cnt += 1


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = []
for (i, a) in enumerate(A, start=1):
	ans.extend([i] * a)
ans.sort()
for (i, w) in enumerate(range(0, H * W, W)):
	print(*ans[w:w + W][::(-1) ** i])


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
color = []
for i in range(n):
	color += [i + 1] * a[i]
ans = [[0] * w for _ in range(h)]
now = 0
for row in range(h):
	for col in range(w):
		if row % 2 == 0:
			ans[row][col] = color[now]
		else:
			ans[row][-(col + 1)] = color[now]
		now += 1
for r in ans:
	print(*r)


from collections import deque
(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	for j in range(a[i]):
		b.append(i + 1)
b = deque(b)
ans = []
for hi in range(h):
	c = [0] * w
	for wi in range(w):
		if hi % 2 == 0:
			j = wi
		else:
			j = w - wi - 1
		c[j] = b.popleft()
	ans.append(c)
for ci in ans:
	print(' '.join(map(str, ci)))


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
color_row = []
for (i, a) in enumerate(A):
	color_row += [i + 1 for _ in range(a)]
for i in range(h):
	if i % 2 == 0:
		print(*color_row[w * i:w * i + w])
	else:
		print(*reversed(color_row[w * i:w * i + w]))


(h, w) = map(int, input().split())
n = int(input())
l = []
a = [int(x) for x in input().split()]
for i in range(n):
	l.extend([i + 1 for _ in range(a[i])])
for hi in range(h):
	line = []
	for wi in range(w):
		line.append(l[w * hi + wi])
	if hi % 2 == 1:
		line = line[::-1]
	print(*line)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = []
for (i, a) in enumerate(A):
	ans += [str(i + 1)] * a
for h in range(H):
	if h % 2 == 0:
		print(' '.join(ans[h * W:(h + 1) * W]))
	else:
		print(' '.join(ans[h * W:(h + 1) * W][::-1]))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
a_list = []
for (i, j) in enumerate(a):
	a_list += [i + 1] * j
inx = 0
ans = [0] * w
for i in range(h):
	if i % 2 == 0:
		for j in range(w):
			ans[j] = a_list[inx]
			inx += 1
	else:
		for j in range(w - 1, -1, -1):
			ans[j] = a_list[inx]
			inx += 1
	print(*ans)


(h, w) = map(int, input().split())
n = int(input())
(*a,) = map(int, input().split())
grid = []
for i in range(n):
	for j in range(a[i]):
		grid.append(i + 1)
for i in range(h):
	if i % 2 == 0:
		print(*grid[i * w:i * w + w])
	else:
		print(*grid[i * w:i * w + w][::-1])


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
res = []
j = 0
st = 0
for i in range(H):
	j = 0
	while j < W:
		while 0 < a[st] and j < W:
			res.append(str(st + 1))
			j += 1
			a[st] -= 1
		if a[st] == 0:
			st += 1
	if i % 2 == 1:
		res.reverse()
	print(' '.join(res))
	res = []


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
C = [0 for i in range(w * h)]
idx = 0
for i in range(n):
	a = A[i]
	for j in range(a):
		C[idx] = i + 1
		idx += 1
C = [C[i:i + w] for i in range(0, h * w, w)]
for i in range(h):
	if i % 2 == 0:
		print(*C[i])
	else:
		print(*C[i][::-1])


(H, W) = map(int, input().split())
N = int(input())
X = list(map(int, input().split()))
Y = [[-1] * W for _ in range(H)]
u = 0
for i in range(H):
	(s, e, d) = (0, W, 1) if i % 2 else (W - 1, -1, -1)
	for j in range(s, e, d):
		if X[u]:
			X[u] -= 1
			Y[i][j] = u + 1
		else:
			u += 1
			X[u] -= 1
			Y[i][j] = u + 1
for i in range(H):
	print(*Y[i])


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = [[0] * W for _ in range(H)]
S = 0
for (i, a) in enumerate(A, start=1):
	for _ in range(a):
		(h, w) = divmod(S, W)
		ans[h][w] = i
		S += 1
for (i, a) in enumerate(ans):
	print(*a[::(-1) ** i])


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
G = [[0 for _ in range(W)] for _ in range(H)]
a = 0
ii = 0
for i in range(H):
	for j in range(W):
		if a == 0:
			a = A[ii]
			ii += 1
		G[i][j] = str(ii)
		a -= 1
for i in range(H):
	if i % 2 == 0:
		print(' '.join(G[i]))
	else:
		print(' '.join(G[i][::-1]))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
l = []
for (i, ai) in enumerate(a, 1):
	l += [i] * ai
for i in range(h):
	ansi = l[w * i:w * (i + 1)]
	print(*(ansi if i % 2 == 0 else ansi[::-1]))


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
cnt = 0
now = 0
c = [[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
	iter_w = range(W)
	if h % 2:
		iter_w = reversed(iter_w)
	for w in iter_w:
		c[h][w] = now + 1
		cnt += 1
		if cnt == a[now]:
			now += 1
			cnt = 0
for i in range(H):
	print(*c[i])


from collections import deque
(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
ans = deque()
for (i, a) in zip(list(range(1, n + 1)), A):
	for _ in range(a):
		ans.append(i)
check = 0
for i in range(h):
	a = []
	for _ in range(w):
		a.append(ans.popleft())
	if check % 2 == 0:
		print(' '.join(map(str, a)))
	else:
		print(' '.join(map(str, a[::-1])))
	check += 1


from itertools import chain
(h, w) = map(int, input().split())
n = int(input())
field = chain.from_iterable(([i + 1] * a for (i, a) in enumerate(map(int, input().split()))))
for (r, row) in enumerate(zip(*[field] * w)):
	if r & 1:
		print(*reversed(row))
	else:
		print(*row)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
tmp = []
for (i, a) in enumerate(A, start=1):
	tmp.extend([i] * a)
ans = []
rev = 0
add = []
for i in range(1, H * W + 1):
	add.append(tmp[i - 1])
	if i % W == 0:
		if rev:
			add = add[::-1]
		ans.append(add)
		rev = 1 - rev
		add = []
for a in ans:
	print(*a)


import sys
readline = sys.stdin.readline
(H, W) = map(int, readline().split())
N = int(readline())
Arr = []
A = list(map(int, readline().split()))
for i in range(N):
	Arr.extend([i + 1] * A[i])
G = [Arr[W * i:W * (i + 1)] for i in range(H)]
for i in range(0, H, 2):
	G[i].reverse()
for g in G:
	print(' '.join(map(str, g)))


(H, W) = list(map(int, input().split()))
M = int(input())
A = list(map(int, input().split()))
C = [[0 for _ in range(W)] for l in range(H)]
back = 1
c = 1
count = 0
for i in range(H):
	for j in range(W)[::back]:
		C[i][j] = c
		count += 1
		if count == A[c - 1]:
			c += 1
			count = 0
	back = -back
for c in C:
	print(' '.join(map(str, c)))


def main():
	(h, w) = list(map(int, input().split()))
	n = int(input())
	A = list(map(int, input().split()))
	ans = [str(i + 1) for (i, a) in enumerate(A) for _ in range(a)]
	for i in range(h):
		if i % 2 == 0:
			print(' '.join(ans[i * w:i * w + w]))
		else:
			print(' '.join(ans[i * w + w - 1:i * w - 1:-1]))
main()


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
MAP = [[0 for i in range(w)] for j in range(h)]
(s, num) = (0, 1)
for i in range(h):
	if i % 2 == 0:
		add = [k for k in range(w)]
	else:
		add = [k for k in reversed(range(w))]
	for j in add:
		MAP[i][j] = num
		A[s] -= 1
		if A[s] == 0:
			s += 1
			num += 1
for i in range(h):
	print(*MAP[i])


(h, w) = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
X = []
for i in range(n):
	X += [i + 1] * A[i]
for i in range(h):
	x = X[w * i:w * (i + 1)]
	if i % 2 == 0:
		print(*x)
	else:
		x.reverse()
		print(*x)


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = [[0] * W for _ in range(H)]
(x, y) = (0, 0)
sign = 1
for (idx, a) in enumerate(A):
	idx += 1
	for _ in range(a):
		if x < 0 or x >= W:
			y += 1
			sign = sign * -1
			x += 1 * sign
		ans[y][x] = idx
		x += 1 * sign
for a in ans:
	print(*a)


(H, W) = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
res = []
for i in range(len(a)):
	for c in range(a[i]):
		res.append(i + 1)
for i in range(H):
	row = ''
	for j in range(W):
		r = W * i
		if i % 2 == 0:
			c = j
		else:
			c = W - 1 - j
		row += str(res[r + c])
		row += ' '
	print(row)


(H, W) = map(int, input().split())
N = int(input())
A = [int(x) for x in input().split()]
L = []
for (i, a) in enumerate(A):
	for j in range(a):
		L.append(i + 1)
T = [[0] * W for i in range(H)]
idx = 0
for i in range(H):
	k = 1
	if i % 2:
		k = -1
	for j in range(W)[::k]:
		T[i][j] = L[idx]
		idx += 1
for t in T:
	print(*t)


(H, W) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
area = [[0] * W for _ in range(H)]
color = 1
filled = 0
for h in range(H):
	if h % 2 == 0:
		sec = range(W)
	else:
		sec = range(W - 1, -1, -1)
	for w in sec:
		area[h][w] = color
		filled += 1
		if filled == a[color - 1]:
			color += 1
			filled = 0
	print(*area[h], sep=' ')


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = [[-1] * W for _ in range(H)]
now = rem = 0
for i in range(H):
	r = range(W)
	if i % 2:
		r = reversed(r)
	for j in r:
		if rem:
			ans[i][j] = now
			rem -= 1
		else:
			now += 1
			ans[i][j] = now
			rem = A[now - 1] - 1
for row in ans:
	print(*row)


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
	while a[i] > 0:
		a[i] -= 1
		c.append(str(i + 1))
for i in range(h):
	if i % 2 == 0:
		print(' '.join(c[i * w:(i + 1) * w]))
	else:
		print(' '.join(reversed(c[i * w:(i + 1) * w])))


(H, W) = map(int, input().split())
N = int(input())
A = list((int(a) for a in input().split()))
color = []
for (i, a) in enumerate(A, 1):
	color.extend([i] * a)
grid = [[0] * W for _ in range(H)]
k = 0
for i in range(H):
	for j in range(W):
		if i % 2:
			j = W - 1 - j
		grid[i][j] = color[k]
		k += 1
for i in range(H):
	print(' '.join(map(str, grid[i])))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0 for _ in range(w)] for _ in range(h)]
cnt = 0
for i in range(n):
	for j in range(a[i]):
		r = cnt // w
		c = r % 2 * (w - 1) + (-1) ** (r % 2) * (cnt % w)
		ans[r][c] = i + 1
		cnt += 1
for ls in ans:
	print(' '.join(list(map(str, ls))))


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = [0] * (H * W)
cnt = 0
for (idx, a) in enumerate(A):
	for i in range(a):
		ans[cnt + i] = idx + 1
	cnt += a
for h in range(H):
	if h % 2 == 0:
		print(*ans[h * W:(h + 1) * W])
	else:
		temp = ans[h * W:(h + 1) * W]
		print(*temp[::-1])


(H, W) = [int(n) for n in input().split()]
N = int(input())
A = [int(n) for n in input().split()]
list_ = []
for (i, num) in enumerate(A):
	list_.extend([i + 1] * num)
result = ''
for h in range(H):
	tmp = [str(n) for n in list_[h * W:(h + 1) * W]]
	if h % 2 == 0:
		result += ' '.join(tmp) + '\n'
	else:
		result += ' '.join(tmp[::-1]) + '\n'
print(result[:-1])


(h, w, n, *a) = map(int, open(0).read().split())
ans = []
for (i, j) in enumerate(a):
	ans += [i + 1] * j
for i in range(h):
	print(*ans[i * w:(i + 1) * w][::-1 + 2 * (i % 2)])


(h, w) = map(int, input().split())
n = int(input())
ans = sum([[i + 1] * j for (i, j) in enumerate(map(int, input().split()))], [])
for i in range(h):
	print(*ans[w * i:w * i + w][::(-1) ** (i % 2)], sep=' ')


(H, W) = map(int, input().split())
N = int(input())
A = [int(i) for i in input().split()]
color = []
for (i, a) in enumerate(A, 1):
	for _ in range(a):
		color.append(i)
flag = 1
for i in range(H):
	left = i * W
	right = left + W
	print(*color[left:right][::flag])
	flag *= -1


(H, W) = list(map(int, input().split()))
N = int(input())
A = list(map(int, input().split()))
L = [0] * (H * W)
n = 0
for i in range(N):
	a = A[i]
	L[n:n + a] = [i + 1] * a
	n += a
for i in range(H):
	S = L[i * W:(i + 1) * W]
	if i % 2 == 1:
		S = S[::-1]
	print(*S)


tmp = list(map(int, input().split()))
(h, w) = (tmp[0], tmp[1])
n = int(input())
t = []
ans = []
As = list(map(int, input().split()))
for i in range(1, n + 1):
	for j in range(As[i - 1]):
		t.append(i)
for i in range(h):
	j = t[:w]
	if i % 2:
		j.reverse()
	print(*j)
	t = t[w:]


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(len(a)):
	ans = ans + [i + 1] * a[i]
for i in range(h):
	if i % 2 == 0:
		c = ans[w * i:w * (i + 1)]
		print(' '.join(map(str, c)))
	else:
		c = ans[w * i:w * (i + 1)]
		c1 = c[::-1]
		print(' '.join(map(str, c1)))


(H, W) = map(int, input().split())
(N,) = map(int, input().split())
As = list(map(int, input().split()))
c = 1
r = [[0] * W for _ in range(H)]
for i in range(H):
	for j in range(W):
		if i % 2:
			r[i][j] = c
		else:
			r[i][W - j - 1] = c
		As[c - 1] -= 1
		if As[c - 1] == 0:
			c += 1
for i in range(H):
	print(*r[i])


(H, W) = list(map(int, input().split()))
N = int(input())
a = list(map(int, input().split()))
ansline = []
for i in range(N):
	ansline += [i + 1 for j in range(a[i])]

def split_list(l, n):
	for idx in range(0, len(l), n):
		yield l[idx:idx + n]
ans = list(split_list(ansline, W))
for i in range(1, H, 2):
	ans[i].reverse()
for i in ans:
	print(*i)


import itertools
(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
l = list(itertools.chain.from_iterable([[i + 1] * a[i] for i in range(n)]))
c = 0
for i in range(h):
	if c % 2 == 0:
		print(*l[i * w:(i + 1) * w])
	else:
		print(*l[(i + 1) * w - 1:i * w - 1:-1])
	c += 1


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
	for j in range(a[i]):
		l.append(i + 1)
ans = []
for i in range(h):
	if i % 2 == 1:
		x = l[i * w:(i + 1) * w]
		ans.append(x[::-1])
	else:
		ans.append(l[i * w:(i + 1) * w])
for i in range(h):
	print(*ans[i])


s = input().split()
(h, w) = (int(s[0]), int(s[1]))
n = int(input())
s = input().split()
l = [int(s[i]) for i in range(n)]
res = []
for i in range(1, n + 1):
	res += [i] * l[i - 1]
for i in range(h):
	ll = res[i * w:i * w + w]
	if i % 2 == 1:
		ll = ll[-1::-1]
	for j in ll[:-1]:
		print(j, end=' ')
	print(ll[-1])


(h, w) = map(int, input().split())
n = int(input())
l = []
a = list(map(int, input().split()))
for i in range(n):
	for j in range(a[i]):
		l.append(i + 1)
for i in range(h):
	if i % 2 == 0:
		print(' '.join(map(str, l[i * w:(i + 1) * w])))
	else:
		b = l[i * w:(i + 1) * w]
		b.reverse()
		print(' '.join(map(str, b)))


(h, w) = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = [[0 for _ in range(w)] for _ in range(h)]
z = 0
for i in range(len(a)):
	for j in range(a[i]):
		p = z + j
		y = p // w
		x = p % w
		if y % 2 == 1:
			x = w - x - 1
		c[y][x] = i + 1
	z += a[i]
for b in c:
	s = map(str, b)
	print(' '.join(s))


(h, w) = map(int, input().split())
n = int(input())
a = map(int, input().split())
l = []
for (i, x) in enumerate(a):
	for j in range(x):
		l.append(i + 1)
for i in range(h):
	t = l[i * w:(i + 1) * w]
	if i % 2 == 1:
		t.reverse()
	print(' '.join(map(str, t)))


(H, W, N, *a) = map(int, open(0).read().split())
a = [None] + a
mapp = [[-1] * W for _ in range(H)]
x = 0
y = 0
c = 1
for _ in range(W):
	for _ in range(H):
		if a[c] == 0:
			c += 1
		mapp[y][x] = c
		a[c] -= 1
		y += 1 * [+1, -1][x % 2]
	y -= 1 * [+1, -1][x % 2]
	x += 1
for y in range(H):
	print(*mapp[y])


(h, w) = map(int, input().split())
n = int(input())
c = list(map(int, input().split()))
d = []
for i in range(1, n + 1):
	for j in range(c[i - 1]):
		d.append(i)
ansl = [[0] * w for i in range(h)]
for i in range(h):
	if i % 2 == 0:
		for j in range(w):
			ansl[i][j] = str(d[i * w + j])
	else:
		for j in range(w):
			ansl[i][w - j - 1] = str(d[i * w + j])
for j in ansl:
	print(' '.join(j))


(H, W) = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
B = [[] for i in range(H)]
k = 0
for (i, a) in enumerate(A):
	for j in range(a):
		B[k].append(i + 1)
		if len(B[k]) == W:
			k += 1
for (i, row) in enumerate(B):
	if i % 2 == 0:
		print(*row)
	else:
		print(*row[::-1])


def LI():
	return list(map(int, input().split()))
(H, W) = LI()
N = int(input())
A = LI()

def main():
	l = []
	for i in range(N):
		for _ in range(A[i]):
			l.append(i + 1)
	for i in range(H):
		x = l[i * W:i * W + W]
		if i % 2 == 1:
			x = x[::-1]
		print(*x)
main()