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()))
A = []
for i in range(n):
    for j in range(a[i]):
        A.append(i+1)

C = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        if i%2 == 0:
            C[i][j] = A[i*w+j]
        else:
            C[i][-j-1] = A[i*w+j]
for i in range(h):
    for j in range(w):
        print(C[i][j],end="")
        print(" ",end="")
    print("")

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

for y in range(H):
    print(*mapp[y])

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():


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

        


    route = []
    for h in range(H):
        if h % 2 == 0:
            route.extend([(h, w) for w in range(W)])
        else:
            route.extend([(h, w) for w in reversed(range(W))])
    
    ans=[[0]*W for _ in range(H)]
    val=1
    i=0
    cnt=0
    for i in range(N):
        for j in range(A[i]):
            ans[route[cnt][0]][route[cnt][1]]=i+1
            cnt+=1
    for i in ans:
        print(*i)



resolve()

Solution (Python):


def LI():
    return list(map(int, input().split()))


H, W = LI()
N = int(input())
A = LI()


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


if __name__ == "__main__":
    main()

Solution (Python):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
field = [[0 for j in range(w)] for i in range(h)]

d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
y, x = 0, 0
if h == 1 and w == 1:
    print(1)
else:
    for i in range(n):
        cnt = a[i]
        while cnt > 0:
            for j in range(len(d)):
                if 0 <= y + d[j][0] and y + d[j][0] < h and 0 <= x + d[j][1] and x + d[j][1] < w:
                    if field[y+d[j][0]][x+d[j][1]] == 0: 
                        dy, dx = d[j][0], d[j][1]
                        break
            field[y][x] = i+1
            y += dy
            x += dx
            cnt -= 1
    for i in range(h):
        for j in range(w):
            print(field[i][j], end=' ')
        print()

Solution (Python):
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
B = [[0]*w for _ in range(h)]
Bi = 0
Bj = 0
for i in range(n):
    cnt = a[i]
    while cnt>0:
        B[Bi][Bj] = str(i+1)
        cnt-=1
        if Bi%2==0:
            if Bj<w-1:
                Bj+=1
            else:
                if Bi<h-1:
                    Bi+=1
                else:
                    break
        else:
            if Bj>0:
                Bj-=1
            else:
                if Bi<h-1:
                    Bi+=1
                else:
                    break
[print(' '.join(B[i]),end='\n') for i in range(h)]

Solution (Python):
H, W = map(int, input().split())
N = int(input())
A = [int(i) for i in input().split()]

align = [(i+1) for i, a in enumerate(A) for _ in range(a)]

count = 0
ans = []
for i in range(H):
    tmp = align[W*i:W*(i+1)]
    if i % 2 != 0:
        tmp = tmp[::-1]
    print(*tmp)

Solution (Python):
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
dic_color = {}
for i, num in enumerate(A):
    color = i + 1
    dic_color[color] = num

if h <= w:
    yokonaga = True
else:
    yokonaga = False
    h, w = w, h

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

longer_side = max(h, w)

pointer_h = 0
pointer_w = 0

for color in dic_color.keys():
    num = dic_color[color]
    for i in range(num):
        board[pointer_h][pointer_w] = color
        
        if pointer_h % 2 == 0 and pointer_w < w - 1:
            pointer_w += 1
            
        elif pointer_h % 2 == 0 and pointer_w == w - 1:
            pointer_h += 1
            
        elif pointer_h % 2 == 1 and pointer_w > 0:
            pointer_w -= 1
            
        elif pointer_h % 2 == 1 and pointer_w == 0:
            pointer_h += 1
            

if yokonaga:
    for i in range(h):
        print(*board[i], sep=" ")
else:
    board = [[board[i][j] for i in range(h)] for j in range(w)]
    for i in range(w):
        print(*board[i], sep=" ")

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

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

color = 1
filled = 0
for h in range(H):
    if h%2==0: sec = range(W)
    else: sec = range(W-1, -1, -1)
    for w in sec:
        area[h][w] = color
        filled+=1
        if filled == a[color-1]:
            color+=1
            filled = 0
    print(*area[h], sep=' ')

Solution (Python):
n,w = map(int,input().split(" "))
c = int(input())
ar = [[0 for i in range(w)] for j in range(n)]
br = list(map(int,input().split(" ")))
z = 1
for i in range(n):
    if i % 2 ==0:
        for j in range(w):
            ar[i][j] = z
            br[z-1] -= 1
            if br[z-1] == 0:
                z += 1
    else:
        for j in range(w-1,-1,-1):
            ar[i][j] = z 
            br[z-1] -= 1
            if br[z-1] == 0:
                z += 1
for r in ar:
    for i in range(w-1):
        print(r[i],end=" ")
    print(r[w-1])

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod=10**9+7

h,w=MI()
n=I()
colors=LI()
col=[]
for i in range(n):
    for j in range(colors[i]):
        col.append(i+1)

lis=[[0 for i in range(w)] for j in range(h)]
count=0
for i in range(h):
    for j in range(w):
        if i%2==0:
            k=j
        else:
            k=w-j-1
        lis[i][k]=col[count]
        count+=1

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

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

Solution (Python):
def main():
    from itertools import cycle

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

    g = [[-1] * (W + 2) for _ in range(H + 2)]
    for r in range(H + 1):
        g[r][0] = g[r][W + 1] = 0
    for c in range(W + 1):
        g[0][c] = g[H + 1][c] = 0

    def next_pos():
        dir_ = cycle([(1, 0), (0, 1), (-1, 0), (0, -1)])
        r, c = 1, 1
        cnt = 0

        dr, dc = next(dir_)
        while cnt < H * W:
            g[r][c] = cnt
            cnt += 1
            yield r - 1, c - 1
            if ~g[r + dr][c + dc]:
                dr, dc = next(dir_)
            r += dr
            c += dc

    gen_np = next_pos()

    ans = [[-1] * W for _ in range(H)]
    for i, x in enumerate(a, start=1):
        for _ in range(x):
            r, c = next(gen_np)
            ans[r][c] = i

    for row in ans:
        print(*row)


if __name__ == '__main__':
    main()

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

ans = [[0 for j in range(w)] for i in range(h)]
nextColor = 0
H = 0
W = 0

while nextColor < n:
    
    for j in range(a[nextColor]):
        ans[H][W] = nextColor+1
        W += 1

        
        if W >= w:
            H += 1
            W = 0
    
    
    nextColor += 1

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

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


ans = [[0 for j in range(w)] for i in range(h)]
nextColor = 0
H = 0
W = 0

while nextColor < n:
    
    for j in range(a[nextColor]):
        ans[H][W] = nextColor+1
        
        
        
        
        W += 1

        
        if W >= w:
            H += 1
            W = 0
    
    
    
    nextColor += 1

for i in range(h):
    
    if i%2 != 0:
        ans[i] = ans[i][::-1]
    print(*ans[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)]
h = -1
w = -1
flag = False
for i in range(N):
    for j in range(a[i]):
        w+=1
        w%=W
        if w==0:
            w=0
            h+=1
            if flag:
                flag = False
            else:
                flag = True
        if flag:
            ans[h][w] = i+1
        else:
            ans[h][W-1-w] = i+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 = [[0] * W for _ in range(H)]
S = 0
for i, a in enumerate(A, start=1):
    for _ in range(a):
        h, w = divmod(S, W)
        ans[h][w] = i
        S += 1

for i, a in enumerate(ans):
    print(*a[::(-1)**i])

Solution (Python):
h,w=map(int,input().split())
n=int(input())
a=list(map(int , input().split()))
ans=[[0]*w for _ in range(h)]
f=1
k=0
for i in range(h):
    for j in range(w):
        if f==1:
            if a[k]<=0:
                k+=1
            ans[i][j]=k+1
            a[k]-=1
        else:
            if a[k]<=0:
                k+=1
            ans[i][w-1-j]=k+1
            a[k]-=1
        if j==w-1:
            f=f*(-1)
for i in range(h):
  print(*ans[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 heapq import heapify, heappop, heappush
from fractions import gcd
def input(): return sys.stdin.readline().strip()
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 = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
N = INT()
A = LIST()
C = [[0] * W for i in range(H)]
num = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if A[num] > 0:
                A[num] -= 1
            else:
                num += 1
                A[num] -= 1
            C[h][w] = num + 1
    else:
        for w in range(W-1, -1, -1):
            if A[num] > 0:
                
                A[num] -= 1
            else:
                num += 1
                A[num] -= 1
            C[h][w] = num + 1

for c in C:
    print(*c, end="\n")

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split())) + [-1]

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

flag = True 
h = 0
w = 0
k = 1
next_ = A[0]

while next_ > 0:
    G[h][w] = k
    next_ -= 1
    if flag:
        if w == W - 1:
            flag = False
            h += 1
        else:
            w += 1
    else:
        if w == 0:
            flag = True
            h += 1
        else:
            w -= 1


    if next_ == 0:
        next_ = A[k]
        k += 1

for g in G:
    print (*g)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    h,w=map(int,readline().split())
    n=int(readline())
    a=list(map(int,readline().split()))

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

    x=0
    y=0
    color=1
    cnt=0
    total=0
    flag=True
    while total<h*w:
        grid[y][x]=color
        cnt+=1
        total+=1
        if flag:
            if x+1<w:
                x+=1
            else:
                y+=1
                flag=False
        else:
            if x-1>=0:
                x-=1
            else:
                y+=1
                flag=True
        if cnt==a[color-1]:
            color+=1
            cnt=0

    for i in range(h):
        print(*grid[i])
        
if __name__=="__main__":
    main()

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()))
idx = 0
for i in range(h):
    ans = []
    for j in range(w):
        if a[idx] == 0:
            idx += 1
        a[idx] -= 1
        ans.append(idx + 1)
    if i % 2 == 1:
        ans = ans[::-1]
    print(*ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w = inpl()
n = inp()
a = inpl()
ind = 0
now = a[0]
res = [[None]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        res[i][j] = ind+1
        now -= 1
        if now == 0 and ind < n-1:
            ind += 1
            now = a[ind]
for i in range(h):
    if i%2:
        tmp = [str(x) for x in res[i][::-1]]
    else:
        tmp = [str(x) for x in res[i]]  
    print(' '.join(tmp))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    n = int(input())
    A = list(map(int, input().split()))

    grid = [[0 for _ in range(W)] for _ in range(H)]
    h, w = 0, 0
    for i in range(n):
        cnt = A[i]
        while cnt:
            grid[h][w] = i + 1
            cnt -= 1
            if w + 1 < W:
                w += 1
            else:
                h += 1
                w = 0

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


if __name__ == '__main__':
    resolve()

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h,w = iim()
n = ii()
A = iil()
ans = []
l = []
for i,item in enumerate(A):
    l += [i+1]*A[i]

for i in range(h):
    p = l[i*w:(i+1)*w]
    if i%2 == 1:
        ans.append(p[::-1])
    else:
        ans.append(p)

for i in ans:
    print(*i)

Solution (Python):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Solution (Python):
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
n=int(input())
a=lmp()
l=[]
for i in range(n):
    for k in range(a[i]):
        l.append(i+1)


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

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

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

if __name__ == '__main__':
    main()

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

c = [[0] * w for i in range(h)]
cnt = 0
flag = 0
for i in range(n):

    for j in range(a[i]):
        if cnt < w:
            c[flag][cnt] = i + 1
            cnt += 1
        else:
            flag += 1
            c[flag][0] = i + 1
            cnt = 1
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()))

ans=[[0 for _ in range(W)] for _ in range(H)]
if H%2==1:
    END=[H-1,W-1]
else:
    END=[H-1,0]
h=0
w=0
col=1
cnt=0

while h<H:
    ans[h][w]=col
    cnt+=1
    if cnt>=a[col-1]:
        cnt=0
        col+=1
    if (h%2==1 and w==0) or (h%2==0 and w==W-1):
        h+=1
    else:
        w+=(-1)**h

if W>1:
    for A in ans:
        for B in A:
            print(B,end=" ")
        print()
else:
    for A in ans:
        print(A[0])

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

ans = []
tmp = []
count = 0
for i in range(n):
    num = i+1
    itr = 0
    while itr < a[i]:
        tmp.append(num)
        if len(tmp) == w:
            count += 1
            if count %2 != 0:
                tmp.reverse()
            ans.append(tmp)
            tmp=[]
            
        itr+=1
for i in ans:
    for j in range(len(i)):
        print(i[j],end=" ")
    print()

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

def pprint(c):
    for ci in c:
        print(*ci)

def main():
    h, w = MII()
    n = II()
    aa = MII()
    aa = deque([i+1 for i, a in enumerate(aa) for _ in range(a)])
    for i in range(h):
        tmp = []
        for j in range(w):
            tmp.append(aa.popleft())
        if i%2==1:
            tmp = tmp[::-1]
        print(*tmp)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

def pprint(c):
    for ci in c:
        print(*ci)

def main():
    h, w = MII()
    n = II()
    aa = MII()
    aa = deque([i+1 for i, a in enumerate(aa) for _ in range(a)])
    if w == 1:
        print(*aa, sep='\n')
        return None
    c = DD2(h,w)
    for i in range(h):
        if not aa: break
        for j in range(i,w-i): 
            c[i][j] = aa.popleft()
        if not aa: break
        for k in range(i+1, i+1+(h-2*(i+1))): 
            c[k][w-1-i] = aa.popleft()
        if not aa: break
        for j in reversed(range(i,w-i)): 
            c[h-1-i][j] = aa.popleft()
        if not aa: break
        for k in reversed(range(i+1, i+1+(h-2*(i+1)))): 
            c[k][i] = aa.popleft()
    for ci in c:
        print(*ci)



if __name__ == '__main__':
    main()

Solution (Python):
import math
import fractions



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rln(s):
    return range(len(s))










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

ans = [[-1 for i in range(w)]for j in range(h)]
for i in range(h*w):
    x = i//h
    y = i%h if(x%2==0) else h-1-i%h
    ans[y][x] = num[i]

for i in range(h):
    print(' '.join(map(str,ans[i])))

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


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

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

Solution (Python):
import numpy as np
inputs = open(0).readlines()
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

def z_iterate(x, y, w):
    if y % 2:
        if x == 0:
            y += 1
        else:
            x -= 1
    else:
        if x == w-1:
            y += 1
        else:
            x += 1
    return x, y

h, w = map(int, inputs[0].split())
*A, = map(int, inputs[2].split())
grid = Grid(np.zeros((h, w), dtype=np.int))

x = y = 0
for i, a in enumerate(A, 1):
    for _ in range(a):
        grid[y, x] = i
        x, y = z_iterate(x, y, w)
print(grid)

Solution (Python):
import numpy as np
inputs = open(0).readlines()
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

h, w = map(int, inputs[0].split())
*A, = map(int, inputs[2].split())
grid = Grid(np.zeros((h, w), dtype=np.int))

x = y = 0
for i, a in enumerate(A, 1):
    for j in range(a):
        grid[y, x] = i
        if y % 2 == 0:
            if x == w-1:
                y += 1
            else:
                x += 1
        else:
            if x == 0:
                y += 1
            else:
                x -= 1
print(grid)

Solution (Python):
h,w = map(int,input().split())
n = int(input())
li = list(map(int,input().split()))
all_ans = []
for i,l in enumerate(li):
    bangou = i+1
    all_ans += [bangou]*l


last = -1
for k in range(h):
    target = all_ans[last+1:last+1+w]
    if k%2 == 1:
        target.reverse()
    print(*target)
    last = last + w

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
n = ni()
a = na()

ans = [[0] * w for _ in range(h)]
cur = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            ans[i][j] = cur + 1
            a[cur] -= 1
            if a[cur] == 0:
                cur += 1
    else:
        for j in range(w - 1, -1, -1):
            ans[i][j] = cur + 1
            a[cur] -= 1
            if a[cur] == 0:
                cur += 1

for i in range(h):
    print(*ans[i], sep=" ")

Solution (Python):
from collections import Counter
H,W = map(int,input().split())
N = int(input())
a= list(map(int,input().split()))
c= [[0 for _ in range(W)] for _ in range(H)]
b= []
for i,num in enumerate(a):
  b += num*[i+1]


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