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()))
tiles = [[0 for _ in range(W)] for _ in range(H)]
index = 0
rest_a = A[0]
for h in range(H):
  for w in range(W):
    if rest_a == 0:
      index += 1
      rest_a = A[index]-1
    else:
      rest_a -= 1
    if h%2 == 0:
      tiles[h][w] = index+1
    else:
      tiles[h][W-w-1] = index+1
for h in range(H):
  print(' '.join(map(str, tiles[h])))

Solution (Python):
import sys


def main():
    h, w = map(int, sys.stdin.buffer.readline().split())
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    ans = [0]*(w*h)
    now = 0
    for i, x in enumerate(a):
        for j in range(x):
            ans[now + j] = i+1
        now += x

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import numpy as np


def main():
    h, w = map(int, sys.stdin.buffer.readline().split())
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    ans = np.zeros(w*h, np.int64)
    now = 0
    for i, x in enumerate(a):
        for j in range(x):
            ans[now + j] = i+1
        now += x

    ans = ans.reshape(h, w)
    for i in range(h):
        if i % 2:
            print(*ans[i, ::-1])
        else:
            print(*ans[i])


if __name__ == "__main__":
    main()

Solution (Python):
H,W,N,*a=map(int,open(0).read().split())
O=[]
for i in range(N):O+=[i+1]*a[i]
for i in range(H):print(*O[W*i:W*-~i][::(-1)**i])

Solution (Python):
H,W,N,*a=map(int,open(0).read().split())
O=[[0]*W for _ in range(H)]
i=0
for j in range(N):
 for k in range(a[j]):w=i%W if i//W%2 else W-1-i%W;O[i//W][w]=str(j+1);i+=1
for i in range(H):print(' '.join(O[i]))

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

ans=[]
for i in range(N):
    for j in range(A[i]):
        ans.append(i+1)

for y in range(H):
    x=ans[y*W:y*W+W]
    if y%2!=0:
        x.reverse()
    print(*x)

Solution (Python):
h,w,n,*A=map(int,open(0).read().split());c=[]
for i in range(n):c+=[i+1]*A[i]
for i in range(h):print(*c[i*w:-~i*w][::(-1)**i])

Solution (Python):
h,w,n,*A=map(int,open(0).read().split());c=[]
for i in range(n):c+=[i+1]*A[i]
for i in range(h):print(*c[i*w:-~i*w:][::(-1)**i])

Solution (Python):
h,w,n,*A=map(int,open(0).read().split());c=[]
for i in range(n):c+=[i+1]*A[i]
for i in range(h):print(*(c[i*w:-~i*w])[::(-1)**i])

Solution (Python):
h,w,n,*A=map(int,open(0).read().split());c=[]
for i in range(1,n+1):c+=[i]*A[i-1]
for i in range(h):print(*(c[i*w:-~i*w])[::(-1)**i])

Solution (Python):
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
tmp=[]
for i in range(len(a)):
  for _ in range(a[i]):
    tmp.append(i+1)
ans=[]
for i in range(h):
  if i%2==0:
    print(*tmp[i*w:i*w+w])
  else:
    print(*list(reversed(tmp[i*w:i*w+w])))

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

Solution (Python):
h, w = (int(x) for x in input().split())
n = int(input())
A = list(int(x) for x in input().split())
B = []
for i, a in enumerate(A, start=1):
    B += [i] * a
for i in range(h):
    start, end = i * w, i * w + w
    if i % 2 == 0:
        print(*B[start:end])
    else:
        print(*B[start:end][::-1])

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

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

for i in range(H):

    if i % 2 == 0:
        k = 1
    else:
        k = -1

    ans = ans_lis[i * W:(i + 1) * W][::k]
    ans = list(map(str, ans))
    print(" ".join(ans))

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    h, w = LI()
    n = I()
    a = [0] + LI()

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


    zahyo = [0,0]
    pr = True
    for color in range(1, len(a)):
        for i in range(a[color]):
            board[zahyo[0]][zahyo[1]] = color
            if pr:
                if zahyo[1] == w-1:
                    zahyo[0] += 1
                    pr = False
                else:
                    zahyo[1] += 1
            else:
                if zahyo[1] == 0:
                    zahyo[0] += 1
                    pr = True
                else:
                    zahyo[1] -= 1


    for line in board:
        print(*line)
            


                    


main()

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

ans = []
for i, a in enumerate(A):
  index = i + 1
  for _ in range(a):
    ans.append(index)
  
m = [[0 for _ in range(w)] for _ in range(h)]
cnt = 0
for i in range(h):
  if i % 2 == 0:
    for j in range(w):
      m[i][j] = ans[cnt]
      cnt += 1
  else:
    for j in range(w-1,-1,-1):
      m[i][j] = ans[cnt]
      cnt += 1
  print(" ".join(map(str, m[i])))

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

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

for i in range(H):
    c = b[i * W:i * W + W]
    if i % 2 == 1:
        c = c[::-1]
    print(" ".join(map(str, c)))

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)]
h = 0
w = 0
for i in range(N):
  for j in range(a[i]):
    g[h][w] = i+1
    if h % 2 == 0:
      if w == (W-1):
        h += 1
      else:
        w += 1
    else:
      if w == 0:
        h += 1
      else:
        w -= 1
        
for i in range(H):
  for j in range(W):
    print(g[i][j], end=" ")
  print("")

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

li = []
for i in range(n):
    for j in range(L[i]):
        li.append((i+1))

l = h*w-len(li)
li = li + [0]*l
ans = []
for i in range(h):
    ans.append(li[i*w:(i+1)*w])

for i in range(h-1):
    if ans[i][-1] == ans[i+1][0]:
        ans[i+1] = ans[i+1][::-1]

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

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

H,W=mint()
N=intput()
A=[0]+lint()
C=[[0]*W for _ in range(H)]
k=1
a=0
for i in range(H):
    tmp = range(W) if i%2==0 else range(W-1,-1,-1)
    for j in tmp:
        C[i][j]=k
        a+=1
        if a==A[k]:
            k+=1
            a=0
for c in C:
    lprint(c,' ')
    print('')

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

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


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

Solution (Python):
h, w = list(map(int, input().split()))
n = int(input())
colors = list(map(int, input().split()))
ans = [[0] * w for i in range(h)]
color_stock = []
for i in range(len(colors)):
    for j in range(colors[i]):
        color_stock.append(i+1)


for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            c = color_stock.pop()
            ans[i][j] = c
    else:
        for j in range(w, 0, -1):
            c = color_stock.pop()
            ans[i][j-1] = c

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

Solution (Python):
'''
Created on 2020/09/04

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  H,W=map(int,pin().split())
  N=int(pin())
  a=list(map(int,pin().split()))
  l=[]
  for i in range(N):
    l+=[str(i+1) for _ in range(a[i])]
  s=1
  ans=[]
  for j in range(H):
    if s==1:
      ans=list(l[j*W:(j+1)*W])
      s=-1
    else:
      ans=list(l[j*W:(j+1)*W])
      ans.reverse()
      s=1
    u=" ".join(ans)
    print(u)
  return 
main()

Solution (Python):
H,W=map(int,input().split())
N = int(input())
Alist = list(map(int,input().split()))
C = [[0]*W for _ in range(H)]
def change(x,y):
    return (-y,x)
h = 0
w = 0
(x,y) = (1,0)
i = 1
for a in Alist:
    while a > 0:
        C[h][w] = i
        h += y
        w += x
        a -= 1
        if w == W or h == H or w == -1 or h == -1 or C[h][w] != 0:
            h -= y
            w -= x
            (x,y) =change(x,y)
            h += y
            w += x
    i += 1
for c in C:
    print(*c)

Solution (Python):
def main():
    h,w=map(int,input().split())
    n=int(input())
    a=list(map(int,input().split()))
    ans=[[0]*w for _ in range(h)]
    x,y=0,0
    r=False
    for i,v in enumerate(a):
        i+=1
        while v > 0:
            
            ans[y][x] = i
            v -= 1
            x = x-1 if r else x+1
            if x < 0 or w <= x:
                r=not r
                x = w-1 if r else 0
                y+=1
    for i in ans:
        print(*i)
    
if __name__ == "__main__":
    main()

Solution (Python):
r, c = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

x = 0
grid = [[] for i in range(r)]
for i in range(r):
    while x < n and len(grid[i])+a[x] <= c:
        grid[i].extend([x+1]*a[x])
        x += 1
    if x < n:
        a[x] -= c-len(grid[i])
        grid[i].extend([x+1]*(c-len(grid[i])))

for i in range(1,r,2):
    grid[i] = grid[i][::-1]

for row in grid:
    print(*row)

Solution (Python):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0] * w for _ in range(h)]
now_color = 1
now_a_index = now_color - 1
ans_index = [0, 0]
for i in range(h * w):
    ans[ans_index[0]][ans_index[1]] = now_color
    a[now_a_index] -= 1
    if a[now_a_index] == 0:
        now_color += 1
        now_a_index += 1
    ans_index[1] += 1
    if ans_index[1] >= w:
        ans_index[1] = 0
        ans_index[0] += 1
cnt = 0
for l_ans in ans:
    if cnt % 2 == 1:
        for ll_ans in reversed(l_ans):
            print(ll_ans, end=" ")
        cnt += 1
    else:
        for ll_ans in l_ans:
            print(ll_ans, end=" ")
        cnt += 1
    print("")

Solution (Python):


h,w = list(map(int, input().split()))
n = int(input())
a = [0] + list(map(int, input().split()))[::-1]
b = [[0] * w for _ in range(h)]
color = 1
rest = a.pop()
for x in range(w):
    if x&1:
        hh = reversed(range(h))
    else:
        hh = range(h)
        
    for y in hh:
        b[y][x] = color
        rest -= 1
        if rest == 0:
            color += 1
            rest= a.pop()

for line in b:
    print(*line)

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

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

cur = 1
cnt = 0
for y in range(h):
    for x in range(w):
        if y % 2 == 0:
            g[y][x] = cur
        else:
            g[y][w-x-1] = cur

        cnt += 1
        if a[cur-1] == cnt:
            cnt = 0
            cur += 1


for row in g:
    print(" ".join(map(str, row)))

Solution (Python):
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
answers=[[0 for _ in range(W)] for _ in range(H)]
h=0
w=0
number=1
for a_ in a:
    for _ in range(a_):
        answers[h][w] = number
        if w>=0:
            w+=1
        else:
            w-=1
        if w==W:
            h+=1
            w=-1
        elif w==-W-1:
            h+=1
            w=0
    number+=1
for answer in answers:
    print(*answer)

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

b = queue.Queue()
for i, j in enumerate(a):
    for _ in range(j):
        b.put(i+1)

for i in range(h):
    ans = []
    for j in range(w):
        ans += [b.get()]
    if i%2 == 1:
        ans = list(reversed(ans))
    print(*ans)

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


for i in range(1,n+1):
  for j in range(a[i-1]):
    lst.append(str(i))

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

for i in range(h):
  if i%2==0:
    for j in range(w):
      ans[i][j]=lst.pop()

  else:
    for j in range(w-1,-1,-1):
      ans[i][j]=lst.pop()

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

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


for i in range(1,n+1):
  for j in range(a[i-1]):
    lst.append(str(i))

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

for i in range(h):
  if i%2==0:
    for j in range(w):
      ans[i][j]=lst.pop()

  else:
    for j in range(w-1,-1,-1):
      ans[i][j]=lst.pop()

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

Solution (Python):
def main():
    h,w = map(int,input().split())
    n = int(input())
    a = list(map(int,input().split()))
    c = [[0 for i in range(w)] for i in range(h)]
    p = [0,0]
    up = 1
    for i in range(n):
        cnt = 0
        while cnt<a[i]:
            c[p[0]][p[1]] = i+1
            cnt += 1
            if up==1 and p[1] < w-1:
                p[1] += 1
            elif up == 1 and p[1] == w-1:
                p[1] = w-1
                p[0] += 1
                up = 0
            elif up == 0 and p[1] > 0:
                p[1] -= 1
            elif up == 0 and p[1] == 0:
                p[1] = 0
                p[0] += 1
                up = 1
    for i in range(h):
        print(' '.join([str(x) for x in c[i]]))

if __name__ == "__main__":
    main()

Solution (Python):




def solve(h,w,n,a):
  acc = []
  for i in range(n):
    acc.extend([i+1]*a[i])
  res = []
  k = 0
  for i in range(h):
    res.append(acc[k:k+w] if i%2==0 else acc[k:k+w][::-1])
    k += w
  return res


def main():
  H,W = map(int,input().split())
  N = int(input())
  a = list(map(int,input().split()))
  ans = solve(H,W,N,a)
  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()))
c = []

for i in range(n):
  while a[i]>0:
    a[i] -=1
    c.append(str(i+1))

for i in range(h):
  if i%2==0:
    print(" ".join(c[i * w:(i + 1) * w]))
  else:
    print(" ".join(reversed(c[i * w:(i + 1) * w])))

Solution (Python):
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():

    H,W = NMI()
    N = NI()
    A = NLI()
    
    ls = []
    
    
    for n in range(N):
        for _ in range(A[n]):
            ls.append(n+1)
    
    
    for h in range(H):
        if h % 2 == 0:
            print(" ".join(map(str,ls[h*W:(h+1)*W])))
        else:
            print(" ".join(map(str,list(reversed(ls[h*W:(h+1)*W])))))



if __name__ == '__main__':
    main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

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


def main():
    H, W = MAP()
    N = INT()
    A = LIST()

    idx = 0
    cnt = 0
    C = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            C[i][j] = idx + 1
            cnt += 1
            if A[idx] == cnt:
                idx += 1
                cnt = 0

    for i in range(H):
        line = list(reversed(C[i])) if i % 2 else C[i]
        print(*line)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

ans = []
for i in range(N):
    tmp = [i+1] * A[i]
    ans += tmp

ans = np.array(ans).reshape(H, W).tolist()
for i in range(H):
    if i % 2 == 1:
        ans[i] = ans[i][::-1]

for a in ans:
    print(' '.join([str(i) for i in a]))

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 = [[0] * W for i in range(H)]
i = 0
for h in range(H):
    for w in range(W):
        while A[i] == 0:
            i += 1
        if h % 2 == 0:
            
            C[h][w] = i + 1
        else:
            
            C[h][W-w-1] = i + 1
        A[i] -= 1

for c in C:
    print(*c, sep=" ")

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

for i in c:
  print(' '.join(map(str, i)))

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W = map(int, readline().split())
    N = int(readline())
    A = list(map(int, readline().split()))
    C = [[0]*W for _ in range(H)]
    h=0
    w=0
    for i,a in enumerate(A):
        for _ in range(a):
            C[h][w] = i +1
            w += 1
            if w==W:
                h += 1
                w = 0
    for i,c in enumerate(C):
        if i%2==0:
            print(' '.join(map(str, c)))
        else:
            print(' '.join(map(str, reversed(c))))



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 _ in range(H)]
x = -1
for c, i in enumerate(A, 1):
  for _ in range(i):
    x += 1
    row = x // W
    column = x % W
    C[row][column] = c
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()))

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

strate = True
w = 0
h = 0
dp[0][0] = 1

for key,value in enumerate(a):
    if key == 0:
        count = 1
        if value == 1:
            continue       
    else:
        count = 0

    while count < value:
        count += 1
        if strate:
            if w < W-1:
                w += 1
            elif w == W-1:
                strate = False
                h += 1
        else:
            if 0 < w:
                w -= 1
            elif w == 0:
                strate = True
                h += 1

        dp[h][w] = key+1
                
for aa in dp:
    print(*aa)

Solution (Python):
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
B = [[0 for _ in range(W)] for _ in range(H)]

col = 1
cnt = 0
i = 0
j = 0
d = 1
while True:
    if cnt<A[col]:
        B[i][j] = col
        cnt += 1
    else:
        col += 1
        cnt = 0
        B[i][j] = col
        cnt += 1
    if d==1 and j<W-1:
        j += 1
    elif d==1 and j==W-1:
        i += 1
        d = -1
    elif d==-1 and j>0:
        j -= 1
    elif d==-1 and j==0:
        i += 1
        d = 1
    if i>=H:break
for i in range(H):
    print(*B[i])

Solution (Python):



def main():
    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)]
    k = 0

    for j in range(h):
        if j % 2 == 0:
            for i in range(w):
                c[j][i] = k + 1
                a[k] -= 1

                if a[k] == 0:
                    k += 1
        else:
            for i in range(w - 1, -1, -1):
                c[j][i] = k + 1
                a[k] -= 1

                if a[k] == 0:
                    k += 1

    for ci in c:
        print(' '.join(map(str, ci)))


if __name__ == '__main__':
    main()

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

MAP = [[0 for i in range(W)] for j in range(H)]

h = 0
w = 0
num = 1

for i in range(N):
    while A[i] > 0:
        MAP[h][w] = num
        A[i] -= 1
        if h % 2 == 0:
            if w == W - 1:
                h += 1
            else:
                w += 1
        else:
            if w == 0:
                h += 1
            else:
                w -= 1
    num += 1

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

Solution (Python):
from collections import deque

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

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

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

    
for a in ans:
    print(*a)

Solution (Python):
h, w = map(int, input().split())
n = int(input())
alst = list(map(int, input().split()))
cnt = 0
pos = 0
rev = False
for i in range(h):
    ans = [0 for _ in range(w)]
    for j in range(w):
        if rev:
            ans[w - 1 - j] = pos + 1
        else:
            ans[j] = pos + 1
        cnt += 1
        if alst[pos] == cnt:
            cnt = 0
            pos += 1
    print(*ans)
    if rev:
        rev = False
    else:
        rev = True

Solution (Python):
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
cnt = 0
now = 0
c=[[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
  iter_w = range(W)
  if h%2:
    iter_w = reversed(iter_w)
  for w in iter_w:
    c[h][w] = now + 1
    cnt += 1
    if cnt == a[now]:
      now += 1
      cnt = 0

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

Solution (Python):
import numpy as np

h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [["" for _ in range(w)] for _ in range(h)]
ptr = 0
for y in range(h):
    for x in range(w):
        if a[ptr] == 0:
            ptr += 1
        ans[y][x] = str(ptr+1)

        a[ptr] -= 1

for y in range(h):
    print(" ".join(ans[y] if y % 2 == 0 else reversed(ans[y])))

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

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

C=[0]
for a in A:
    C.append(C[-1]+a)
K=0
X,Y=0,0
D=1
while K<H*W:
    K+=1

    B[Y][X]=D

    if Y%2:
        if X==0:
            Y+=1
        else:
            X-=1
    else:
        if X==W-1:
            Y+=1
        else:
            X+=1

    if K==C[D]:
        D+=1

L=[" ".join(map(str,P)) for P in B]
print("\n".join(L))

Solution (Python):

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

Solution (Python):
def resolve():
    '''
    code here
    '''
    H, W = [int(item) for item in input().split()]
    N = int(input())
    As = [int(item) for item in input().split()]

    line = []
    for i, val in enumerate(As):
        line += val * [i+1]

    grid = [[] for _ in range(H)]

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

    for temp in grid:
        print(*temp)

if __name__ == "__main__":
    resolve()

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

res = []

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

for i in range(H):
    if i%2 == 0:
        print(" ".join(res[i*W:(i+1)*W]))
    else:
        print(" ".join(reversed(res[i*W:(i+1)*W])))

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

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

x=0
for i in range(1,n+1):
    c[x:x+a[i-1]]=[i]*(a[i-1])
    x+=a[i-1]

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

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    h, w = na()
    n = ni()
    a = na()
    g = [0] * (h*w)
    gi = 0; ai = 0
    while gi != h * w:
        anow = a[ai]
        for i in range(gi, gi+anow):
            g[i] = (ai+1)
        gi = gi + anow
        ai += 1
    g_rev = g[::-1]
    for i in range(h):
        l = i*w
        r = i*w + w
        if i % 2 == 0:
            print(*g[l:r])
        else:
            l_rev = h*w - r
            r_rev = h*w - l
            print(*g_rev[l_rev:r_rev])
if __name__ == "__main__":
    main()

Solution (Python):
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
B = [[0 for _ in range(W)] for _ in range(H)]
col = 1
cnt = 0
y = 0
x = 0
d = "R"
while y<H:
    if cnt<A[col]:
        B[y][x] = col
        cnt += 1
    else:
        col += 1
        cnt = 0
        B[y][x] = col
        cnt += 1
    if x<W-1 and d=="R":
        x += 1
    elif x==W-1 and d=="R":
        y += 1
        d = "L"
    elif d=="L" and x>0:
        x -= 1
    elif d=="L" and x==0:
        y += 1
        d = "R"
for i in range(H):
    print(*B[i])

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

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

cnt = 0
i, j = 0, 0
direction = 0  
ptr = 0
res = A[ptr]
while cnt < h * w:
    cnt += 1
    
    if res > 0:
        grid[i][j] = ptr + 1
        res -= 1
    elif res == 0:
        ptr += 1
        grid[i][j] = ptr + 1
        res = A[ptr] - 1
    
    if direction == 0 and j < w - 1:
        j += 1
    elif direction == 0 and j == w - 1:
        i += 1
        direction = 1
    elif direction == 1 and j > 0:
        j -= 1
    elif direction == 1 and j == 0:
        i += 1
        direction = 0

for line in grid:
    print(" ".join((str(i) for i in line)))