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):
from collections import deque

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

q = deque([])
for i,a in enumerate(al):
    c = i+1
    for _ in range(a):
        q.append(c)


for hi in range(h):
    for wi in range(w):
        if hi%2 == 0: ind = wi
        else: ind = ind = w-1-wi
        ans[hi][ind] = q.popleft()

for row in ans:
    print(*row)

Solution (Python):
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [[-1]*W for _ in range(H)]
col = []

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

idx = 0

for i in range(H):
    if i%2==0:
        for j in range(W):
            ans[i][j] = col[idx]
            idx += 1
    else:
        for j in range(W-1, -1, -1):
            ans[i][j] = col[idx]
            idx += 1

for ans_i in ans:
    print(*ans_i)

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

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

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

col=[]
cnt=1
for i in a:
    col.extend([cnt]*i)
    cnt+=1

ans=[[0]*W for _ in range(H)]
idx=0
for h in range(H):
    if h%2==0:
        for w in range(W):
            ans[h][w]=col[idx]
            idx+=1
    elif h%2==1:
        for w in range(W-1,-1,-1):
            ans[h][w]=col[idx]
            idx+=1

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

Solution (Python):






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





c = 0
tmp = 1
for h in range(H):
    line = []
    for w in range(W):
        line.append(c+1)
        tmp += 1
        if tmp > a[c]:
            c += 1
            tmp = 1
    if h%2 == 0:
        print(" ".join(map(str,line)))
    else:
        print(" ".join(map(str,list(reversed(line)))))

Solution (Python):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(H):
    ans.append([0] * W)

now = 0
cnt = 0
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            ans[i][j] = now + 1
            cnt += 1
            if cnt == A[now]:
                now += 1
                cnt = 0
    else:
        for j in range(W - 1, -1, -1):
            ans[i][j] = now + 1
            cnt += 1
            if cnt == A[now]:
                now += 1
                cnt = 0
for row in ans:
    print(*row, sep=' ')

Solution (Python):
H,W=map(int,input().split())
N=int(input())
*A,=map(int,input().split())
A=[0]+A
ans=[[0]*W for _ in range(H)]
countH=0
countW=0
i=0
for a in A:
    for _ in range(a):
        ans[countH][countW]=str(i)
        if countW==W-1 and countH%2==0:
            countH+=1
        elif countW==0 and countH%2==1:
            countH+=1
        elif countH%2==0:
            countW+=1
        elif countH%2==1:
            countW-=1
    i+=1

for s in ans:
    print(*s)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)



import numpy as np



INF = 1 << 50

def run():
    H, W = map(int, sysread().split())
    N = int(sysread())
    A = list(map(int, sysread().split()))
    MAP = np.zeros(H * W, dtype=np.int32)
    idx = 0
    for i, a in enumerate(A, 1):
        MAP[idx:idx+a] = i
        idx += a

    MAP = MAP.reshape(H,W)
    for i in range(1, len(MAP), 2):
        MAP[i, :] = MAP[i, ::-1]

    for row in MAP:
        for val in row:
            print(val, end=' ')
        print('')


if __name__ == "__main__":
    run()

Solution (Python):
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
l = [[0]*W for _ in range(H)]
bol = 1
line,cnt = 0,0

for i in range(1,N+1):
    for j in range(a[i-1]):
        if bol == 1:
            l[line][cnt] = i
        else:
            l[line][-cnt-1] = i
        cnt += 1
        if cnt == W:
            cnt = 0
            line += 1
            bol *= -1

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

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

    map_list = [[-1]*W for i in range(H)]

    pre = A.pop(0)
    idx = 1
    for i in range(H):
        if i%2==0:
            start = 0
            end = W
            step = 1
        else:
            start = W-1
            end = -1
            step = -1

        for j in range(start,end,step):
            if pre==0:
                pre = A.pop(0)
                idx += 1
        
            pre-=1
            map_list[i][j]= idx

    for i in range(H):
        print(' '.join(map(str,map_list[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, 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]))

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

L = []
for i in range(N):
    k = a[i]
    while k > 0:
        k -= 1
        L.append(i + 1)


c = 0
count = 0
for i in range(H):
    if (count % 2 == 0):
        A = []
        while c < W * (i + 1):
            A.append(str(L[c]))
            c += 1
        print(' '.join(A))
    else:
        B = []
        while c < W * (i + 1):
            B.append(str(L[c]))
            c += 1
        print(' '.join(B[:: -1]))

    count += 1

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

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

Solution (Python):
from collections import deque

H, W = map(int, input().split())
N = int(input())
A = []
B = list(map(int,input().split()))
for i in range(N):
    for j in range(B[i]):
      A.append(i)
flg = True
c = []
for k in range(1,H*W+1):
  c.append(A[k-1]+1)
  if k % W == 0:
    if flg:
      for s in c:
        print(s, end = ' ')
    else:
      for s in reversed(c):
        print(s, end = ' ')
    c = []
    print()
    flg = not flg

Solution (Python):
import sys
import numpy as np
input = sys.stdin.readline

H,W=list(map(int,input().split()))
N=int(input())
a=list(map(int,input().split()))
ans = []
for i,ai in enumerate(a):
    ans +=[i+1]*ai
ans = np.array(ans).reshape(H,W).tolist()
for i in range(len(ans)):
    if i%2 == 0:
        print(*ans[i])
    else:
        print(*(ans[i][::-1]))

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

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

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

tt = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            ans[i][j] = temp[tt]
            tt+=1
    else:
        for j in range(w-1, -1, -1):
            ans[i][j] = temp[tt]
            tt+=1

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

Solution (Python):
import numpy as np
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)

n = np.array(ans).reshape(H, W)
for i in range(H):
  if i % 2 == 0:
    p = n[i]
    print(*p)
  else:
    p = n[i][::-1]
    print(*p)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W = mapint()
N = int(input())
As = list(mapint())
query = [0]*W*H

idx = 0
for i in range(N):
    a = As[i]
    for j in range(a):
        query[idx] = i+1
        idx += 1

idx = 0
for h in range(H):
    if h%2==0:
        print(*query[idx:idx+W])
        idx += W
    else:
        print(*query[idx:idx+W][::-1])
        idx += W

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

Solution (Python):
import numpy as np
import collections

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

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

Currentx = 0
Currenty = 0
colour = 0

while A:
	D = A.popleft()
	colour+=1
	for i in range (0, D):
		if Currentx == W-1 and Currenty%2 == 0:
			Graph[Currenty][Currentx] = colour
			Currenty+= 1
		elif Currentx == 0 and Currenty%2 == 1:
			Graph[Currenty][Currentx] = colour
			Currenty+= 1
		elif Currenty%2 == 0:
			Graph[Currenty][Currentx] = colour
			Currentx+= 1			
		else:
			Graph[Currenty][Currentx] = colour
			Currentx-= 1				

for i in range (0, H):
	print(*Graph[i], sep = " ")

Solution (Python):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    g = []
    for i, x in enumerate(a):
        g += [i+1]*x
    import numpy as np
    g = np.array(g, dtype=int).reshape((h,w))
    for i in range(h):
        if i%2 == 1:
            g[i,:] = g[i, ::-1]
        print(' '.join(map(str, g[i])))

    
if __name__ == '__main__':
    main()

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

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi



import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    n, m = [int(x) for x in input().split()]
    t = int(input())
    a = [int(x) for x in input().split()]
    k = 0
    for i in range(n):
        r = []
        while len(r) != m:
            if not a[k]:
                k += 1
            x = min(m - len(r), a[k])
            a[k] -= x
            r += [k+1] * x
        if i % 2:
            r.reverse()
        print(*r)  


t = 1

for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Solution (Python):
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 map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return 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]))

Solution (Python):
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 map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return 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]))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

from collections import deque





def solve():
    H, W = MI()
    N = II()
    A = LI()

    q = deque([])
    for i, a in enumerate(A):
        for _ in range(a):
            q.append(i+1)
    

    even = False
    for h in range(H):
        tmp = []
        for w in range(W):
            tmp.append(q.popleft())
        if even:
            print(*tmp[::-1])
        else:
            print(*tmp)
        even = not even


if __name__ == '__main__':
    solve()

Solution (Python):
H,W=map(int,input().split())
n=int(input())
l=list(map(int,input().split()))
lst=[]
for i in range(n):
    for j in range(l[i]):
        lst.append(i+1)
ans=[[None]*W for _ in range(H)]
nuri=[-1,0]
switch=0
for num in lst:
    if switch==0:
        if nuri[0]+1>H-1:
            nuri[1]+=1
            ans[nuri[0]][nuri[1]]=num
            switch=1
        else:
            nuri[0]+=1
            ans[nuri[0]][nuri[1]]=num
    else:
        if nuri[0]-1<0:
            nuri[1]+=1
            ans[nuri[0]][nuri[1]]=num
            switch=0
        else:
            nuri[0]-=1
            ans[nuri[0]][nuri[1]]=num
for i in ans:
    print(" ".join(map(str,i)))

Solution (Python):


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)

Solution (Python):
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]))
if __name__ == '__main__':
    main()

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

cnt = 0
c = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    if(i%2 == 0):
        for j in range(W):
            if(a[cnt] > 1):
                c[i][j] = cnt+1
                a[cnt] -= 1
            elif(a[cnt] == 1):
                c[i][j] = cnt+1
                a[cnt] -= 1
                cnt += 1
    else:
        for j in range(W-1, -1, -1):
            if(a[cnt] > 1):
                c[i][j] = cnt+1
                a[cnt] -= 1
            elif(a[cnt] == 1):
                c[i][j] = cnt+1
                a[cnt] -= 1
                cnt += 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()))

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

Solution (Python):
from collections import deque


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

n = int(input())

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


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


colors = deque()
for i in range(n):
    for j in range(a[i]):
        colors.append(i + 1)




for i in range(h):
    for j in range(w):
        if i % 2 == 0:
            ans[i][j] = colors.popleft()
        else:
            ans[i][w - 1 - j] = colors.popleft()

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

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, w = MAP()
n = INT()
a = LIST()
b = [[0]*w for i in range(h)]
c = deque()

for i in range(n):
    for j in range(a[i]):
        c.append(i+1)

for i in range(h):
    for j in range(w):
        if i % 2 == 0:
            b[i][j] = c.popleft()
        else:
            b[i][w-1-j] = c.popleft()

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

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

import numpy as np
ans = np.zeros((h, w))

r = 0
c = 0
is_down = True
for i, a in enumerate(A):
    x = i + 1
    for _ in range(a):
        ans[r, c] = x
        if is_down:
            if r < h-1:
                r += 1
            else:
                c += 1
                is_down = False
        else:
            if r > 0:
                r -= 1
            else:
                c += 1
                is_down = True

for x in ans:
    print(' '.join(x.astype(int).astype(str)))

Solution (Python):
import numpy as np

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

f = np.zeros(h*w, dtype=int)

j = 0
for i in range(n):
    m = a[i]
    k = i+1
    f[j:j+m] = k
    j += m
f = f.reshape(h, w).tolist()
for i in range(1, h, 2):
    f[i].reverse()
for i in range(len(f)):
    b = [str(i) for i in f[i]]
    print(' '.join(b))

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


inf = 10 ** 18
mod = 10 ** 9 + 7

h,w = lr()
n = ir()
a = lr()
ans = [[-1 for j in range(w)] for i in range(h)]
now = 1
nowa = 0
i = 0
j = 0
for i in range(h):
    for j in range(w):
        if i%2==0:
            ans[i][j] = now
        else:
            ans[i][w-1-j] = now
        a[nowa]-=1
        if a[nowa] == 0:
            now+=1
            nowa+=1
for i in range(h):
    print(*ans[i], sep = ' ')

Solution (Python):
import sys
input = sys.stdin.buffer.readline




def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
	h,w=MI()
	n=II()
	A=LI()

	G=[]

	for i,v in enumerate(A):
		G+=[i+1]*v

	GG=[]

	for i in range(h):
		if i%2==0:
			GG.append(G[i*w:i*w+w])
		else:
			GG.append(G[i*w:i*w+w][::-1])

	for a in GG:
		print(*a)














if __name__ == "__main__":
	main()

Solution (Python):
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [[0]*W for _ in range(H)]

now = a.pop()
now_i = N
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            if now == 0:
                now = a.pop()
                now_i -= 1
            ans[i][j] = str(now_i)
            now -= 1
    else:
        for j in range(W-1, -1, -1):
            if now == 0:
                now = a.pop()
                now_i -= 1
            ans[i][j] = str(now_i)
            now -= 1
for i in range(H):
    print(" ".join(ans[i]))

Solution (Python):
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
ans=[[]for i in range(h)]
t=0
tmp=0
for i in range(n):
    for j in range(a[i]):
        if tmp!=w:
            ans[t].append(i+1)
            tmp+=1
            if tmp==w:
                tmp=0
                t+=1
flg=True
for i in range(h):
    if flg:
        print(*ans[i])
        flg=False
    elif flg==False:
        print(*ans[i][::-1])
        flg=True

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    H, W = in_nn()
    _ = in_n()
    a = in_nl()
    a = [(i + 1, t) for i, t in enumerate(a)]

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

    for y in range(H):
        for x in range(W):
            if y % 2 == 1:
                x = W - x - 1
            c, num = a[-1]
            ans[y][x] = c
            if num - 1 == 0:
                a.pop(-1)
            else:
                a[-1] = (c, num - 1)

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


if __name__ == '__main__':
    main()

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

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

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

c = [0]*W
i, j = 0, 0
for n, a in enumerate(A, 1):
  for _ in range(a):
    c[j] = n
    if (i % 2 == 0) and (j != W-1):
      j += 1
    elif (i % 2 == 1) and (j != 0):
      j -= 1
    else:
      i += 1
    if c[0] != 0 and c[W-1] != 0:
      print(*c)
      c = [0]*W

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

Solution (Python):
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 map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



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

Solution (Python):
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 map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



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==0:
			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]))