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 (Python):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))









build_order = []
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            build_order.append((i, j))
    else:
        for j in range(W - 1, -1, -1):
            build_order.append((i, j))

colors = [[None for _ in range(W)] for _ in range(H)]

index = 0
color = 0

while index < W * H:
    c = A[color]
    k = 0
    while k < c:
        (i, j) = build_order[index]
        index += 1
        k += 1
        colors[i][j] = color + 1
    color += 1

for c in colors: print(" ".join(map(str, c)))

Solution (Python):
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

c = [[0]*W for _ in range(H)]
now_h, now_w = 0, 0

rest = 0
col = 0
direction = 1
while now_h + now_w < H * W:
  if rest == 0:
    if len(a) == 0:
      break
    rest = a.pop(0)
    col += 1
  if direction == 1:
    if now_w + 1 < W:
      c[now_h][now_w] = col
      now_w += 1 
      rest -= 1
    elif now_w + 1 == W:
      c[now_h][now_w] = col
      now_h += 1
      direction = -1
      rest -= 1
  elif direction == -1:
    if now_w - 1 > -1:
      c[now_h][now_w] = col
      now_w -= 1
      rest -= 1
    elif now_w - 1 == -1:
      c[now_h][now_w] = col
      now_h += 1
      direction = 1
      rest -= 1

  
for h in range(H):
  for w in range(W):
    print(c[h][w], end=" ")
  print()

Solution (Python):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

color = 1
color_count = A[color-1]

grid = [[None] * W for _ in range(H)]
for i in range(H):
    if i % 2 == 0:
        rng = range(W)
    else:
        rng = range(W-1,-1,-1)
    for j in rng:
        if color_count == 0:
            color += 1
            color_count = A[color-1]
        color_count -= 1
        grid[i][j] = color

for i in range(H):
    print(*grid[i], sep=' ')

Solution (Python):
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
grid = [[0]*w for _ in range(h)]
cur = [0,0]
for i in range(n):
    color = str(i+1)
    remain = a[i]
    while remain > 0:
        remain -= 1
        grid[cur[0]][cur[1]] = color
        if cur[0] % 2 == 0:
            if cur[1] == w-1:
                cur[0] += 1
            else:
                cur[1] += 1
        else:
            if cur[1] == 0:
                cur[0] += 1
            else:
                cur[1] -= 1
for i in range(h):
    print(" ".join(grid[i]))

Solution (Python):
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
a_=[]
for i in range(n):
    l=a[i]
    for j in range(l):
        a_.append(i+1)
ans=[]
now=0
for i in range(h):
    if (i+1)%2==1:
        for j in range(w):
            ans.append(a_[now])
            now+=1
    else:
        for j in range(now+(w-1),now-1,-1):
            ans.append(a_[j])
            now+=1
now=0
for i in range(h):
    for j in range(w):
        print(ans[now],end=" ")
        now+=1
    print()

Solution (Python):
if __name__ == '__main__':

    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))

    field = [0 for i in range(h * w)]
    index = 0
    for i in range(n):
        for j in range(a[i]):
            field[index] = str(i + 1)
            index += 1
    for i in range(h):
        ans = field[(i * w):(i * w + w)]
        if i % 2 == 1:
            ans.reverse()
        print(' '.join(ans))

Solution (Python):
import numpy as np
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
B = np.zeros([H,W], np.int64)
ind = 0
for i in range(H):
    for j in range(W):
        if A[ind] == 0:
            ind += 1
        B[i,j] = ind+1
        A[ind] -= 1

for i in range(H):
    if i % 2 == 0:
        print(*B[i])
    else:
        print(*B[i][::-1])

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Solution (Python):
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)

Solution (Python):
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [['' for i in range(W)] for i in range(H)]
indexH = 0
indexW = 0
cnt = 0
for i in range(N):
    for j in range(a[i]):
        ans[indexH][indexW] = i + 1
        if cnt % 2 == 0:
            if indexW == W - 1:
                indexW = -1
                indexH += 1
                cnt += 1
            else:
                indexW += 1
        else:
            if indexW == -W:
                indexW = 0
                indexH += 1
                cnt += 1
            else:
                indexW -= 1

for i in ans:
    print(*i)

Solution (Python):
h,w = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
area = [[0]*w for i in range(h)]
cnt = 1
inv = 1
for i in range(h):
    for j in range(w):
        if inv ==1:
            area[i][j] = str(cnt)
        else:
            area[i][-j-1] = str(cnt)
        if A[cnt-1] != 1:
            A[cnt-1] -=1
        else:
            cnt+=1
    inv *= -1
for i in range(h):
    print(" ".join(area[i]))

Solution (Python):
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
ans = [[0]*w for _ in range(h)]

idx_ls = []

flip = 0
for i in range(h):
    if not flip:
        for j in range(w):
            idx_ls.append((i, j))
    else:
        for j in range(w-1, -1, -1):
            idx_ls.append((i, j))
    flip ^= 1


for color, a in enumerate(A):
    color += 1
    for _ in range(a):
        i, j = idx_ls.pop()
        ans[i][j] = color

for x in ans:
    print(*x)

Solution (Python):
def main():
    H,W = map(int,input().split())
    N = int(input())
    a = list(map(int,input().split()))
    a.reverse()
    ans = []
    i = 1
    tmp = []
    k = -1
    cnt = 1
    while a:
        num = a.pop()
        l = len(tmp)
        if num > W-l:
            tmp += [i]*(W-l)
            if i-1 == k and cnt%2 == 1:
                tmp.reverse()
                cnt += 1
            ans.append(tmp)
            num -= (W-l)
            while num >= W:
                ans.append([i]*W)
                num -= W
            tmp = [i]*num
            k = i

        else:
            tmp += [i]*num
            if len(tmp) == W:
                if i-1 == k and cnt%2==1:
                    tmp.reverse()
                    cnt += 1
                ans.append(tmp)
                tmp = []
        i += 1
    for i in range(1,H):
        if ans[i][0] == ans[i-1][-1]:
            ans[i].reverse()
    for v in ans:
        print(*v)
if __name__ == "__main__":
    main()

Solution (Python):
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=" ")

Solution (Python):
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())

Solution (Python):
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)

Solution (Python):
H,W=map(int,input().split())
N=int(input())
la=list(map(int,input().split()))
lans=[[0 for _ in range(W)] for _ in range(H)]
count=0
tmpi=0
for i in range(H):
    if i%2==0:
        for j in range(W):
            if count==0:
                tmpi+=1
                count=la[tmpi-1]
            lans[i][j]=tmpi
            count-=1
    else:
        for j in range(W-1,-1,-1):
            if count==0:
                tmpi+=1
                count=la[tmpi-1]
            lans[i][j]=tmpi
            count-=1
for i in range(H):
    for j in range(W-1):
        print(lans[i][j],end=" ")
    print(lans[i][W-1])

Solution (Python):
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

Solution (Python):


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)

Solution (Python):
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])

Solution (Python):
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)

Solution (Python):
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])

Solution (Python):
def main():
    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 = 0
    color = 1

    for h in range(H):
        if h % 2 == 0:
            range_W = range(W)
        else:
            range_W = range(W)[::-1]
        for w in range_W:
            c[h][w] += color
            A[i] -= 1
            if A[i] == 0:
                i += 1
                color += 1

    for i in range(H):
        print(*c[i])


if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
h, w, n, *a = map(int, open(0).read().split())

c = [[0]*w for i in range(h)]
i = j = 0
tor = True
for k in range(n):
        for x in range(a[k]):
                c[i][j] = k+1

                if tor:
                        j += 1
                        if j>=w:
                                i += 1
                                j = w-1
                                tor = False
                else:
                        j -= 1
                        if j<0:
                                i += 1
                                j = 0
                                tor = True
for i in c: print(*i)

Solution (Python):
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

ans = [[None]*W for _ in range(H)]
i = j = a = 0
while A:
    n = len(A)
    a = A.pop()
    while a:
        ans[i][j] = n
        if i%2:
            if j:
                j -= 1
            else:
                i += 1
        else:
            if j==W-1:
                i += 1
            else:
                j += 1
        a -= 1
for row in ans:
    print(*row)

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    N = int(input())
    A = list(map(int, input().split()))

    c = [[0]*W for _ in range(H)]
    c_idx = 0
    for i in range(H):
        for j in range(W):
            if i&1: j = W-1-j
            if A[c_idx] == 0: c_idx += 1
            c[i][j] = c_idx + 1
            A[c_idx] -= 1
    
    for i in range(H):
        print(*c[i])


if __name__ == '__main__':
    main()

Solution (Python):
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])

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h, w = MAP()
n = INT()
a = LIST()
ans = [[0 for _ in range(w)] for _ in range(h)]
index = 0
cnt = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if cnt < a[index]:
                ans[i][j] = index + 1
                cnt += 1
            else:
                index += 1
                cnt = 0
                if cnt < a[index]:
                    ans[i][j] = index + 1
                    cnt += 1
    else:
        for j in reversed(range(w)):
            if cnt < a[index]:
                ans[i][j] = index + 1
                cnt += 1
            else:
                index += 1
                cnt = 0
                if cnt < a[index]:
                    ans[i][j] = index + 1
                    cnt += 1
for i in range(h):
    print(' '.join(map(str, ans[i])))

Solution (Python):









import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    h, w = list(map(int,ipti().split()))
    n = int(input())
    a = list(map(int,ipti().split()))

    grid = [[0] * w for _ in range(h)]
    x = 0
    y = 0
    direction = 1

    for i in range(n):
        color = i + 1
        rem = a[i]
        while rem > 0:
            grid[y][x] = color
            rem -= 1
            x += direction
            if x == w:
                x -= 1
                direction *= -1
                y += 1
            if x == -1:
                x += 1
                direction *= -1
                y += 1

    for i in range(h):
        print(*grid[i])

if __name__ == '__main__':
    main()

Solution (Python):
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))

Solution (Python):
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
c=[[0 for i in range(0,W)] for i in range(0,H)]
grid=(0,0)
for i in range(0,N):
    color=i+1
    for j in range(0,a[i]):
        h,w=grid
        c[h][w]=color
        if W-1>w and h%2==0:
            grid=(h,w+1)
        if w>0 and h%2==1:
            grid=(h,w-1)
        if h%2==0 and w==W-1:
            grid=(h+1,W-1)
        if h%2==1 and w==0:
            grid=(h+1,0)

for i in range(0,H):
    print(*c[i])

Solution (Python):
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])

Solution (Python):
H,W = [int(i) for i in input().split()]
N = int(input())
a = [int(i) for i in input().split()]
seen = [[False] * W for _ in range(H)]
ans = [0 for _ in range(H*W)]
from numpy import cumsum
a_sum = list(cumsum(a))
colour = 0
for i in range(H*W):
    if i >= a_sum[colour]:
        colour +=1
    ans[i] = colour +1
for h in range(H):
    if h%2 == 0:
        print(" ".join(map(str, ans[h*W:(h+1)*W])))
    else:
        print(" ".join(map(str, reversed(ans[h*W:(h+1)*W]))))

Solution (Python):
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)

Solution (Python):
import math
import numpy as np
H, W = list(map(int, input().split()))
N = input()
colors = list(map(int, input().split()))

cumsum_colors = np.cumsum(colors)

color_ind = 0
arr = [0 for _ in range(H*W)]
for i in range(H*W):
    if i >= cumsum_colors[color_ind]:
        color_ind += 1
    arr[i] = color_ind + 1

for h in range(H):
    if h%2 == 0:
        print(" ".join(map(str, arr[h*W:(h+1)*W])))
    else:
        print(" ".join(map(str, reversed(arr[h*W:(h+1)*W]))))

Solution (Python):
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)

Solution (Python):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

grid = [[0] * W for _ in range(H)]

alternate = True
index = 0
for i in range(H):
    if alternate:
        for j in range(W):
            if A[index] != 0:
                grid[i][j] = index
                A[index] -= 1
            else:
                index += 1
                grid[i][j] = index
                A[index] -= 1
    else:
        for j in reversed(range(W)):
            if A[index] != 0:
                grid[i][j] = index
                A[index] -= 1
            else:
                index += 1
                grid[i][j] = index
                A[index] -= 1
    alternate = not alternate

for gr in grid:
    for g in gr:
        print('{} '.format(g+1),end='')
    print()

Solution (Python):
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

arr = [[0 for i in range(w)] for j in range(h)]

now_x=0
now_y=0
move_r=True
for num in range(len(a)):
    for i in range(a[num]):
        arr[now_y][now_x] = num+1
        if move_r:
            if now_x == w-1:
                now_y+=1
                move_r=False
            else:
                now_x+=1
        else:
            if now_x == 0:
                now_y+=1
                move_r=True
            else:
                now_x-=1

for tmp in arr:
    print(' '.join(map(str, tmp)))

Solution (Python):
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))

CC = [[-1] * w for _ in range(h)]
col = 1
count = 0
dir = 0
x, y = 0, 0
cands = ((1, 0), (0, 1), (-1, 0), (0, -1))
for _ in range(h * w):
    CC[y][x] = col
    count += 1
    if count == A[col - 1]:
        count = 0
        col += 1
    dx, dy = cands[dir]
    nx, ny = x + dx, y + dy
    if nx < 0 or nx >= w or ny < 0 or ny >= h or CC[ny][nx] != -1:
        dir = (dir + 1) % 4
        dx, dy = cands[dir]
        nx, ny = x + dx, y + dy
    x, y = nx, ny

for C in CC:
    print(*C)

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

Solution (Python):
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])

Solution (Python):
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

c = [[0] * w for _ in range(h)]
li = [[0,0]]
hw = [0,0]
dir = 'r'

while len(li) < h*w:
    if dir == 'r':
        if hw[1] < h-1:
            if [hw[0], hw[1]+1] not in li:
                hw[1] += 1
                li.append([hw[0], hw[1]])
            else:
                dir = 'd'
        else:
            dir = 'd'
    elif dir == 'd':
        if hw[0] < w-1:
            if [hw[0]+1, hw[1]] not in li:
                hw[0] += 1
                li.append([hw[0], hw[1]])
            else:
                dir = 'l'
        else:
            dir = 'l'
    elif dir == 'l':
        if hw[1] > 0:
            if [hw[0], hw[1]-1] not in li:
                hw[1] -= 1
                li.append([hw[0], hw[1]])
            else:
                dir = 'u'
        else:
            dir = 'u'
    else:
        if hw[0] > 0:
            if [hw[0]-1, hw[1]] not in li:
                hw[0] -= 1
                li.append([hw[0], hw[1]])
            else:
                dir = 'r'
        else:
            dir = 'r'

count = 0

for i in range(n):
    for _ in range(a[i]):
        c[li[count][1]][li[count][0]] = i+1
        count += 1

for i in range(h):
    for j in range(w):
        print(c[i][j],end = ' ')
    print()

Solution (Python):
h,w = map(int,input().split())
n = int(input())

a = list(map(int,input().split()))

d = [[0]*w for i in range(h)]

I = 0
J = 0
for i in range(n):
    while a[i] > 0:
        d[I][J] = i+1
        a[i] -= 1
        if I%2 == 0 and J == w-1:
            I += 1
        elif I %2 == 1 and J == 0:
            I += 1
        else:
            if I%2 == 0:
                J += 1
            else:
                J -= 1

for i in range(h):
    print(*d[i])

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    h,w = inpm()
    n = inp()
    a = inpl()
    ans = [[0 for _ in range(w)] for _ in range(h)]
    x,y,key = 0,0,1
    for i in range(n):
        for j in range(a[i]):
            ans[x][y] = str(i+1)
            if key:
                x += 1
                if x == h:
                    key = 0
                    x -= 1
                    y += 1
            else:
                x -= 1
                if x == -1:
                    key = 1
                    x += 1
                    y += 1
    for i in range(h):
        print(' '.join(ans[i]))
    
if __name__ == "__main__":
    main()

Solution (Python):
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)

Solution (Python):
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

a_list=[]
for i in range(n):
 a_list+=[(i+1)]*a[i]

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)

Solution (Python):
H,W=map(int, input().split())
N=int(input())
A=[0]+list(map(int, input().split()))

M=[[0 for _ in range(W)] for __ in range(H)]
i=1
for y in range(H):
    if y&1:
        for x in range(W):
            if A[i]==0: i+=1
            M[y][x]=i
            A[i]-=1
    else:
        for x in range(W-1,-1,-1):
            if A[i]==0: i+=1
            M[y][x]=i
            A[i]-=1

for line in M: print(' '.join(map(str,line)))

Solution (Python):
import bisect
h,w = map(int,input().split())
n = int(input())
lst1 = list(map(int,input().split()))

lst2 = [[0]*w for _ in range(h)]

for i in range(1,n):
    lst1[i] += lst1[i-1]

res = 1

for i in range(h):
    if i%2 == 0:
        for j in range(w):
            lst2[i][j] = bisect.bisect_left(lst1,res) + 1
            res += 1

    else:
        for j in range(w-1,-1,-1):
            lst2[i][j] = bisect.bisect_left(lst1,res) + 1
            res += 1

for i in lst2:
    print(*i)

Solution (Python):
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])

Solution (Python):
H, W, N, *A = map(int, open(0).read().split())

ret = [[0 for i in range(W+2)] for j in range(H+2)]
for i in range(H+2):
  for j in range(W+2):
    if i == 0:
      ret[i][j] = 1
      continue
    if i == H+1:
      ret[i][j] = 1
      continue
    if j == 0:
      ret[i][j] = 1
      continue
    if j == W+1:
      ret[i][j] = 1
      continue

ret[1][1] = 1

x = 1
y = 1
dx = 1
dy = 0

for i, a in enumerate(A, 1):
  if i == 1:
    a -= 1
  while a > 0:
    _x = x + dx
    _y = y + dy
    if ret[_y][_x]:
      if dx == 1:
        dx = 0
        dy = 1
        continue
      if dx == -1:
        dx = 0
        dy = -1
        continue
      if dy == 1:
        dx = -1
        dy = 0
        continue
      if dy == -1:
        dx = 1
        dy = 0
        continue
    else:
      ret[_y][_x] = i
      x = _x
      y = _y
      a -= 1
      
for i in range(H):
  print(*ret[i+1][1:W+1])

Solution (Python):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

b = []
for i, j in enumerate(a):
    b += [i + 1] * j

for i in range(h):
    if i % 2 == 0:
        print(*b[i * w:i * w + w])
    else:
        print(*b[i * w:i * w + w][::-1])

Solution (Python):
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)

Solution (Python):
import numpy as np
h,w=map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
d = [i+1 for i,x in enumerate(a) for _ in range(x)]
d = np.array(d).reshape((h,w))
for i,x in enumerate(d):
  if i%2==0:
    print(*x,sep=" ")
  else:
    print(*x[::-1],sep=" ")

Solution (Python):
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])

Solution (Python):
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)))

Solution (Python):
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))))