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())
S=list(map(int,input().split()))

T = [[0 for j in range(W)] for i in range(H)]
posx=1
posy=1
for i in range(N):
    tmp=S[i]
    cnt=0
    while tmp>cnt:
        T[posy-1][posx-1]=i+1
        if posy%2!=0:
            posx+=1
            if posx>W:
                posy+=1
                posx-=1
        else:
            posx-=1
            if posx<1:
                posy+=1
                posx+=1
        cnt+=1  

for i in T:
    print(*i)

Solution (Python):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(N):
    D[i + 1] = A[i]
C = []
for k, v in D.items():
    [C.append(k) for _ in range(v)]
h = 0
while True:
    h += 1
    for i in range(W):
        print(C[i], end=' ')
    print('')
    [C.pop(0) for _ in range(W)]
    if h == H:
        break
    h += 1
    for i in reversed(range(W)):
        print(C[i], end=' ')
    print('')
    [C.pop(0) for _ in range(W)]
    if h == H:
        break

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



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

cnt = 0
ans = [[-1]*W for _ in range(H)]
tmp = a.pop(0)
color = 1
flg = 0

for i in range(H):
	for j in range(W):
		if i%2 == 1:
			j = -j-1
		ans[i][j] = color
		tmp -= 1
		if tmp == 0:
			if not a:
				break
			tmp = a.pop(0)
			color += 1



for i in ans:
	print(" ".join([str(x) for x in i]))

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

Solution (Python):
h,w,_,*a=map(int,open(0).read().split())
l=[]
for i,c in enumerate(a): l+=[i+1]*c
for i in range(h): print(*l[i*w:-~i*w][::2*(i%2)-1])

Solution (Python):
h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=w-t:
    g[r]+=[i]*(w-t)
    r+=1; c-=w-t; t=0
  if c:
    g[r]+=[i]*c
    t+=c
for i in range(h): print(*g[i][::2*(i%2)-1])

Solution (Python):
h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=(s:=w-t):
    g[r]+=[i]*s
    r+=1; c-=s; t=0
  if c:
    g[r]+=[i]*c
    t+=c
for i in range(h): print(*g[i][::2*(i%2)-1])

Solution (Python):
h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=(s:=w-t):
    if r%2: g[r]+=[i]*s
    else: g[r]=[i]*s+g[r]
    r+=1
    c-=s
    t=0
  if c:
    if r%2: g[r]+=[i]*c
    else: g[r]=[i]*c+g[r]
    t+=c
for r in g: print(*r)

Solution (Python):
H,W,N,*a = map(int, open(0).read().split())
ans = [[0] * W for _ in range(H)]
count = 0
using = 0
for i in range(H*W):
    dm = divmod(i,W)
    h = dm[0]
    if h % 2 == 0:
        w = dm[1]
    else:
        w = (dm[1]+1) * (-1)
    ans[h][w] = using + 1
    count += 1
    if count == a[using]:
        using += 1
        count = 0
for x in ans:
    print(*x)

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

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

H,W = I()
N = i()
a = l()
list = []
for i in range(N):
    for j in range(a[i]):
        list.append(i+1)
ans = [[] for _ in range(H)]
for i in range(H):
    for j in range(W):
        ans[i].append(list.pop(0))
for i in range(H):
    if i%2 == 1:
        print(*ans[i][::-1])
    else:
        print(*ans[i])

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

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

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

b=[]
for i in range(n):
    for k in range(a[i]):
        b.append(i+1)

hidx=0
widx=0
for i in range(len(b)):
    ans[hidx][widx]=b[i]
    if hidx%2==0:
        widx+=1
    else:
        widx-=1
    if widx==w:
        widx=-1
        hidx+=1
    if widx==-(w+1):
        widx=0
        hidx+=1

for i in range(h):
    answer=ans[i]
    L=[str(a) for a in answer]
    L=" ".join(L)
    print(L)

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

M = [[0] * w for _ in range(h)]
ii = 0
ij = 0
for i, a in enumerate(A):
    i += 1
    for _ in range(a):
        M[ij][ii] = i

        if ij%2 == 0:
            ii += 1
            if ii == w:
                ij += 1
                ii = w-1
        else:
            ii -= 1
            if ii == -1:
                ij += 1
                ii = 0
for l in M:
    print(*l)

Solution (Python):
import sys

H, W = map(int, sys.stdin.readline().split())
N = int(sys.stdin.readline())
A =  list(map(int, sys.stdin.readline().split()))

grid = [[0 for _ in range(W)] for _ in range(H)]
point = A[0]
color = 0
for i in range(H):
    for j in range(W):
        
        if i % 2 == 0:
            x = j
        else:
            x = W - j - 1
        if point == 0:
            color += 1
            point = A[color]

        grid[i][x] = color + 1
        point -= 1

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

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

for i in range(len(a)):
  l += [(i+1)]*a[i]
  
for i in range(h):
  if i%2 == 0:
    print(*l[i*w:(i+1)*w])
  else:
    print(*list(reversed(l[i*w:(i+1)*w])))

Solution (Python):
h,w = map(int,input().split())
n = int(input())
ls = list(map(int,input().split()))
di = []
def split_list(l, n):
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]
for i in range(n):
    for j in range(ls[i]): 
        di.append(i+1)
new = list(split_list(di, w))
for j in range(len(new)):
    if j % 2 == 0:
        new[j].sort(reverse=True)
for k in range(len(new)):
    print(*new[k])

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

Solution (Python):
h, w = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
color = [[0]*w for i in range(h)]
loch = 0
locw = 0
for i in range(n):
  for j in range(a[i]):
    color[loch][locw]=str(i+1)
    if loch % 2 == 0:
      if locw != w-1:
        locw+=1
      else:
        loch+=1
    else: 
      if locw != 0:
        locw-=1
      else:
        loch+=1

for i in range(h):
  print(" ".join(color[i]))

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

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

color = 0
for ai in a:
    color += 1
    count = 0
    for i in range(w):
        for j in range(h):
            if i % 2 == 0:
                if colored[j][i] == 0:
                    colored[j][i] = color
                    count += 1
                    if count == ai:
                        break
            else:
                if colored[h-1-j][i] == 0:
                    colored[h-1-j][i] = color
                    count += 1
                    if count == ai:
                        break
        else:
            continue
        break

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

Solution (Python):
def resolve():
    H, W = list(map(int, input().split()))
    N = int(input())
    A = list(map(int, input().split()))
    C = [[0 for _ in range(W)] for __ in range(H)]
    color = 1
    reverse = False
    cnt = 0
    for i in range(H):
        for j in range(W):
            if reverse:
                _j = W-1 - j
            else:
                _j = j
            C[i][_j] = color
            cnt += 1
            if cnt == A[color-1]:
                color += 1
                cnt = 0
        reverse = not reverse
    [print(" ".join(map(str, C[i]))) for i in range(H)]
        

if '__main__' == __name__:
    resolve()

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

for i in range(1, H+1):
    for j in range(1, W+1):
        m[i][j] = 0

d = [0, 1]
c = [1, 0]
for i in range(N):
    for j in range(a[i]):
        if m[c[0]+d[0]][c[1]+d[1]] != 0:
            if d == [0, 1]:
                d = [1, 0]
            elif d == [1, 0]:
                d = [0, -1]
            elif d == [0, -1]:
                d = [-1, 0]
            else:
                d = [0, 1]
        c = [c[0]+d[0], c[1]+d[1]]
        m[c[0]][c[1]] = i+1

for i in range(H):
    print(*m[i+1][1:W+1])

Solution (Python):
from collections import deque
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
c=1
for i in range(h):
    row=deque()
    for j in range(w):
        if i%2==0:
            row.append(c)
            a[c-1]-=1
            if a[c-1]==0:
                c+=1
        else:
            row.appendleft(c)
            a[c-1]-=1
            if a[c-1]==0:
                c+=1
    print(*row)

Solution (Python):
def main():
    def flatten_list(l):
        for el in l:
            if isinstance(el, list):
                yield from flatten_list(el)
            else:
                yield el
    H, W = list(map(int, input().split()))
    n = int(input())
    A = list(map(int, input().split()))
    ans = []
    for i, a in enumerate(A):
        ans .append([str(i + 1)] * a)
    ans = list(flatten_list(ans))
    ans = [ans[i:i + W] if i // W % 2 == 0 else ans[i + W - 1:i - 1:-1] for i in range(0, len(ans), W)]
    [print(' '.join(a)) for a in ans]

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    h, w, n, *a = map(int, open(0).read().split())
    s = sum([[i + 1] * a[i] for i in range(n)], [])

    for i in range(h):
        print(' '.join(map(str, s[i * w:(i + 1) * w])) if i % 2 == 0 else ' '.join(map(str, s[i * w:(i + 1) * w][::-1])))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    h, w, n, *a = map(int, open(0).read().split())
    l = [[i + 1] * a[i] for i in range(n)]
    s = sum(l, [])

    f = False
    ans = ''
    for i in range(h):
        x = s[i * w: (i + 1) * w]
        if f:
            x = x[::-1]
        f = not f
        ans += ' '.join(map(str, x)) + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
def main():
  ans = [[0]*W for _ in range(H)]
  color = 0
  num = 0
  for i in range(H):
    if i % 2 == 0:
      for j in range(W):
        ans[i][j] = color+1
        num += 1
        if num == a[color]:
          color += 1
          num = 0
    else:
      for j in range(W-1, -1, -1):
        ans[i][j] = color+1
        num += 1
        if num == a[color]:
          color += 1
          num = 0
  for i in range(H):
    print(*ans[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()))


j=1
for i in range(H):
    x=deque()
    while len(x)<W:
        if i%2==0:
            a[j-1]-=1
            x.append(str(j))
        else:
            a[j-1]-=1
            x.appendleft(str(j))
        if a[j-1]==0:
            j+=1
    A=" ".join(list(x))
    print(A)

Solution (Python):
h, w, n, *a = map(int, open(0).read().split())
l = []
for c, a in enumerate(a, 1):
    l += [c] * a
for p in range(h):
    print(*l[p*w:-~p*w][::[1, -1][p%2]])

Solution (Python):
h, w, n, *a = map(int, open(0).read().split())
l = []
for c, a in enumerate(a):
    l += [c + 1] * a
for p in range(h):
    print(*l[p*w:-~p*w][::[1, -1][p%2]])

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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


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


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





H,W = IL()
N = I()
A = IL()
As = []
for i in range(N):
  As.extend([i+1]*A[i])

color = []

for i in range(H):
  temp = []
  for j in range(W):
    temp.append(As.pop())
  if i%2:
    temp = temp[::-1]
  color.append(temp)

for c in color:
  print(*c)

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

ans=[[0]*W for _ in range(H)]
p=[0,0]
for i in range(N):
    cnt=a[i]
    while cnt>0:
        ans[p[0]][p[1]]=i+1
        if p[1]%2==0:
            if p[0]==H-1:
                p[1]+=1
            else:
                p[0]+=1
        else:
            if p[0]==0:
                p[1]+=1
            else:
                p[0]-=1
        cnt-=1

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

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

res=[]

for i in range(n):
    for j in range(al[i]):
        res.append((i+1))

for k in range(h):
    temp = res[k*w:(k+1)*w]        
    if k % 2==1:
        temp = list(reversed(temp))
    else:
        pass
    print(str(temp).replace("[","").replace("]","").replace(","," "))

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

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

l_list = []

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

judge = 0
for i in range(H):
    p_list = l_list[i*W:(i+1)*W]
    if judge % 2 == 1:
        p_list = p_list[::-1]
    for j in p_list:
        print(j, end=' ')
    print()
    judge += 1

Solution (Python):
def main():
    H, W = list(map(int, input().split(' ')))
    N = int(input())
    A = list(map(int, input().split(' ')))
    colors = list()
    for i, a in enumerate(A):
        c = i + 1
        for _ in range(a):
            colors.append(c)
    assert len(colors) == H * W
    ans = [[0 for _ in range(W)] for _ in range(H)]
    
    for i, c in enumerate(colors):
        w = i // H
        h = min([i % (2 * H), 2 * H - 1 - (i % (2 * H))])
        ans[h][w] = c
    for row in ans:
        print(' '.join(map(str, row)))


if __name__ == '__main__':
    main()

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())


    
    
    h, w = mi()
    n = ii()
    L = lmi()

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

    grid = [color_command[i:i+w] if (i//w)%2 == 0 else list(reversed(color_command[i:i+w])) for i in range(0, (h-1)*w+1, w)]

    for line in grid:
        print(*line)


if __name__ == "__main__":
    main()

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

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


def zigzag(h, w):
    ih, iw = 0, 0

    while ih < h:
        yield (ih, iw)

        if ih % 2 == 0:
            if iw == w - 1:
                ih += 1
            else:
                iw += 1
        else:
            if iw == 0:
                ih += 1
            else:
                iw -= 1


ia = 0
ic = 0

for ih, iw in zigzag(h, w):
    ia += 1
    if ia > a[ic]:
        ic += 1
        ia = 1

    color[ih][iw] = ic + 1


for row in color:
    print(' '.join(map(str, row)))

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

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

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

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

    w = 0
    toRight = True
    idx = 0
    for h in range(H):

        while 0 <= w < W:
            field[h][w] = str(paint[idx])
            idx += 1
            if toRight:
                w += 1
            else:
                w -= 1

        if toRight:
            toRight = False
            w = w-1
        else:
            toRight = True
            w = 0

    for i in range(H):
        print(" ".join(field[i]))

    
if __name__ == '__main__':
    solve()

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

g = [[1]*(W+2)]
for i in range(H):
    g.append([1] + [0]*W + [1])
g.append([1]*(W+2))

temp = [[1, 1]]
g[1][1] = 1
c, cnt = 1, 0
while temp:
    p = temp.pop()
    for y, x in [[0, 1], [0, -1], [1, 0]]:
        if g[p[0]+y][p[1]+x] == 0:
            temp.append([p[0]+y, p[1]+x])
            if c == a[cnt]:
                cnt += 1
                c = 1
            else: c += 1
            g[p[0]+y][p[1]+x] = cnt+1
            break
for gg in g[1:-1]:
    print(*gg[1:-1])

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

line = []

for i, item in enumerate(a):
    line.extend([i+1] * item)

for i, item in enumerate(line):
    sho = i // w
    amari = i % w
    if sho % 2 == 0:
        ret[sho][amari] = item
    else:
        ret[sho][w-1-amari] = item

for item in ret:
    print(' '.join(map(str, item)))

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

c=[['']*W for _ in range(H)]
visit=[[0]*W for _ in range(H)]

q=[[0,0,1]]

while len(q)>0:
    h,w,clr=q.pop()
    visit[h][w]=1
    c[h][w]=str(clr)
    a[clr-1]-=1
    if a[clr-1]==0:
        clr+=1

    if h+1<H and visit[h+1][w]==0:
        q.append([h+1,w,clr])
    elif 0<h and visit[h-1][w]==0:
        q.append([h-1,w,clr])
    elif w+1<W and visit[h][w+1]==0:
        q.append([h,w+1,clr])
    
for i in range(H):
    print(' '.join(c[i]))

Solution (Python):
from collections import deque
H,W = map(int,input().split())
n = int(input())
a_ls = list(map(int, input().split()))
color_q = deque()
for color, times in enumerate(a_ls,1):
    for _ in range(times):
        color_q.append(color)
ans_mat = [[0] * W for _ in range(H)]
for y in range(H):
    for x in range(W):
        ans_mat[y][x] = color_q.popleft()
for i,y in enumerate(range(H)):
    ans_ls = ans_mat[y]
    if i % 2 == 1:
        ans_ls = ans_ls[::-1]
    ans_ls = list(map(str,ans_ls))
    print(' '.join(ans_ls))

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

ans = [[-1 for _ in range(W)] for _ in range(H)]
color = 1

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

for i in range(H):
    a = ans[i]
    if i % 2 == 1:
        a = a[::-1]
    print(" ".join(map(str, a)))

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

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

H, W = getNM()
N = getN()
A = getList()
dist = []
for i in range(N):
    for j in range(A[i]):
        dist.append(i + 1)
distalta = [[0] * W for i in range(H)]
for i in range(H * W):
    
    hei = i // W
    if hei % 2 == 0:
        wid = i % W
    else:
        wid = -1 * (i % W) - 1
    distalta[hei][wid] = dist[i]
for i in distalta:
    print(*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) ]

v=0
d=0
df=0
for i in range(n):
    t=i+1
    f=0
    while f<a[i]:
        if df==0:
            ans[v][d]=t

        elif df==1:

            ans[v][w-1-d]=t
        f+=1
        d+=1
        if df==0 and d==w:
            v+=1
            df^=1
            d=0
        if df==1 and w-d==0:
            v += 1
            df ^= 1
            d = 0
for h in ans:
    print(*h)

Solution (Python):
import numpy as np

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

out = []

for i, a in enumerate(A):
    for j in range(a):
        out.append(i + 1)


out = np.array(out).reshape((H, W))


sign = 1
for li in out:
    print(*li[::sign])
    sign *= -1

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

def main():
    H, W = map(int, readline().rstrip().split())
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    res = [[-1] * W for _ in range(H)]
    ht, wt = 0, 0
    for i, a in enumerate(A):
        while a:
            res[ht][wt] = i+1
            a -= 1
            if (ht % 2 == 0 and wt == W-1) or (ht % 2 == 1 and wt == 0):
                ht += 1 
            elif  ht % 2 == 0:
                wt += 1
            else:
                wt -= 1
                
    for l in res:
        print(*l, sep=' ')

if __name__ == '__main__':
    main()

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

for index,item in enumerate(a):
    for _ in range(item):
        aa.append(index+1)


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


i=0

for y in range(h):
    for x in range(w):
        
        if y%2==0:
            result[y][x]=aa[i]
        else:
            result[y][w-1-x]=aa[i]
        i+=1

for item in result:
    print(" ".join(map(str,item)))

Solution (Python):
h, w = map(int, input().split())
n = int(input())
colors = list(map(int, input().split()))
cmap = [(i+1,a) for i,a in enumerate(colors)]
campus=[0]*(h*w)

def printmtrx(campus):
    ts=""
    for idx,i in enumerate(campus):
        if((idx+1)%w==1):
            if idx==0:
                ts += str(i) + " "
            else:
                ts+="\n"+str(i)+" "
        else:
            if (idx+1)%w==0:
                ts += str(i)
            else:
                ts+=str(i)+" "
    print(ts)

def printmtrx2(campus):
    cnt=0
    for i in range(h):
        ts=""
        for j in range(w):
            if not j==0:
                ts+=" "
            ts+=str(campus[cnt])
            cnt+=1
        print(ts)




cnt=cmap[0][1]
idx=0
campusidx=0
direct=0
while cnt:
    
    
    
    campus[campusidx]=cmap[idx][0]
    cnt-=1
    if(cnt<1):
        idx+=1
        if(idx>=len(cmap)):
            break
        cnt=cmap[idx][1]
    campusidx+=1-2*direct
    if campusidx%w==0 and direct==0:
        campusidx+=w-1
        direct=1
    elif campusidx%w==w-1 and direct==1:
        campusidx+=w+1
        direct=0
printmtrx2(campus)

Solution (Python):
import numpy as np

def abc069_d():
    H, W = map(int, input().split())
    _ = int(input())
    A = list(map(int, input().split()))

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

    
    grid = np.array(flat, dtype=int).reshape((H, W))
    for i in range(H):
        if i % 2 == 0:
            print(*grid[i], sep=' ')
        else:
            print(*grid[i, ::-1], sep=' ')

abc069_d()

Solution (Python):
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
now = 0
grid = [0]*(H*W)

for i in range(N):
  for j in range(now,now+a[i]):
    grid[j] = i+1
  now += a[i]

reverse = 0

for k in range(0,H*W,W):
  if reverse:
    print(*grid[k+W-1:k-1:-1])
    reverse = 0
  else:
    print(*grid[k:k+W])
    reverse = 1

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 i in range(h):
    tar = ans[i * w:(i+1) * w]
    if i % 2 == 0:
        print(*tar)
    else:
        tar.reverse()
        print(*tar)

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

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


if w==1:
    for i in range(n):
        for j in range(a[i]):
            print(i+1)
    exit()



for z in range(n):
    count=0
    while count<a[z]:
       
        if jugh==0:
            ans[i][j]=z+1
            j+=1
            c=0
        elif jugh==2:
            if j==0:
                jugh=0
                c=1
                ans[i][j]=z+1
                j+=1
            else:
                
                jugh=1
                c=1
                
                ans[i][j]=z+1
                j-=1
        else:
            ans[i][j]=z+1
            j-=1
            c=0

        if j==w and c==0:
            i+=1
            j-=1
            jugh=2
        if j==-1 and c==0:
            i+=1
            j+=1
            jugh=2
            
        count+=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()))
s = []
for i in range(1,N+1):
    for j in range(a[i-1]):
        s.append(i)

num = 0
for i in range(H):
    tmp = []
    for j in range(W):
        tmp.append(s[num])
        num += 1
    
    if i%2 == 1:
        tmp.reverse()
    print(*tmp)