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

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

i = 0

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




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

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

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

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

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

x,y=0,0
c=1
for a in alist:
  while a:
    
    cmat[x][y]=c
    y+=1
    a-=1
    
    if y==W:
      x+=1
      y=0
  c+=1
      

for i in range(H):
  if i%2==1:
    cmat[i].reverse()
  print(*cmat[i])

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

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

x,y=0,0
c=1
for a in alist:
  while a:
    if y<W:
      
      cmat[x][y]=c
      y+=1
      a-=1
    
    if y==W:
      x+=1
      y=0
  
  c+=1
      

for i in range(1,H,2):
  cmat[i].reverse()

      
for i in range(H):
  print(*cmat[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)]
ctr = [0] * N
n = 0
for i in range(H):
    for j in range(W):
        if i % 2 == 1:
            j = W - 1 - j
        ans[i][j] = n + 1
        ctr[n] += 1
        if A[n] == ctr[n]:
            n += 1

for v in ans:
    print(*v)

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

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]

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

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

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

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)]
now = 1
cnt = 0
for i in range(H):
    if i&1:
        for j in reversed(range(W)):
            if cnt == a[now-1]:
                now += 1
                cnt = 0
            ans[i][j] = now
            cnt += 1

    else:
        for j in range(W):
            if cnt == a[now-1]:
                now += 1
                cnt = 0
            ans[i][j] = now
            cnt += 1

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

Solution (Python):

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

solve()

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

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

pre=[]
for i in range(n):
    for j in range(int(a[i])):
        pre.append(str(i+1))
for i in range(h):
    if i%2==1:
        sub=pre[w*(i+1)-1:w*i-1:-1]
        pre[w*i:w*(i+1)]=sub
for i in range(h):
    print(' '.join(pre[w*i:w*(i+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)]
pre = 0
cur = 1
for i in range(H):
    if i % 2 == 0:
        cnt = 0
        while cnt < W:
            if a[cur - 1] == 0:
                cur += 1
            ans[i][cnt] = cur
            a[cur - 1] -= 1
            cnt += 1
        
    else:
        cnt = W - 1
        while cnt >= 0:
            if a[cur - 1] == 0:
                cur += 1
            ans[i][cnt] = cur
            a[cur - 1] -= 1
            cnt -= 1
        
for i in range(H):
    print(*ans[i])

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    H,W=map(int,input().split())
    N=int(input())
    a=list(map(int,input().split()))
    c=[[0]*W for _ in range(H)]
    nv=[[()]*W for _ in range(H)]
    for i in range(H):
        if i%2==0:
            for j in range(W):
                if j<W-1:
                    nv[i][j]=(i,j+1)
                else:
                    nv[i][j]=(i+1,j)
        else:
            for j in range(W-1,-1,-1):
                if j>0:
                    nv[i][j]=(i,j-1)
                else:
                    nv[i][j]=(i+1,j)
    v=(0,0)
    for i,x in enumerate(a,1):
        for _ in range(x):
            c[v[0]][v[1]]=i
            v=nv[v[0]][v[1]]
    for a in c:
        print(*a)

if __name__ == '__main__':
    main()

Solution (Python):
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
s = []
ans = []
for i in range(1,n+1):
    for j in range(a[i-1]):
        s.append(i)
for i in range(h):
    ans.append(s[i*w:(i+1)*w])
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()))
for i in range(N-1):
    A[i+1] = A[i] + A[i+1]
C = [[0 for i in range(W)] for j in range(H)]
cnt = 1
index = 0
for i in range(H):
    for j in range(W):
        if cnt > A[index]:
            index += 1
        C[i][j] = index + 1
        cnt += 1
for i in range(H):
    if i % 2 == 0:
        print(*C[i])
    else:
        print(*C[i][::-1])

Solution (Python):
nim,mike = map(int,input().split())

data = int(input())

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

ans = []
for i,v in enumerate(array):
    ans += [i+1] * v
for i in range(nim):
    print(*ans[mike * i:mike*(i+1)][::(-1)**i])

Solution (Python):
h, w = map(int, input().split())
n = int(input())
ns = map(int, input().split())
s = []
rslt = []
for i, num in enumerate(ns):
    s += [str(i+1)] * num
i = 0
j = 0
while i < h:
    if i % 2 == 0:
        rslt.append(s[i * w:(i + 1) * w])
    else:
        rslt.append(s[i * w:(i + 1) * w][::-1])
    i += 1
for i in range(h):
    print(' '.join(rslt[i]))

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)]
cu = 0
for y in range(H):
    for x in range(W):
        ans[y][x] = cu + 1
        a[cu] -= 1
        if not a[cu]:
            cu += 1

for i in range(H):
    if i % 2 != 0:
        print(' '.join(map(str, sorted(ans[i], reverse=True))))
    else:
        print(' '.join(map(str, ans[i])))

Solution (Python):


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


x, y = 0, 0


status = 0


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

for i in range(n):
    for j in range(a[i]):
        
        ans[y][x] = i+1
        if status == 0:
            x += 1
        else:
            x -= 1
        if x == w:
            status = 1
            x -= 1
            y += 1
        if x == -1:
            status = 0
            x += 1
            y += 1

for i in ans:
    for j in i:
        print(j, end=' ')
    print()

Solution (Python):
from itertools import chain, islice

h, w = map(int, input().split())
n = int(input())
a = map(int, input().split())
c = chain.from_iterable([i] * ai for i, ai in enumerate(a, 1))

for i in range(h):
    l = list(islice(c, 0, w))
    if i % 2 == 1:
        l.reverse()
    print(*l)

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

g = [[0 for _ in range(W)] for _ in range(H)]
h = 0
w = 0
for i in range(1, N+1):
    for _ in range(A[i-1]):
        g[h][w] = i
        if h % 2 == 0:
            w += 1
            if w > W-1:
                h += 1
                w = W-1
        else:
            w -= 1
            if w < 0:
                h += 1
                w = 0

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

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

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

aij = []

for i in range(n):
    for j in range(ai[i]):
        aij.append(i+1)

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

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

Solution (Python):
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
color = [[0] * W for _ in range(H)]
nowx = 0
nowy = 0
for i in range(N):
  for j in range(a[i]):
    color[nowx][nowy] = i+1
    if(nowx % 2 == 0 and nowy < W-1):
      nowy += 1
    elif(nowx % 2 == 1 and nowy > 0):
      nowy -= 1
    else:
      nowx += 1
      
for h in range(H):
  print(*color[h])

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

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

PATH = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            PATH.append((i, j))
    else:
        for j in range(w)[::-1]:
            PATH.append((i, j))

color = 1
count = 0
for i, j in PATH:
    GRID[i][j] = color
    count += 1
    if count == A[color - 1]:
        color += 1
        count = 0

for ROW in GRID:
    print(*ROW)

Solution (Python):

import math
h, w = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

i = 0
l = []
flg = True
while i < N:
    if A[i] > 0:
        if flg:
            l.append(str(i+1))
        else:
            l.insert(0,str(i+1))
        A[i] -= 1
    else:
        i += 1
    if len(l) == w:
        print(' '.join(l))
        if flg:
            flg = False
        else:
            flg = True
        l = []

Solution (Python):
h, w = map(int, input().split())
n = int(input())
list_A = list(map(int, input().split()))
ans = [[0]*w for _ in range(h)]
cnt = -1
x = []
y = []
for i in range(w):
    if i % 2 == 0:
        x += [i for i in range(h)]
    else:
        l = [i for i in range(h)]
        l.reverse()
        x += l

for i in range(w):
    for _ in range(h):
        y.append(i)

for i, num in enumerate(list_A):
    for _ in range(num):
        cnt += 1
        ans[x[cnt]][y[cnt]] = i+1

for l in ans:
    print(*l)

Solution (Python):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[] for i in range(h)]
inc = True
r = 0
for i in range(n):
    while(a[i] > 0):
        if(inc):
            if(r <= h - 1):
                ans[r].append(i + 1)
                r += 1
            else:
                r = h - 1
                ans[r].append(i + 1)
                r -= 1
                inc = False
        else:
            if(r >= 0):
                ans[r].append(i + 1)
                r -= 1
            else:
                r = 0
                ans[r].append(i + 1)
                r += 1
                inc = True
        a[i] -= 1
for x in ans:
    for i in x:
        print(i, end = " ")
    print()

Solution (Python):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[] for i in range(h)]
inc = True
r = 0
for i in range(n):
    while(a[i] > 0):
        if(inc):
            if(r <= h - 1):
                ans[r].append(i + 1)
                r += 1
            else:
                r = h - 1
                ans[r].append(i + 1)
                r -= 1
                inc = False
        else:
            if(r >= 0):
                ans[r].append(i + 1)
                r -= 1
            else:
                r = 0
                ans[r].append(i + 1)
                r += 1
                inc = True
        a[i] -= 1
for x in ans:
    for i in x:
        print(i, end = " ")
    print()

Solution (Python):
H,W = map(int, input().split())
input()
A = list(map(int, input().split()))
s = [[0] * W for _ in range(H)]
index = 0
for i in range(H):
    r = range(W)
    if i % 2 == 1: r = reversed(r)
    for j in r:
        if A[index] == 0:
            index += 1
        s[i][j] = index + 1
        A[index] -= 1

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

Solution (Python):
def main():
    t = list(map(int, input().split()))
    mass = [[0]*t[1] for i in range(t[0])]
    input()
    colors = list(map(int, input().split()))

    w = 0
    h = 0
    direction = 0
    count = 0
    for color in colors:
        count += 1
        for i in range(color):
            mass[h][w] = count
            w = w + 1 if direction == 0 else w - 1
            if w == len(mass[0]) or w <= -1:
                h += 1
                direction = 1 if direction == 0 else 0
                w = 0 if direction == 0 else len(mass[0]) - 1
                continue
    for m in mass:
        print(' '.join([str(v) for v in m]))



if __name__ == '__main__':
    main()

Solution (Python):
h,w= map(int,input().split())
n= int(input())
a= list(map(int,input().split()))
st = []
for i in range(1,n+1):
    for c in range(a[i-1]):st.append(i)
ans = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):ans[i][j]= st[i*w+j]
    if i%2==1: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()))
A = []
for i in range(len(a)):
    A += [i + 1] * a[i]

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

for i in range(len(A)):
    h = i // W
    w = i % W
    if h % 2 == 0:
        ans[h][w] = A[i]
    else:
        ans[h][W - w - 1] = A[i]


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 for i in range(W)] for j in range(H)]

color=1
cnt=0

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


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

Solution (Python):
import sys
from heapq import heappush, heappop, heappushpop, heapify, heapreplace
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

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


def factorization(n):
    arr = []
    temp = n
    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


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

cnt = 0
ans = [[0 for j in range(w)] for i in range(h)]
for i in range(1, n + 1):
    for j in range(a[i - 1]):
        ans[cnt // w][cnt % w] = i
        cnt += 1

for i in range(h):
    if i % 2 == 1:
        ans[i] = ans[i][::-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 = [int(i) for i in input().split()]
con = 1
d = []

for i in a:
    for j in range(i):
        d.append(con)
    con += 1

whi = 0
for i in range(h):
    if whi == 0:
        a = d[i*w:w+w*i]
        L=[str(j) for j in a]
        L=' '.join(L)
        print(L)
        whi = 1
    else:
        a = d[i*w:w+w*i]
        a.reverse()
        L=[str(j) for j in a]
        L=' '.join(L)
        print(L)
        whi = 0

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

ans = [[0]*w for k in range(h)]
for i in range(h):
    for j in range(w):
        l = res.pop()
        ans[i][j] = l

for i in range(h):
    if(i%2==1):
        ans[i].reverse()
for i in range(h):
    print(*ans[i])

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

Table = [[None] * W for _ in range(H)]
h, w = 0, 0
for i, a in enumerate(A):
    for x in range(a):
        Table[h][w] = i + 1
        if h % 2:
            if w == 0:
                h += 1
            else:
                w -= 1
        else:
            if w == W - 1:
                h += 1
            else:
                w += 1
for t in Table:
    print(*t)

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

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

i, j, k = 0, 0, 0
while i < H:
    step = 1 if i % 2 == 0 else -1
    grid[i][j] = k + 1
    A[k] -= 1
    if A[k] == 0:
        k += 1
    if j + step in (-1, W):
        i += 1
    else:
        j += step

for row in grid:
    print(*row)

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

i=0
back=0
zagflag=0
if H%2==0:
   j=0
   back=0
   zagflag=0
else:
    j=W-1
    back=1
    zagflag=1
allcnt=0
colorid=1
cnt=0
while (j!=0)or(i!=H-1):
    
    if cnt==a[colorid-1]:
        colorid=colorid+1
        cnt=0
    table[i][j]=colorid
    cnt=cnt+1
    allcnt=allcnt+1
    if (((zagflag%2==1)and(j==0))or((zagflag%2==0)and(j==W-1)))and(allcnt!=0):
        i=i+1
        back=(back+1)%2
        zagflag=zagflag+1
    else:
        if back==0:
            j=j+1
        else:
            j=j-1
    
    
table[H-1][0]=N
for i in range(H):
    print(*table[i],sep=" ")

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

Solution (Python):


def submit():
    h, w = map(int, input().split())
    n = int(input())
    alist = list(map(int, input().split()))

    color = [[0 for _ in range(w)] for _ in range(h)]
    cur = 1

    
    direction = 1
    for i in range(h):
        if direction == 1:
            j = 0
        else:
            j = w - 1

        while 0 <= j < w:
            if alist[cur - 1] <= 0:
                cur += 1          
            color[i][j] = cur
            alist[cur - 1] -= 1
            j += direction

        direction *= -1
                

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


submit()

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

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

key = 0
for i in range(h):
  if i%2 == 0:
    for j in range(w):
      ans[i][j] = key+1
      a[key] -= 1
      if not a[key]:
        key += 1
  else:
    for j in range(w-1, -1, -1):
      ans[i][j] = key+1
      a[key] -= 1
      if not a[key]:
        key += 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 = [[-1] * W for _ in range(H)]

from itertools import cycle
v = cycle([(1,0),(0,1),(-1,0),(0,-1)])

def nextxy(x,y,nv):
    return x+nv[0],y+nv[1]

nv = next(v)
x,y = 0,0
for i,a in enumerate(A):
    while a > 0:
        ans[y][x] = i+1
        a -= 1
        nx, ny = nextxy(x,y,nv)
        if nx < 0 or W <= nx or ny < 0 or ny >= H or ans[ny][nx] != -1:
            nv = next(v)
        x, y = nextxy(x,y,nv)
        
for j in range(H):
    print(' '.join(map(str,ans[j])))

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

color=[]
for i in range(N):
    for _ in range(a[i]):
       color.append(i+1)

answer=[]
for y in range(H):
    answer.append([None]*W)
cursol=0
for y in range(H):
    if y % 2 == 0:
        for x in range(W):
            answer[y][x]=color[cursol]
            cursol+=1
    if y % 2 == 1:
        for x in range(W-1, -1, -1):
            answer[y][x] = color[cursol]
            cursol += 1

for y in range(H):
    print(' '.join(list(map(str,answer[y]))))

Solution (Python):


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

    k = 0
    c = [[None for j in range(w)] for i in range(h)]
    p = 0
    for i in range(h):
        jlist = range(w) if i % 2 == 0 else reversed(range(w))
        for j in jlist:
            c[i][j] = p + 1
            a[p] -= 1
            if a[p] == 0:
                p += 1
            k += 1
        print(" ".join(str(x) for x in c[i]))

if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

H,W=map(int,input().split())
n=int(input())
A=list(map(int,input().split()))
C=[]
for i in range(n):
    for _ in range(A[i]):
        C.append(i+1)


M=[deque([]) for _ in range(H)]

for i in range(H*W):
    if (i//W)%2==0:
        M[i//W].append(C[i])
    else:
        M[i//W].appendleft(C[i])

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

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

ans = []

for i in range(1, N + 1):
    ans.extend([i] * A[i - 1])

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

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

ans = [[-1 for i in range(w)] for j in range(h)]

num_list = []
for i in range(len(a)):
    num_list.extend([i+1]*a[i])

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


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

Solution (Python):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
lis = []
for i in range(N):
  for _ in range(A[i]):
    lis.append(str(i+1))
ans= []
for i in range(H):
  if i%2==0:
    add = lis[:W]
  else:
    add = lis[:W][::-1]
  ans.append(' '.join(add))
  lis = lis[W:]
print(*ans,sep='\n')

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

ans = [[0] * W for _ in range(H)]
flg = 0
i = 0
for h in range(H):
    flg ^= 1
    if flg:
        w_list = list(range(W))
    else:
        w_list = reversed(list(range(W)))
    for w in w_list:
        if A[i]:
            ans[h][w] = i+1
            A[i] -= 1
        else:
            i += 1
            ans[h][w] = i+1
            A[i] -= 1
for h in range(H):
    print(*ans[h])

Solution (Python):
h, w = map(int, input().split())
n = int(input().strip())
a = list(map(int, input().split()))
ans = []
tmp = []
for i in range(n):
    tmp += [(i + 1)] * a[i]
for i in range(len(tmp) // w):
    ans.append(tmp[i * w:(i + 1) * w])
odd = True
for elem in ans:
    if odd:
        print(*elem)
        odd = False
    else:
        print(*elem[::-1])
        odd = True

Solution (Python):

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

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

Solution (Python):
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
ans=[0 for _ in range(h*w)]
i=0
c=1
for x in a:
  while x>0:
    ans[i]=c
    x-=1
    i+=1
  c+=1

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

Solution (Python):
def solve():
    H, W = map(int, input().split())
    _ = int(input())
    a = list(map(int, input().split()))
    
    ans = [[0] * W for _ in range(H)]
    ans[0][0] = 1
    a[0] -= 1
    direction = 1
    i, j, k = 0, 0, 1
    cnt = 1
    while cnt != H * W:
        if j == W - 1 and direction == 1:
            i += 1
            direction = -1
        elif j == 0 and direction == -1:
            i += 1
            direction = 1
        else:
            j += direction
        
        if a[k - 1] == 0:
            k += 1
        a[k - 1] -= 1
        ans[i][j] = k
        cnt += 1
    
    for line in ans:
        print(' '.join(map(str, line)))


if __name__ == '__main__':
    solve()

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

c=[[0 for j in range(W)] for i in range(H)]
b=[]
for i in range(len(a)):
    b = b + [i+1 for _ in range(a[i])]

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

        
for i in range(H):
    ans =""

    for j in range(W-1):
        ans += str(c[i][j]) + " " 
    ans += str(c[i][W-1]) 
    print(ans)

Solution (Python):
H, W = map(int, input().split())
N = int(input())
arr = list(map(int, input().split()))
ans = [[0]*W for _ in range(H)]
count = 0
index = 0
for h in range(H):
    for w in range(W):
        if h % 2 == 0:
            ans[h][w] = index + 1
        else:
            ans[h][W-1-w] = index + 1
        count += 1
        if count == arr[index]:
            count = 0
            index += 1
for h in range(H):
    for w in range(W):
        print(ans[h][w], end=" ")
    print()

Solution (Python):
h, w = (int(x) for x in input().split())
n = int(input())
seq = [int(x) for x in input().split()]
ans = [[0 for _ in range(w)] for _ in range(h)]
cnt = 0
for color, val in enumerate(seq,1):
    color = str(color)
    for _ in range(val):
        if (cnt // w) % 2 == 0:
            ans[cnt // w][cnt % w] = color
        else:
            ans[cnt // w][-1 - (cnt % w)] = color
        cnt += 1
for line in ans:
    print(' '.join(line))

Solution (Python):
import numpy as np

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

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

l = []
for i in range(n):
    l.extend([i + 1] * a[i])

l = np.array(l).reshape((h,w))
cnt = 0
for i in range(h):
    if cnt % 2 == 1:
        l[i] = np.flipud(l[i])
    cnt+=1
for i in l:
    print(*i)

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

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

g = [[-1] * w for _ in range(h)]

ch = 0
cw = 0
o = 1

for i in range(n):
    while a[i] > 0:
        g[ch][cw] = i + 1

        a[i] -= 1

        if not (0 <= cw + o < w):
            ch += 1

            if o == 1:
                o = -1
            else:
                o = 1
        else:
            cw += o

for i in g:
    print(*i)