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-----
2 2
3
2 1 1

-----Sample Output-----
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.

Difficulty: interview

Starter code:

Solutions:
h, w = map(int, input().split())
n = int(input())
A = tuple(map(int, input().split()))

M = [[0] * w for _ in range(h)]
ii = 0
ij = 0
for i, a in enumerate(A):
    i += 1
    for _ in range(a):
        M[ij][ii] = i

        if ij%2 == 0:
            ii += 1
            if ii == w:
                ij += 1
                ii = w-1
        else:
            ii -= 1
            if ii == -1:
                ij += 1
                ii = 0
for l in M:
    print(*l)

def main():
    H, W = list(map(int, input().split(' ')))
    N = int(input())
    A = list(map(int, input().split(' ')))
    colors = list()
    for i, a in enumerate(A):
        c = i + 1
        for _ in range(a):
            colors.append(c)
    assert len(colors) == H * W
    ans = [[0 for _ in range(W)] for _ in range(H)]
    # 蛇腹状にぬっていく
    for i, c in enumerate(colors):
        w = i // H
        h = min([i % (2 * H), 2 * H - 1 - (i % (2 * H))])
        ans[h][w] = c
    for row in ans:
        print((' '.join(map(str, row))))


def __starting_point():
    main()

__starting_point()

H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)

ans = [[-1 for _ in range(W)] for _ in range(H)]
color = 1

for i in range(H):
    for j in range(W):
        if A[color] == 0:
            color += 1
        A[color] -= 1
        ans[i][j] = color

for i in range(H):
    a = ans[i]
    if i % 2 == 1:
        a = a[::-1]
    print(" ".join(map(str, a)))

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

c=[[0 for i in range(W)] for i in range(H)]
k=0
for i in range(H):
    if i%2==0:
        for j in range(W):
            c[i][j]=k+1
            a[k]-=1
            if a[k]==0:
                k+=1
    else:
        for j in range(W-1,-1,-1):
            c[i][j]=k+1
            a[k]-=1
            if a[k]==0:
                k+=1
for i in range(H):
    for j in range(W):
        print(c[i][j],end=' ')
    print()


H, W = [int(x) for x in input().split()]
N = int(input())
a = [0] + [int(x) for x in input().split()]

ans = [[0 for _ in range(W)] for _ in range(H)]
c = 1  # 色
n = 0  # c色で塗られた数
for i in range(H):
    if i % 2 == 0:
        start = 0
        end = W
        by = 1
    else:
        start = W - 1
        end = -1
        by = -1
    for j in range(start, end, by):
        ans[i][j] = c
        n += 1
        if n >= a[c]:
            c += 1
            n = 0

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

def main():
    h, w, n, *a = list(map(int, open(0).read().split()))
    s = sum([[i + 1] * a[i] for i in range(n)], [])

    for i in range(h):
        print((' '.join(map(str, s[i * w:(i + 1) * w])) if i % 2 == 0 else ' '.join(map(str, s[i * w:(i + 1) * w][::-1]))))


def __starting_point():
    main()

__starting_point()

H,W = list(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(i)
##print(s)
num = 0
for i in range(H):
    tmp = []
    for j in range(W):
        tmp.append(s[num])
        num += 1
    
    if i%2 == 1:
        tmp.reverse()
    print((*tmp))


h,w = map(int,input().split())
n = int(input())
A = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    dic[i+1] = A[i]

Map = [0 for i in range(h*w)]
height = 0
width = 0
now = 0
color = list(dic.keys())

color_num = 0
while now < h*w:
    if height%2==0:
        Map[now] = color[color_num]
        dic[color[color_num]] -= 1
        if dic[color[color_num]]==0:
            color_num += 1
        width += 1
        if width==w:
            height += 1
            width = w-1
    else:

        Map[now] = color[color_num]
        dic[color[color_num]] -=1
        if dic[color[color_num]]==0:
            color_num += 1
        width -= 1
        if width==-1:
            height += 1
            width = 0
    now = height*w + width
st = 0

for i in range(h):
    print(*Map[st:st+w])
    st = st+w

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)
s = 0
for i in range(H):
    if i % 2== 0:
        print(*b[s:s+W])
    else:
        print(*b[s+W-1:s-1:-1])
    s += W

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

ans=[[0]*w for _ in range(h)]
i=0
j=0
jugh=0


if w==1:
    for i in range(n):
        for j in range(a[i]):
            print(i+1)
    return



for z in range(n):
    count=0
    while count<a[z]:
       # print(i,j,z+1)
        if jugh==0:
            ans[i][j]=z+1
            j+=1
            c=0
        elif jugh==2:
            if j==0:
                jugh=0
                c=1
                ans[i][j]=z+1
                j+=1
            else:
                
                jugh=1
                c=1
                
                ans[i][j]=z+1
                j-=1
        else:
            ans[i][j]=z+1
            j-=1
            c=0

        if j==w and c==0:
            i+=1
            j-=1
            jugh=2
        if j==-1 and c==0:
            i+=1
            j+=1
            jugh=2
            
        count+=1

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


import sys

H, W = map(int, sys.stdin.readline().split())
N = int(sys.stdin.readline())
A =  list(map(int, sys.stdin.readline().split()))

grid = [[0 for _ in range(W)] for _ in range(H)]
point = A[0]
color = 0
for i in range(H):
    for j in range(W):
        # 色iが接するように、左 -> 右 -> 下の列を右から、と染めていく
        if i % 2 == 0:
            x = j
        else:
            x = W - j - 1
        if point == 0:
            color += 1
            point = A[color]

        grid[i][x] = color + 1
        point -= 1

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


def solve():
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    a_line = []
    for i, i_cnt in enumerate(a):
        color = i+1
        for j in range(i_cnt):
            a_line.append(color)
    # wごとに区切ってlistに詰める
    ans = [['']*w for _ in range(h)]
    cur = 0
    for i in range(h):
        for j in range(w):
            ans[i][j] = str(a_line[cur])
            cur += 1
    for i in range(h):
        print(' '.join(ans[i] if i%2==0 else reversed(ans[i])))

solve()

from collections import deque

H, W = 2, 2
N = 3
ARR = [2, 1, 1]

H, W = 3, 5
N = 5
ARR = [1, 2, 3, 4, 5]

H, W = 1, 1
N = 1
ARR = [1]

H, W = list(map(int, input().split()))
N = int(input())
ARR = list(map(int,input().split()))

def calculate(h, w, n, arr):
    resources = deque()

    for index, ar in enumerate(arr):
        for m in range(ar):
            resources.append((index + 1))

    nodeStatus = [[False for i in range(w)] for j in range(h)]
    for j in range(h):
        if j % 2 == 0:
            startIndex = 0
            for i in range(startIndex, w, 1):
                nodeStatus[j][i] = str(resources.popleft())
        else:
            startIndex = w - 1
            for i in range(startIndex, -1, -1):
                nodeStatus[j][i] = str(resources.popleft())

    for j in range(h):
        print((" ".join(nodeStatus[j])))


calculate(H, W, N, ARR)


h, w = list(map(int, input().split()))
n = int(input())
a = [int(i) for i in input().split()]

color = [[None] * w for _ in range(h)]


def zigzag(h, w):
    ih, iw = 0, 0

    while ih < h:
        yield (ih, iw)

        if ih % 2 == 0:
            if iw == w - 1:
                ih += 1
            else:
                iw += 1
        else:
            if iw == 0:
                ih += 1
            else:
                iw -= 1


ia = 0
ic = 0

for ih, iw in zigzag(h, w):
    ia += 1
    if ia > a[ic]:
        ic += 1
        ia = 1

    color[ih][iw] = ic + 1


for row in color:
    print((' '.join(map(str, row))))


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

h,w=map(int,input().split());input();a,d,MAP,w1,h1=list(map(int,input().split())),[],[[0 for i in range(w)] for j in range(h)],0,0
for i,j in enumerate(a):
  for _ in range(j):
    if w1<w:
      MAP[h1][w1]= i+1
      w1+=1
      if w1==w:
        w1=0
        h1+=1
for i in range(h):
  if i%2!=0: MAP[i] = MAP[i][::-1]
[print(*i,sep=' ') for i in MAP]

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]*a[i])
  
for i in range(H):
  if i % 2 == 0:
    print(*ans[i*W:(i+1)*W])
  else:
    print(*ans[i*W:(i+1)*W][::-1])

h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
ans = [[0] * w for i in range(h)]
i = 0
j = 0
k = 0
flg = True
while i < h:
    ans[i][j] = str(k+1)
    a[k] -= 1
    if a[k] == 0:
        k += 1
    if flg:
        j += 1
        if j == w:
            j -= 1
            i += 1
            flg = False
    else:
        j -= 1
        if j == -1:
            j += 1
            i += 1
            flg = True
for i in range(h):
    print(' '.join(ans[i]))

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
i = 0

for x in range(H):
    c = []
    for y in range(W):
        c.append(i + 1)
        a[i] -= 1
        if a[i] == 0:
            i += 1
            
    if x % 2 == 0:
        print(*c)
    else:
        print(*c[::-1])

h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=(s:=w-t):
    if r%2: g[r]+=[i]*s
    else: g[r]=[i]*s+g[r]
    r+=1
    c-=s
    t=0
  if c:
    if r%2: g[r]+=[i]*c
    else: g[r]=[i]*c+g[r]
    t+=c
for r in g: print(*r)

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

for y in range(h):
  print((" ".join(list(map(str, mat[y])))))


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

l = [[] for _ in range(h)]
x = 0
y = 0
for i in range(n):
  for _ in range(a[i]):
    l[y].append(i+1)
    x += 1
    if x == w:
      x = 0
      y += 1
for i in range(h):
  if i%2 == 0: print((*l[i]))
  else: print((*reversed(l[i])))


from numpy import *
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
B = []
ans = zeros((H,W),int64)

for n in range(N):
  B.extend(A[n]*[n+1])

n = 0
for h in range(H):
  for w in range(W):
    if h%2==0:
      ans[h][w] = B[n]
    else:
      ans[h][-(w+1)] = B[n]
    n+=1

for h in range(H):
  print(*ans[h])


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

bb=[[0]*w for i in range(h)]
idx=0
kk=0
for i in range(h):
    if i%2==0:
        wst=0
        wed=w
        wpt=1
    else:
        wst=w-1
        wed=-1
        wpt=-1
        
    for j in range(wst,wed,wpt):
        if kk>=a[idx]:
            idx+=1
            kk=0
        bb[i][j]=str(idx+1)
        kk+=1
        
for i in range(h):
    print((" ".join(bb[i])))    


H,W=map(int,input().split())
N=int(input())
alist=list(map(int,input().split()))

cmat=[[-1]*W for _ in range(H)]

x,y=0,0
c=1
for a in alist:
  while a:
    #print(x,y)
    cmat[x][y]=c
    y+=1
    a-=1
    
    if y==W:
      x+=1
      y=0
  c+=1
      
#print(cmat)
for i in range(H):
  if i%2==1:
    cmat[i].reverse()
  print(*cmat[i])

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

from collections import defaultdict
h, w=list(map(int,input().split()))
n=int(input())
a=list(map(int,input().split()))

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

b=[]
for i in range(n):
    for k in range(a[i]):
        b.append(i+1)

hidx=0
widx=0
for i in range(len(b)):
    ans[hidx][widx]=b[i]
    if hidx%2==0:
        widx+=1
    else:
        widx-=1
    if widx==w:
        widx=-1
        hidx+=1
    if widx==-(w+1):
        widx=0
        hidx+=1

for i in range(h):
    answer=ans[i]
    L=[str(a) for a in answer]
    L=" ".join(L)
    print(L)




import numpy as np
H,W = map(int,input().split())
N = int(input())
lsa = list(map(int,input().split()))
ls2 = []
for i in range(N):
    ls2 += [i+1]*lsa[i]
arr = np.array(ls2)
arr = arr.reshape(H,W).tolist()
arr2 = []
for i in range(H):
    if i % 2 == 0:
        arr2.append(arr[i])
    else:
        arr[i].reverse()
        arr2.append(arr[i])
for i in range(H):
    arr2[i] = [str(j) for j in arr2[i]]
    print(' '.join(arr2[i]))

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
def main():
  ans = [[0]*W for _ in range(H)]
  color = 0
  num = 0
  for i in range(H):
    if i % 2 == 0:
      for j in range(W):
        ans[i][j] = color+1
        num += 1
        if num == a[color]:
          color += 1
          num = 0
    else:
      for j in range(W-1, -1, -1):
        ans[i][j] = color+1
        num += 1
        if num == a[color]:
          color += 1
          num = 0
  for i in range(H):
    print(*ans[i])
  
def __starting_point():
  main()        
__starting_point()

h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=w-t:
    g[r]+=[i]*(w-t)
    r+=1; c-=w-t; t=0
  if c:
    g[r]+=[i]*c
    t+=c
for i in range(h): print(*g[i][::2*(i%2)-1])


H,W=list(map(int,input().split()))
N=int(input())
S=list(map(int,input().split()))

T = [[0 for j in range(W)] for i in range(H)]
posx=1
posy=1
for i in range(N):
    tmp=S[i]
    cnt=0
    while tmp>cnt:
        T[posy-1][posx-1]=i+1
        if posy%2!=0:
            posx+=1
            if posx>W:
                posy+=1
                posx-=1
        else:
            posx-=1
            if posx<1:
                posy+=1
                posx+=1
        cnt+=1  

for i in T:
    print((*i))



def main():
	H, W = [int(x) for x in input().split(" ")]
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	c = [[0] * W for i in range(H)]
	k = 0
	for i in range(len(c)):
		for j in range(len(c[i])):
			if i % 2 == 0:
				c[i][j] = str(k + 1)
				A[k] -= 1
			elif i % 2 == 1:
				c[i][-j-1] = str(k + 1)
				A[k] -= 1
			if A[k] == 0:
				k += 1
	print("\n".join([" ".join(ci) for ci in c]))

main()

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

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

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

ans = sum(([i]*ai for i,ai in enumerate(a,1)),[])
ans = [ans[i*w:(i+1)*w] if i%2 ==0 else ans[(i+1)*w-1:i*w-1:-1] for i in range(h)]
for c in ans:
    print(*c)

h,w = list(map(int,input().split()))
n = int(input())
ls = list(map(int,input().split()))
di = []
def split_list(l, n):
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]
for i in range(n):
    for j in range(ls[i]): 
        di.append(i+1)
new = list(split_list(di, w))
for j in range(len(new)):
    if j % 2 == 0:
        new[j].sort(reverse=True)
for k in range(len(new)):
    print((*new[k]))


H,W,N,*A = map(int,open(0).read().split())
B = []

for n in range(N):
  B+=A[n]*[n+1]

for h in range(H):
  print(*B[h*W:h*W+W][::1-h%2*2])

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 == 0:
    print(*ans[i*W:(i+1)*W])
  else:
    print(*reversed(ans[i*W:(i+1)*W]))

h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
c=[0]*(w*h)
k=0
for l,i in enumerate(a):
  for j in range(i):
    c[k]=l+1
    k+=1
def split_list(l, n):
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]
ans = list(split_list(c, w))
for i,j in enumerate(ans):
  if i%2==0:
    print(*j)
  else:
    print(*j[::-1])

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

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

X = []
for i, a in enumerate(A):
    X += [i + 1] * a

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

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


h,w=map(int,input().split());input();a,MAP,w1,h1=list(map(int,input().split())),[[0 for i in range(w)] for j in range(h)],0,0
for i,j in enumerate(a):
  for _ in range(j):
    if w1<w:
      MAP[h1][w1]= i+1
      w1+=1
      if w1==w:
        w1=0
        h1+=1
for i in range(h):
  if i%2!=0: MAP[i]=MAP[i][::-1]
[print(*i,sep=' ') for i in MAP]

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


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

for i in range(len(a)):
  l += [(i+1)]*a[i]
  
for i in range(h):
  if i%2 == 0:
    print(*l[i*w:(i+1)*w])
  else:
    print(*list(reversed(l[i*w:(i+1)*w])))

H, W = list(map(int, input().split()))
N = int(input())
from collections import deque

A = deque(list(map(int, input().split())))
nuriwake = 1
ans = []
for i in range(H):
    t = []
    for j in range(W):
        if A[0] == 0:
            A.popleft()
            nuriwake += 1
        A[0] -= 1
        t.append(nuriwake)
    if i % 2 != 0:
        t = reversed(t)
    ans.append(t)
for a in ans:
    print((' '.join(map(str, a))))


H, W = map(int, input().split())
N = int(input())

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

l_list = []

for i in range(N):
    l_list += [i+1] * a[i]

judge = 0
for i in range(H):
    p_list = l_list[i*W:(i+1)*W]
    if judge % 2 == 1:
        p_list = p_list[::-1]
    for j in p_list:
        print(j, end=' ')
    print()
    judge += 1

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

ans=[[0]*W for _ in range(H)]
p=[0,0]
for i in range(N):
    cnt=a[i]
    while cnt>0:
        ans[p[0]][p[1]]=i+1
        if p[1]%2==0:
            if p[0]==H-1:
                p[1]+=1
            else:
                p[0]+=1
        else:
            if p[0]==0:
                p[1]+=1
            else:
                p[0]-=1
        cnt-=1

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

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

H,W = I()
N = i()
a = l()
list = []
for i in range(N):
    for j in range(a[i]):
        list.append(i+1)
ans = [[] for _ in range(H)]
for i in range(H):
    for j in range(W):
        ans[i].append(list.pop(0))
for i in range(H):
    if i%2 == 1:
        print(*ans[i][::-1])
    else:
        print(*ans[i])

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    h,w = i_map()
    n = i_input()

    a = i_list()
    ans = []
    for m,i in enumerate(a):
        ans.extend([str(m+1)]*i)
    ans = list(ans)
    for i in range(1,h+1):
        if i%2 == 0:
            print((" ".join(ans[w*(i-1):w*(i-1)+w])))
        else:
            print((" ".join(ans[w*(i-1):w*(i-1)+w][::-1])))

def __starting_point():
    main()

__starting_point()

from collections import deque
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))

#print(a)
j=1
for i in range(H):
    x=deque()
    while len(x)<W:
        if i%2==0:
            a[j-1]-=1
            x.append(str(j))
        else:
            a[j-1]-=1
            x.appendleft(str(j))
        if a[j-1]==0:
            j+=1
    A=" ".join(list(x))
    print(A)

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]

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

def main():
    h, w, n, *a = list(map(int, open(0).read().split()))
    l = [[i + 1] * a[i] for i in range(n)]
    s = sum(l, [])

    f = False
    ans = ''
    for i in range(h):
        x = s[i * w: (i + 1) * w]
        if f:
            x = x[::-1]
        f = not f
        ans += ' '.join(map(str, x)) + '\n'

    print(ans)


def __starting_point():
    main()

__starting_point()

H, W = list(map(int, input().split()))
N = int(input())
a = [int(x) for x in input().split()]
temp = []
for i in range(N):
    for _ in range(a[i]):
        temp.append(i+1)
ans = []
for i in range(H):
    ans = temp[i*W:(i+1)*W]
    if i&1:
        ans.reverse()
    print((*ans))


H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
c = [[None]*W for _ in range(H)]
dirs = [(0,1),(1,0),(0,-1),(-1,0)]
i,j = 0,0
d = 0
color = 0
for _ in range(H*W):
    c[i][j] = color+1
    a[color] -= 1
    if a[color] == 0:
        color += 1
    di,dj = dirs[d]
    ni,nj = i+di,j+dj
    if 0 <= ni < H and 0 <= nj < W and c[ni][nj] == None:
        i,j = ni,nj
        continue
    d = (d+1) % 4
    di,dj = dirs[d]
    i,j = i+di,j+dj
for l in c:
    print(*l)

h, w = map(int, input().split())
n = int(input())
colors = list(map(int, input().split()))
cmap = [(i+1,a) for i,a in enumerate(colors)]
campus=[0]*(h*w)

def printmtrx(campus):
    ts=""
    for idx,i in enumerate(campus):
        if((idx+1)%w==1):
            if idx==0:
                ts += str(i) + " "
            else:
                ts+="\n"+str(i)+" "
        else:
            if (idx+1)%w==0:
                ts += str(i)
            else:
                ts+=str(i)+" "
    print(ts)

def printmtrx2(campus):
    cnt=0
    for i in range(h):
        ts=""
        for j in range(w):
            if not j==0:
                ts+=" "
            ts+=str(campus[cnt])
            cnt+=1
        print(ts)

#print(cmap)
#print(campus)

cnt=cmap[0][1]
idx=0
campusidx=0
direct=0
while cnt:
    #print(campusidx)
    #printmtrx(campus)
    #print("")
    campus[campusidx]=cmap[idx][0]
    cnt-=1
    if(cnt<1):
        idx+=1
        if(idx>=len(cmap)):
            break
        cnt=cmap[idx][1]
    campusidx+=1-2*direct
    if campusidx%w==0 and direct==0:
        campusidx+=w-1
        direct=1
    elif campusidx%w==w-1 and direct==1:
        campusidx+=w+1
        direct=0
printmtrx2(campus)

h, w = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
ret = [[0] * w for i in range(h)]

line = []

for i, item in enumerate(a):
    line.extend([i+1] * item)

for i, item in enumerate(line):
    sho = i // w
    amari = i % w
    if sho % 2 == 0:
        ret[sho][amari] = item
    else:
        ret[sho][w-1-amari] = item

for item in ret:
    print((' '.join(map(str, item))))


h, w = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(len(a)):
  c += [i + 1] * a[i]
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]))


def resolve():
    H, W = list(map(int, input().split()))
    N = int(input())
    A = list(map(int, input().split()))
    C = [[0 for _ in range(W)] for __ in range(H)]
    color = 1
    reverse = False
    cnt = 0
    for i in range(H):
        for j in range(W):
            if reverse:
                _j = W-1 - j
            else:
                _j = j
            C[i][_j] = color
            cnt += 1
            if cnt == A[color-1]:
                color += 1
                cnt = 0
        reverse = not reverse
    [print(" ".join(map(str, C[i]))) for i in range(H)]
        

if '__main__' == __name__:
    resolve()

H,W,N,*a = map(int, open(0).read().split())
ans = [[0] * W for _ in range(H)]
count = 0
using = 0
for i in range(H*W):
    dm = divmod(i,W)
    h = dm[0]
    if h % 2 == 0:
        w = dm[1]
    else:
        w = (dm[1]+1) * (-1)
    ans[h][w] = using + 1
    count += 1
    if count == a[using]:
        using += 1
        count = 0
for x in ans:
    print(*x)

h, w = [int(x) for x in input().split()]
n = int(input())
a = [int(x) for x in input().split()]
 
ans = [["0"] * w for x in range(h)]
 
now = 0
for i in range(n):
  for j in range(a[i]):
    cc = now
    x = cc // w
    cc %= w
    if x % 2 == 0:
      y = cc
    else:
      y = w - cc - 1
    #print(now,i,x,y)
    ans[x][y] = str(i + 1)
    now += 1
 
for i in range(h):
  print(" ".join(ans[i]))

from collections import deque
h,w=list(map(int,input().split()))
n=int(input())
a=list(map(int,input().split()))
ae=[]
ans=[]
rl=0
for i in range(n):
  ae.extend([i+1]*a[i])
for x in range(h):
  if x%2==0:
    ans.append(ae[w*x:w*(x+1)])
  else:
    ans.append(reversed(ae[w*x:w*(x+1)]))

for r in ans:
  print((' '.join(list(map(str,r)))))
  
  
  


import numpy as np

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

out = []

for i, a in enumerate(A):
    for j in range(a):
        out.append(i + 1)

# print(out)
out = np.array(out).reshape((H, W))
# print(out, out.shape)

sign = 1
for li in out:
    print((*li[::sign]))
    sign *= -1


h,w=map(int,input().split());input();a,MAP,w1,h1=list(map(int,input().split())),[[0 for i in range(w)] for j in range(h)],0,0
for i,j in enumerate(a):
  for _ in range(j):
    if w1<w:
      MAP[h1][w1]= i+1
      w1+=1
      if w1==w:
        w1=0
        h1+=1
for i in range(h):
  if i%2!=0: MAP[i] = MAP[i][::-1]
[print(*i,sep=' ') for i in MAP]



def fill(color_no,color_count,pos_x,pos_y,W,grid):
  
  while color_count > 0:
    grid[pos_y][pos_x] = color_no
    #print(pos_x,pos_y,grid)
    ## 右端に到達
    if pos_x == W-1  and pos_y%2 == 0:
      pos_y = pos_y+1
    ## 左端に到達
    elif pos_x == 0  and pos_y%2 == 1:
      pos_y = pos_y+1
    ##右から左へ
    elif pos_y%2 == 0:
      pos_x = pos_x+1
    ##左から右へ
    elif pos_y%2 == 1:
      pos_x = pos_x-1
    color_count = color_count-1
    
  return pos_x,pos_y,grid
H,W = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))

Grid = [[0]*W for i in range(H)]
pos_x = 0
pos_y = 0
for i in range(N):
  pos_x,pos_y,Grid = fill(i+1,A[i],pos_x,pos_y,W,Grid)

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


import sys
readline = sys.stdin.readline

def main():
    H, W = map(int, readline().rstrip().split())
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    res = [[-1] * W for _ in range(H)]
    ht, wt = 0, 0
    for i, a in enumerate(A):
        while a:
            res[ht][wt] = i+1
            a -= 1
            if (ht % 2 == 0 and wt == W-1) or (ht % 2 == 1 and wt == 0):
                ht += 1 
            elif  ht % 2 == 0:
                wt += 1
            else:
                wt -= 1
                
    for l in res:
        print(*l, sep=' ')

def __starting_point():
    main()
__starting_point()

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
data = [[] for _ in range(H)]

k = 0
for i in range(N):
    for j in range(a[i]):
        data[k].append(i + 1)
        if len(data[k]) == W:
            k += 1

for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            print(data[i][j],'', end = '')
    else:
        for j in range(W):
            print(data[i][W - j - 1],'', end = '')
    print()





import numpy as np
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

B = []
for i, a in enumerate(A, start=1):
    for _ in range(a):
        B.append(i)

B = np.array(B)
B = B.reshape(H, W)

for h in range(H):
    if h % 2 == 1:
        B[h] = B[h, ::-1]

for b in B:
    print(*b)

H,W=map(int,input().split())
N=int(input())
alist=list(map(int,input().split()))

cmat=[]
for i in range(H):
  cmat.append([-1]*W)

x,y=0,0
c=1
for a in alist:
  while a:
    if y<W:
      #print(x,y)
      cmat[x][y]=c
      y+=1
      a-=1
    
    if y==W:
      x+=1
      y=0
  
  c+=1
      
#print(cmat)
for i in range(1,H,2):
  cmat[i].reverse()
#print(cmat)
      
for i in range(H):
  print(*cmat[i])

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W = MAP()
N = INT()
a = LIST()

cnt = 0
ans = [[-1]*W for _ in range(H)]
tmp = a.pop(0)
color = 1
flg = 0

for i in range(H):
	for j in range(W):
		if i%2 == 1:
			j = -j-1
		ans[i][j] = color
		tmp -= 1
		if tmp == 0:
			if not a:
				break
			tmp = a.pop(0)
			color += 1



for i in ans:
	print((" ".join([str(x) for x in i])))


with open(0) as f:
    H, W, N, *a = map(int, f.read().split())

line = []
for i in range(N):
    line += [i+1] * a[i]
ans = [line[i*W:(i+1)*W] for i in range(H)]
for i, v in enumerate(ans):
    if i&1:
        v.reverse()
    print(*v)

h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
R = []
for i in range(n):
    for j in range(a[i]):
        R.append(i+1)
E = []
for i in range(h):
    E.append(R[i*w:(i*w)+w])
for i in range(h):
    if i%2:
        print(" ".join(map(str,reversed(E[i]))))
    else:
        print(" ".join(map(str,E[i])))

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


import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

H, W = mi()
N = ii()
A = li()

table = dp2(0, W, H)
i = -1
j = 0
for ind in range(N):
    a = A[ind]
    while a > 0:
        if i+1 < H and not table[i+1][j]:
            table[i+1][j] = ind+1
            i += 1
        elif j+1 < W and not table[i][j+1]:
            table[i][j+1] = ind+1
            j += 1
        else:
            if i > 0 and not table[i-1][j]:
                table[i-1][j] = ind+1
                i -= 1
            elif j > 0 and not table[i][j-1]:
                table[i][j-1] = ind+1
                j -= 1
        a -= 1

for i in range(H):
    for j in range(W):
        print(table[i][j], '', end='')
    print('')

H,W=map(int,input().split())
L=[[0 for j in range(W)] for i in range(H)]
N=int(input())
R=list()
a=list(map(int,input().split()))
for i in range(N):
  R+=[i+1]*a[i]
for i in range(H):
  if i%2==0:
    s=list(R[i*W:(i+1)*W])
    s=list(map(str,s))
    print(" ".join(s))
  else:
    s=list(R[i*W:(i+1)*W])
    s=list(reversed(s))
    s=list(map(str,s))
    print(" ".join(s))

import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return list(map(int, stdin.readline().split()))
def nl(): return list(map(int, stdin.readline().split()))


def nextidx(h, x, y, dir):
    if y == h - 1 and dir == -1:
        return x + 1, y, 1
    elif y == 0 and dir == 1:
        return x + 1, y, -1
    else:
        return x, y - dir, dir


def main():
    h, w = nm()
    n = ni()
    A = nl()
    M = [[0] * w for _ in range(h)]
    dir = -1
    x = 0
    y = 0
    for i in range(n):
        for j in range(A[i]):
            M[x][y] = i + 1
            y, x, dir = nextidx(h, y, x, dir)
    for m in M:
        print((*m))


def __starting_point():
    main()

__starting_point()

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

ans = []
for i, ai in enumerate(a):
  ans.extend([str(i+1)] * ai)
  
for i in range(h):
  l = ans[i * w : (i + 1) * w ]
  if i % 2:
    l.reverse()
  print(' '.join(l))

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

res=[]

for i in range(n):
    for j in range(al[i]):
        res.append((i+1))

for k in range(h):
    temp = res[k*w:(k+1)*w]        
    if k % 2==1:
        temp = list(reversed(temp))
    else:
        pass
    print(str(temp).replace("[","").replace("]","").replace(","," "))

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

v=0
d=0
df=0
for i in range(n):
    t=i+1
    f=0
    while f<a[i]:
        if df==0:
            ans[v][d]=t

        elif df==1:

            ans[v][w-1-d]=t
        f+=1
        d+=1
        if df==0 and d==w:
            v+=1
            df^=1
            d=0
        if df==1 and w-d==0:
            v += 1
            df ^= 1
            d = 0
for h in ans:
    print(*h)

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

h,w=map(int,input().split());input();a,d,MAP,w1,h1=list(map(int,input().split())),[],[[0 for i in range(w)] for j in range(h)],0,0
for i,j in enumerate(a):
  for _ in range(j):
    if w1<w:
      MAP[h1][w1]= i+1
      w1+=1
      if w1==w:
        w1=0
        h1+=1
if h>2 and w>2:
  for i in range(h):
    if i%2!=0:
      MAP[i] = MAP[i][::-1]
[print(*i,sep=' ') for i in MAP]

H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(N):
    D[i + 1] = A[i]
C = []
for k, v in D.items():
    [C.append(k) for _ in range(v)]
h = 0
while True:
    h += 1
    for i in range(W):
        print(C[i], end=' ')
    print('')
    [C.pop(0) for _ in range(W)]
    if h == H:
        break
    h += 1
    for i in reversed(range(W)):
        print(C[i], end=' ')
    print('')
    [C.pop(0) for _ in range(W)]
    if h == H:
        break

h, w = [int(x) for x in input().split()]
n = int(input())
a = [int(x) for x in input().split()]

ans = [["0"] * w for x in range(h)]

now = 0
for i in range(n):
  for j in range(a[i]):
    cc = now
    x = cc // w
    cc %= w
    if x % 2 == 0:
      y = cc
    else:
      y = w - cc - 1
    #print(now,i,x,y)
    ans[x][y] = str(i + 1)
    now += 1

for i in range(h):
  print(" ".join(ans[i]))

h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=(s:=w-t):
    g[r]+=[i]*s
    r+=1; c-=s; t=0
  if c:
    g[r]+=[i]*c
    t+=c
for i in range(h): print(*g[i][::2*(i%2)-1])

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

b = []

ans = [[0]*w]*h

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

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

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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = na()
N = ni()
a = na()
ans = []
for i in range(N):
    for _ in range(a[i]):
        ans.append(i+1)
for i in range(H):
    if i % 2 == 0:
        print(*ans[i*W:(i+1)*W])
    else:
        print(*ans[i*W:(i+1)*W][::-1])

def main():
    def flatten_list(l):
        for el in l:
            if isinstance(el, list):
                yield from flatten_list(el)
            else:
                yield el
    H, W = list(map(int, input().split()))
    n = int(input())
    A = list(map(int, input().split()))
    ans = []
    for i, a in enumerate(A):
        ans .append([str(i + 1)] * a)
    ans = list(flatten_list(ans))
    ans = [ans[i:i + W] if i // W % 2 == 0 else ans[i + W - 1:i - 1:-1] for i in range(0, len(ans), W)]
    [print(' '.join(a)) for a in ans]

def __starting_point():
    main()

__starting_point()

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
N = INT()
a = LIST()[::-1]

ans = [[0]*W for _ in range(H)]
tmp = a.pop()
color = 1
cnt = 0
for i in range(H):
    for j in range(W):
        if i%2:
            j = W-j-1
        ans[i][j] = color
        cnt += 1
        if cnt == tmp and a:
            cnt = 0
            tmp = a.pop()
            color += 1

for i in ans:
    print((" ".join([str(x) for x in i])))


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

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

i = 0
j = 0
num = 1
while True:
    mat[j][i] = num
    a[num-1] -= 1
    if a[num-1] == 0:
        num += 1
    if i <= w-2:
        i += 1
    elif i == w-1:
        if j == h-1:
            break
        i = 0
        j += 1

for i in range(h):
    if i % 2 == 1:
        tmp = mat[i]
        tmp.reverse()
        mat[i] = tmp

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

h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
temp=[]
for i in range(n):
    for _ in range(a[i]):
        temp.append(i+1)

ans=[]
for j in range(h):
    if j%2==0:
        ans.append(list(temp[j*w:(j+1)*w]))
    else:
        ans.append(list(temp[(j+1)*(w)-1:j*w-1:-1]))
   
        

for k in ans:
    ans2=[str(v) for v in k]
    print(" ".join(ans2))

import numpy as np

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

colors = np.array([[0]*W]*H)

i = 0
j = 0
flag = True
count = 0
for k in range(N):
    for m in range(a[k]):
        colors[i, j] = str(k+1)
        count += 1
        if count % W == 0:
            i += 1
            if flag == True:
                flag = False
            else:
                flag = True
            continue
        if flag == True:
            j += 1
        else:
            j -= 1

for i in range(H):
    s = list(colors[i])
    for j in range(W):
        s[j] = str(s[j])
    p = ' '.join(s)
    print(p)


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

H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
now = 0
grid = [0]*(H*W)

for i in range(N):
  for j in range(now,now+a[i]):
    grid[j] = i+1
  now += a[i]

reverse = 0

for k in range(0,H*W,W):
  if reverse:
    print(*grid[k+W-1:k-1:-1])
    reverse = 0
  else:
    print(*grid[k:k+W])
    reverse = 1

from collections import deque
H,W = map(int,input().split())
n = int(input())
a_ls = list(map(int, input().split()))
color_q = deque()
for color, times in enumerate(a_ls,1):
    for _ in range(times):
        color_q.append(color)
ans_mat = [[0] * W for _ in range(H)]
for y in range(H):
    for x in range(W):
        ans_mat[y][x] = color_q.popleft()
for i,y in enumerate(range(H)):
    ans_ls = ans_mat[y]
    if i % 2 == 1:
        ans_ls = ans_ls[::-1]
    ans_ls = list(map(str,ans_ls))
    print(' '.join(ans_ls))

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

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

g = [[1]*(W+2)]
for i in range(H):
    g.append([1] + [0]*W + [1])
g.append([1]*(W+2))

temp = [[1, 1]]
g[1][1] = 1
c, cnt = 1, 0
while temp:
    p = temp.pop()
    for y, x in [[0, 1], [0, -1], [1, 0]]:
        if g[p[0]+y][p[1]+x] == 0:
            temp.append([p[0]+y, p[1]+x])
            if c == a[cnt]:
                cnt += 1
                c = 1
            else: c += 1
            g[p[0]+y][p[1]+x] = cnt+1
            break
for gg in g[1:-1]:
    print(*gg[1:-1])

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 == 0: print(*ans[i*w:(i+1)*w])
  else: print(*reversed(ans[i*w:(i+1)*w]))

import numpy as np

def abc069_d():
    H, W = map(int, input().split())
    _ = int(input())
    A = list(map(int, input().split()))

    # いったん1次元に並べる
    flat = []
    for i, a in enumerate(A):
        flat += [i+1] * a

    # 2次元に変形して、1行飛ばしで反転(折り返して往復すればつながる)
    grid = np.array(flat, dtype=int).reshape((H, W))
    for i in range(H):
        if i % 2 == 0:
            print(*grid[i], sep=' ')
        else:
            print(*grid[i, ::-1], sep=' ')

abc069_d()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, N, *A = list(map(int, read().split()))

    C = [[0] * W for _ in range(H)]
    vec = [i for i, a in enumerate(A, 1) for _ in range(a)]

    for i in range(H):
        for j in range(W):
            color = vec[i * W + j]
            if i % 2 == 0:
                C[i][j] = color
            else:
                C[i][W - j - 1] = color

    for row in C:
        print((*row))

    return


def __starting_point():
    main()

__starting_point()

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

h, w = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
color = [[0]*w for i in range(h)]
loch = 0
locw = 0
for i in range(n):
  for j in range(a[i]):
    color[loch][locw]=str(i+1)
    if loch % 2 == 0:
      if locw != w-1:
        locw+=1
      else:
        loch+=1
    else: 
      if locw != 0:
        locw-=1
      else:
        loch+=1

for i in range(h):
  print((" ".join(color[i])))