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 itertools import chain, repeat
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(H: int, W: int, N: int, a: "List[int]"):
    it = chain.from_iterable(repeat(i + 1, ai) for i, ai in enumerate(a))
    for i in range(H):
        l = [next(it) for j in range(W)]
        if i % 2 == 1:
            l.reverse()
        print(*l)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(H, W, N, a)


if __name__ == '__main__':
    main()

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

muki = 1
m = [[-1] * W for _ in range(H)]
yoko = 0
tate = 0
for i, a in enumerate(A):
    for j in range(a):
        m[tate][yoko] = i + 1
        if yoko + muki >= W or yoko + muki < 0:
            muki *= (-1)
            tate += 1
        else:
            yoko += muki
        
for i in range(H):
    print(' '.join(list(map(str, m[i]))))

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

color = [[0 for _ in range(w)] for _ in range(h)]
c = 0
for i in range(h*w):
    x = i // w
    y = i % w
    if x % 2:
        y = w - 1 - y
    if a[c] == 0:
        c += 1
    color[x][y] = c+1
    a[c] -= 1
for i in range(h):
    print(*color[i])

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

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

index = 0
for i in range(h):
  for j in range(w):
    if i % 2 == 0:
      hw[i][j] = str(index+1)
        
    else:
      hw[i][w-j-1] = str(index+1)
      
    a[index] -= 1
    if a[index] == 0:
      index += 1
        
for i in range(h):
  print(' '.join(hw[i]))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

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 = [[INF] * W for i in range(H)]

even = 0
num = 0
for i in range(H):
    if even == 0:
        for j in range(W):
            if A[num] > 0:
                C[i][j] = num + 1
                A[num] -= 1
            else:
                num += 1
                C[i][j] = num + 1
                A[num] -= 1

            
        even ^= 1
    else:
        for j in range(W-1, -1, -1):
            if A[num] > 0:
                C[i][j] = num + 1
                A[num] -= 1
            else:
                num += 1
                C[i][j] = num + 1
                A[num] -= 1

        even ^= 1

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

Solution (Python):
H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
b =[0]*(H*W)
k = 0
for i in range(N):
    for j in range(a[i]):
        b[k] = i + 1
        k += 1
x, y = 0, 0
ans =[[0]*W for i in range(H)]
for i in range(H*W):
    ans[y][x] = b[i]
    if (x == 0 and y%2 == 1) or (x == W - 1 and y%2 == 0):
        y += 1
    elif y%2 == 0:
        x += 1
    else:
        x -= 1
for _ in range(H):
    print(*ans[_])

Solution (Python):
h, w = map(int, input().split())
n = int(input())
a = [int(i) for i in input().split()]
c = [[0] * w for _ in range(h)]
i, j = 0, 0
d = 1
k = 1
for ai in a:
    for _ in range(ai):
        c[j][i] = k
        if i == 0 and d == -1:
            j += 1
            d = 1
        elif i == w - 1 and d == 1:
            j += 1
            d = -1
        else:
            i += d
    k += 1
[print(*e) for e in c]

Solution (Python):
import numpy as np

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

ans = []
for i, e in enumerate(a, 1):
    ans += [i] * e

ans = np.array(ans, dtype=np.int16)
ans = ans.reshape((h, w))

ans[1::2, :] = ans[1::2, ::-1]

for ar in ans:
    print(*ar)

Solution (Python):
import numpy as np

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

ans = []
for i, e in enumerate(a, 1):
    ans += [i] * e

ans = np.array(ans, dtype=np.int64)
ans = ans.reshape((h, w))

for i in range(1, h, 2):
    ans[i] = ans[i][::-1]

for ar in ans:
    print(*ar)

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

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

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

c = []
for i, j in enumerate(a):
    c += [i + 1] * j
c = np.array(c).reshape(H, W)
c[1::2, :] = c[1::2, ::-1]

for r in range(H):
    row = c[r, :]
    print(*row, sep=' ')

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

c = []
for i, j in enumerate(a):
    c += [i + 1] * j
c = np.array(c).reshape(H, W)

for i in range(1, H, 2):
    c[i, :] = c[i, ::-1]

for r in range(H):
    row = c[r, :]
    print(*row, sep=' ')

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

x=y=1
for i in range(n):
  cnt=a[i]
  
  while cnt>0:
    
    m[x][y]=i+1
    cnt-=1
    if y+1<=w and m[x][y+1]==0:
        y+=1
    elif y-1>0 and  m[x][y-1]==0:
        y-=1
    else:
      x+=1
  
for i in range(h):
  for j in range(w):
    print(m[i+1][j+1],end=' ') if j!=w-1 else print(m[i+1][j+1])

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

    H,W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))
    res = []
    for i in range(N):
        for _ in range(a[i]):
            res.append(i+1)
    for i in range(H):
        if  i%2==0:
            b = res[i*W:(i+1)*W]
            print(' '.join(map(str, b)))
        else:
            b = res[i*W:(i+1)*W]
            b = b[::-1]
            print(' '.join(map(str, b)))
if __name__ == '__main__':
    main()

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

c=[[0 for i in range(W)]for j in range(H)]
for k in range(N):
    count=0
    flag=True
    for i in range(H):
        for j in range(W):
            if i%2==0:
                if c[i][j]==0:
                    if count!=a[k]:
                        c[i][j]=k+1
                        count+=1
                    else:
                        flag=False
                        break
            else:
                if c[i][W-1-j]==0:
                    if count!=a[k]:
                        c[i][W-1-j]=k+1
                        count+=1
                    else:
                        flag=False
                        break
        if not flag:
            break
for i in range(H):
    print(*c[i])

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

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

def main():
    mod=10**9+7
    H,W=MI()
    N=I()
    a=LI()
    ans=[[0]*W for _ in range(H)]
    num=0
    
    for k in range(H*W):
        i=k//W
        j=k%W
        if i%2==1:
            j=W-1-j
        if a[num]==0:
            num+=1
        ans[i][j]=num+1
        a[num]-=1
        
    for i in range(H):
        print(' '.join(map(str, ans[i])))
            
        
        

main()

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

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

grid=[]
for g in range(H):
    grid.append(color[g*W:(g+1)*W])

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

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

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

direction = 'e'

h_now = 0
w_now = 0


def distribute():
    for i in range(n + 1):
        if a[i] > 0:
            a[i] -= 1
            return i + 1


finish = 0
ans[0][0] = 1
a[0] -= 1
while finish <= 4:
    if direction == 'e':
        if w_now + 1 < w and ans[h_now][w_now + 1] == 0:
            w_now += 1
            ans[h_now][w_now] = distribute()
            finish = 0
        else:
            direction = 's'
            finish += 1

    if direction == 's':
        if h_now + 1 < h and ans[h_now + 1][w_now] == 0:
            h_now += 1
            ans[h_now][w_now] = distribute()
            finish = 0
        else:
            direction = 'w'
            finish += 1

    if direction == 'w':
        if w_now - 1 >= 0 and ans[h_now][w_now - 1] == 0:
            w_now -= 1
            ans[h_now][w_now] = distribute()
            finish = 0
        else:
            direction = 'n'
            finish += 1

    if direction == 'n':
        if h_now - 1 >= 0 and ans[h_now - 1][w_now] == 0:
            h_now -= 1
            ans[h_now][w_now] = distribute()
            finish = 0
        else:
            direction = 'e'
            finish += 1
    

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

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

result = []
for i in range(n):
    result.extend([i+1 for _ in range(a[i])])
for i in range(h):
    out_put = result[w*i:w*(i+1)]
    if i%2==0:
        print(" ".join(list(map(str, out_put))))
    else:
        print(" ".join(list(map(str, out_put[::-1]))))

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

k = 0
l = 0
ary = []
for i in range(n):
	loop = a[i]
	j = 0
	b = [i+1 for j in range(a[i])]
	ary.extend(b)
c = 0
for i in range(0,h*w,w):
	if c%2 == 1:
		d = ary[i:i+w]
		del ary[i:i+w]
		d.reverse()
		ary[i:i] = d
	e = ary[i:i+w]
	print (*e)
	c += 1

Solution (Python):


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


H, W = read_ints()
N = read_a_int()
A = read_ints()

out = []
for i, a in enumerate(A, start=1):
    out.extend([i] * a)



import numpy as np
out = np.array(out)
out = out.reshape((H, W))
for i, o in enumerate(out):
    if i & 1:
        print(*o)
    else:
        print(*o[::-1])

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

for i in range(n):
    lis.append([a[i],i+1])

ans = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if lis[0][0] == 0:
            del lis[0]
        ans[i][j] = lis[0][1]
        lis[0][0] -= 1
for i in range(h):
    if i % 2 != 0:
        ans[i].reverse()
for i in range(h):
    print(' '.join(map(str,ans[i])))

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

ans=[]
for i,j in enumerate(a):
    ans+=[(i+1)]*j
    
b=np.reshape(ans,(h,w))

for i,j in enumerate(b):
    if i%2==0:
        print(*j)
    else:
        print(*j[::-1])

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

ans = [[0] * W for h in range(H)]
h = 0
w = 0
t = 0

for index, a in enumerate(A):
  for i in range(a):
    ans[h][w] = index+1

    if t == 0 and w+1 < W:
      w += 1
      continue

    if t == 0 and w+1 >= W:
      h += 1
      t = 1
      continue

    if t == 1 and w-1 >= 0:
      w -= 1
      continue

    if t == 1 and w-1 < 0:
      h += 1
      t = 0
      continue

for i in ans:
  for k in i:
    print(k, end=" ")

  print("")

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

H, W = [int(x) for x in input().split()]
N = int(input())
a = [int(x) for x in input().split()]
A = []
for i in range(N):
    A += [str(i + 1)] * a[i]

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

for i in range(H):
    for j in range(W):
        ans[i][j] = A.pop(0)

for i in range(H):
    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_raw = []
count = 0
for i in range(len(A)):
    num = i+1
    for _ in range(A[i]):
        Ans_raw.append(str(num))

for i in range(h):
    Now = Ans_raw[i*w:(i+1)*w]
    if i % 2 == 1:
        Now = Now[::-1]
    print(' '.join(Now))

Solution (Python):

h,w = map(int,input().split())
n = int(input())
c = list(map(int,input().split()))
ans1 = []
for i in range(n):
  ans1 += [i+1] * c[i]
ans2 = []
for x in range(h):
  ans2.append(ans1[w*x:w*(x+1)])
for x in range(h):
  if x % 2 == 1:
    ans2[x].reverse()


for x in range(h):
  print(' '.join(list(map(str,ans2[x]))))

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

    ans=[[0]*w for i in range(h)]
    
    i,j,right=0,0,True
    for color in range(1,n+1):
        
        cnt=a[color-1]
        while cnt>0:
            if right:
                if i+cnt<w:
                    for k in range(i,i+cnt):
                        ans[j][k]=color
                    i+=cnt
                    cnt=0
                else:
                    for k in range(i,w):
                        ans[j][k]=color
                    cnt-=w-i
                    i=w-1
                    j+=1
                    right=False
            
            else:
                if i+1-cnt>0:
                    for k in range(i,i-cnt,-1):
                        ans[j][k]=color
                    i-=cnt
                    cnt=0
                else:
                    for k in range(i,-1,-1):
                        ans[j][k]=color
                    cnt-=i+1
                    i=0
                    j+=1
                    right=True
    for i in range(h):
        print(*ans[i])
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)]
k = 0
for i in range(H):
    for j in range(W):
        if i % 2 == 0:
            ans[i][j] = k+1
        else:
            ans[i][W-1-j] = k+1
        a[k] -= 1
        if a[k] == 0:
            k += 1
for i in range(H):
    print(' '.join(map(str, ans[i])))

Solution (Python):
import numpy as np
H, W, N, *A = map(int, open(0).read().split())
ls = []
for i in range(N):
  ls += [i+1]*A[i]
ls = np.array(ls)
ls = ls.reshape((H,W))
ls[1::2] = ls[1::2,::-1]
for a in ls:
  print(*a)

Solution (Python):
import numpy as np
H, W, N, *A = map(int, open(0).read().split())
ls = []
for i in range(N):
  ls += [str(i+1)]*A[i]
ls = np.array(ls)
ls = ls.reshape((H,W))
ls[1::2] = ls[1::2,::-1]
for a in ls:
  print(' '.join(a))

Solution (Python):
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
l=[]
for i,j in enumerate(a):
  for _ in range(j):
    l.append(i+1)
for i in range(h):
  print(*l[i*w:(i+1)*w][::(-1)**i])

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

h,w = m()
n = onem()

a = l()

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


co = 0

for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[co] == 0:
                co += 1
            po[i][j] = co + 1
            a[co] -= 1
    else:
        for j in range(w-1,-1,-1):
            if a[co] == 0:
                co += 1
            po[i][j] = co + 1
            a[co] -= 1

for i in range(h):
    print(jo(po[i]))

Solution (Python):
def main():
    height, width = map(int, input().split())
    color = int(input())
    limits = list(map(int, input().split()))
    answer = []
    for i in range(color):
        answer = answer + [i + 1] * limits[i]
    for i in range(height):
        if i % 2:
            print(" ".join(map(str, list(reversed(answer[i * width:(i + 1) * width:])))))
        else:
            print(" ".join(map(str, answer[i * width:(i + 1) * width])))


if __name__ == '__main__':
    main()

Solution (Python):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
color = []
for i, v in enumerate(a):
    for _ in range(v):
        color.append(i+1)
ans = [[0] * w for _ in range(h)]
q = 1
x, y = 0, -1
for i in range(h*w):
    if q == 1:
        if y == w-1:
            x += 1
            q = 0
        else:
            y += 1

    elif q == 0:
        if y == 0:
            x += 1
            q = 1
        else:
            y -= 1
    ans[x][y] = color[i]
for w in ans:
    print(*w)

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

q = []
for i in range(N):
    q.extend([i+1] * A[i])

ans = [['' for _ in range(W)] for _ in range(H)]
for h in range(H):
    if h % 2 == 0:
        X = range(W)
    else:
        X = reversed(range(W))
    for w in X:
        ans[h][w] = str(q.pop())

for line in ans:
    print(' '.join(line))

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

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

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

ans = []
for i in range(n):
  ans += [i+1]*l[i]

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

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
import queue
import copy






HW = str(input()).split()
H = int(HW[0])
W = int(HW[1])
N = int(input())

Gr = [[0]*W for i in range(H)]

A = [int(x) for x in input().split()]

countH = 0
countW = 0

for i in range(N):
  for j in range(A[i]):
    Gr[countH][countW] = i+1
    countW += 1
    if(countW==W):
      countH += 1
      countW = 0



for i in range(H):
  if(i%2 == 0):
    L=[str(a) for a in Gr[i]]
    L=' '.join(L)
    print(L)
  else:
    L=[str(a) for a in reversed(Gr[i])]
    L=' '.join(L)
    print(L)

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

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


pointer = [0, 0]
direction = 1

for i in range(1, N + 1):
	color_stock = A[i - 1]
	while color_stock:
		ans_lst[pointer[0]][pointer[1]] = i
		color_stock -= 1
		
		
		if pointer[1] == 0 and direction == -1:
			pointer[0] += 1
			direction = 1
		elif pointer[1] == W - 1 and direction == 1:
			pointer[0] += 1
			direction = -1
		elif direction == 1:
			pointer[1] += 1
		elif direction == -1:
			pointer[1] -= 1
		else:
			print("what!?")
			
for i in range(H):
	print(*ans_lst[i])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

H, W = [int(_) for _ in input().split()]
N = int(input())
A = [int(_) for _ in input().split()]
ai = 0
for i in range(H):
    ans = []
    for j in range(W):
        if A[ai] <= 0: ai += 1
        ans.append(ai + 1)
        A[ai]-=1
    if i %2==1:
        print(*reversed(ans))
    else:
        print(*ans)

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

idx = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            c[i][j] = s[idx]
            idx += 1
    else:
        for j in reversed(range(w)):
            c[i][j] = s[idx]
            idx += 1

for i in range(len(c)):
    print(" ".join(list(map(str, c[i]))))

Solution (Python):
h,w = map(int,input().split())
n = int(input())
l = list(map(int,input().split()))
ans = [[0]*w for i in range(h)]
x,y = 0,0
z = 1
num = 1
for i in range(n):
    count = 0
    while count < l[i]:
        ans[x][y] = i+1
        count += 1
        if z == 1:
            if y == w-1:
                x += 1
                z = 2
                
            else:
                y += 1
        elif z == -1:
            if y == 0:
                x += 1
                z = 2
            else:
                y -= 1
        elif z == 2:
            if w != 1:
                if y == 0:
                    y += 1
                    z = 1
                else:
                    y -= 1
                    z = -1
            else:
                x += 1
        
for i in ans:
    print(*i)

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

    else:
        for j in range(w-1,-1,-1):
            if ret:
                ans[i][j] = color
                ret -= 1
            else:
                ret = lst1[color]
                color += 1
                ans[i][j] = color
                ret -= 1

for i in ans:
    print(" ".join(map(str,i)))

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    N = int(input())
    A = [int(x) for x in input().split()]

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

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

    for a in ans:
        print(*a)


    
    
    

if __name__ == '__main__':
    main()

Solution (Python):
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
G=[[0]*W for i in range(H)]
import numpy
from bisect import bisect_right
w=numpy.cumsum(A)
count=0
for i in range(H):
  if i%2==0:
    a=0
    b=W
    c=1
  else:
    a=W-1
    b=-1
    c=-1
  for j in range(a,b,c):
    G[i][j]=bisect_right(w,count)+1
    count+=1
  print(*G[i])

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

Solution (Python):
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
nn = h*w
pos = 0
cnt = 0
while True:
    tmp = []
    for j in range(w):
        if a[pos] == 0:
            pos += 1
        tmp.append(pos+1)
        a[pos] -= 1
    print(*tmp)
    cnt += w
    if cnt >= nn:
        break
    tmp = []
    for j in range(w):
        if a[pos] == 0:
            pos += 1
        tmp.append(pos+1)
        a[pos] -= 1
    print(*tmp[::-1])
    cnt += w
    if cnt >= nn:
        break

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

result = [[None] * W for _ in range(H)]
d = 1
x, y = 0, 0
for i in range(N):
    t = a[i]
    while t > 0:
        result[y][x] = i + 1
        x += d
        if x == -1 or x == W:
            x -= d
            d = -d
            y += 1
        t -= 1

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

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

alist = []
i = 1
for ai in a:
  alist.extend([str(i)]*ai)
  i += 1

i = 0
for h in range(H):
  start = h * W
  end = start + W
  if h % 2 == 0:
    print(' '.join(alist[start:end]))
  else:
    print(' '.join(alist[end-1:start-1:-1]))

Solution (Python):
h, w = list(map(int, input().split()))
n = int(input())
ans = [[0 for i in range(w)] for j in range(h)]
dec = 1
p = 1
cnt = 0
index = 0
a = list(map(int, input().split()))
for i in range(h):
    while 0 <= index < w:
        if cnt == a[p-1]:
            p += 1
            cnt = 0
        ans[i][index] = p
        cnt += 1
        index += dec
    dec *= (-1)
    index += dec
for i in range(h):
    for j in range(w):
        print("{} ".format(ans[i][j]), end = '')
    print()

Solution (Python):
H, W = map(int, input().split())
N = int(input())
A = [int(x) for x in input().split()]
ans = [0] * H
for i in range(H):
    ans[i] = [0] * W
h_index = 0
A_index = 0
w_index = 0
now_num = 0
while (h_index != H):
    
    ans[h_index][w_index] = A_index + 1
    now_num += 1
    if A[A_index] == now_num:
        now_num = 0
        A_index += 1
    if h_index % 2 == 0:
        if w_index == W-1:
            h_index += 1
        else:
            w_index += 1
    else:
        if w_index == 0:
            h_index += 1
        else:
            w_index -= 1
for j in range(H):
    print(*ans[j], sep=" ")

Solution (Python):
import itertools
import math
H,W =list(map(int,input().split(" ")))
N = int(input())
As =list(map(int,input().split(" ")))
color = 0
count = 0
ans = [ [0] * W  for _ in range(H)  ]
for h in range(H):
    if h %2 == 0:
        start = 0
        end = W
        step = 1
    else:
        start = W - 1
        end = -1
        step = -1
    for w in range(start,end,step):
        if count == As[color] :
            color += 1
            count = 0
        ans[h][w] = color + 1
        count += 1

for temp in ans:
    print(*temp)

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

Solution (Python):
h,w=[int(i)for i in input().split()]
n=int(input())
a=[int(i)for i in input().split()]
arr=[]

count=0
for i in a:
    count+=1
    for j in range(i):
        arr.append(count)
        
for y in range(h):
    for x in range(w):
        if y%2==0:print(arr[y*w+x],end=" ")
        else:print(arr[(y+1)*w-1-x],end=" ")
    print("")

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

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


now=[0,0]
muki=0

def chech(x,y):
    if 0<=x<w and 0<=y<h:
        if lst[y][x]==0:
            return 1
        else:
            return 0
    else:
        return 0

while a:
    lst[now[1]][now[0]]=len(a)
    a[-1]-=1
    if a[-1]==0:
        a.pop()
    
    
    
    if muki==0:
        if chech(now[0]+1,now[1]):
            now[0]+=1
        else:
            if chech(now[0],now[1]+1):
                now[1]+=1
                muki=1
            else:
                break
    elif muki==1:
        if chech(now[0],now[1]+1):
            now[1]+=1
        else:
            if chech(now[0]-1,now[1]):
                now[0]-=1
                muki=2
            else:
                break
    elif muki==2:
        if chech(now[0]-1,now[1]):
            now[0]-=1
        else:
            if chech(now[0],now[1]-1):
                now[1]-=1
                muki=3
            else:
                break
    elif muki==3:
        if chech(now[0],now[1]-1):
            now[1]-=1
        else:
            if chech(now[0]+1,now[1]):
                now[0]+=1
                muki=0
            else:
                break
for i in range(h):
    print(*lst[i])

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

ans = [[0]*W for _ in range(H)]
c = 0
for i in range(N):
  for j in range(a[i]):
    ans[c/W][c%W if c/W%2==0 else -c%W-1] = i
    c += 1

for a in ans:
  for x in a:
    print x+1,
  print