jiahuimbzuai/CoQuIR huggingface dataset:
//  [typescript]
import * as fs from 'fs';

namespace AtCoder.abc132 {

    export class ProgramB {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         * 5
         * 1 3 5 4 2
         * out
         * 2
         */
        main(this: ProgramB): void {

            const n = parseInt(this.args[0]);
            const p: number[] = this.args[1].split(' ').map(Number);
            const ans: number = p.reduce((acc: number, cur: number, idx: number) => {
                if (idx === 0) return acc;
                if (idx === n - 1) return acc;
                if (p[idx] > p[idx - 1] && p[idx] < p[idx + 1]) return acc + 1;
                if (p[idx] < p[idx - 1] && p[idx] > p[idx + 1]) return acc + 1;
                return acc;
            }, 0);

            console.log(ans);

        }
    }
}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg = new AtCoder.abc132.ProgramB(args);
prg.main();
//  [typescript]
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { n: number, p: number[] } => {
  const n = +lines[0]
  const p = lines[1].split(' ').map(line => +line)
  const obj = { n, p }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { n, p } = parseLines(lines)
  let count = 0
  for (let i = 0; i < n - 2; i++) {
    let a = p.slice(i, 3 + i)
    a.sort((b, c) => b - c)
    if (a[1] === p[i+1]) {
      count += 1
    }
  }
  return `${count}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}
//  [typescript]
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");

const n: number = +input[0];
const p: number[] = input[1].split(' ').map((x: string): number => +x);

let ans: number = 0;
for(let i = 1; i < n-1; i++){
    if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])){
        ans++
    }
}
console.log(ans);
//  [python]
from numba import jit


@jit
def solve(X, Y, Z):
    while X >= 0:
        if 2 * X + 4 * Z == Y:
            return True
        elif 2 * X + 4 * Z < Y:
            X -= 1
            Z += 1
        else:
            return False
    return False


def main():
    X, Y = map(int, input().split())
    Z = 0

    if solve(X, Y, Z):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
//  [python]
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    x, y = LI()
    for i in range(x+1):
        j = x - i
        if i * 2 + j * 4 == y:
            print("Yes")
            return
    print("No")
    return

main()
//  [java]
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int X = s.nextInt();
		int Y = s.nextInt();
		boolean juge = false;
		for(int x=0; x<=X; x++) {
			for(int y=0; y<=X; y++) {
				if(x+y == X && 2*x + 4*y == Y) {
					juge =true; break;
				}
			}
			if(juge) {break;}
		}
		if(juge) {System.out.println("Yes");}
		else {System.out.println("No");}
	}

}
//  [java]
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x, y;
        x = in.nextInt(); y = in.nextInt();
        if (y % 2 != 0) {
            System.out.println("No");
        } else {
            if (y >= 2 * x && y <= 4 * x) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}
//  [java]
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int Y = sc.nextInt();

        System.out.println(solve(X, Y) ? YES : NO);
    }

    private static boolean solve(int X, int Y) {
        if (2 * X <= Y && Y <= 4*X && Y%2 == 0) return true;

        return false;
    }
}
//  [cpp]
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

bool isSolvable(int x, int y){
    if(y%2!=0)return false;
    if(x==0 && y==0)return true;
    if(y<0)return false;
    if(x<0 && y>=0)return false;
    if(x>=y)return false;
    return isSolvable(x-1,y-2)||isSolvable(x-1,y-4);
}

void solve(){
    int x, y;
    cin>>x>>y;
    bool flag=isSolvable(x,y);
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}
//  [cpp]
#include<iostream>
using namespace std;
int X ,Y;

bool dfs(int i,int sum){
    if(i == X) return sum == Y;
    if(dfs(i + 1, sum+2)) return true;
    if(dfs(i + 1, sum+4)) return true;

    return false;
}

int main(){
    cin >> X >> Y;
    if(Y >= X*2 && Y <= X*4 && Y % 2 == 0){
        if(dfs(0,0)) cout << "Yes";
    }
    else cout << "No";
}
//  [c]
#include<stdio.h>

int main(void){

    double X, Y;
    double a, b;

    scanf("%lf %lf", &X, &Y);
    a = (Y-2*X)/2;
    b = (4*X-Y)/2;

    if((int)a==a && (int)b==b && a>=0 && b>=0){
        printf("Yes");
    }else{
        printf("No");
    }


    return 0;
}
//  [c]
#include<stdio.h>
void main()
{
int n,c,i,j,s=0;
scanf("%d",&n);
scanf("%d",&c);
  i=0;
  j=n;
while(i<=n && j>=0)
{
	s = 2*i+4*j;
  	if(s==c){
      printf("Yes");
  	break;
      
    }
  i++;
  j--;
}
if(i>n)
  printf("No");
}
//  [c]
#include <stdio.h>
int main() {
 	int count = 0, x, y;
 	scanf("%d %d", &x, &y);

	for (int i = 0; i < y; i++) {
		for (int j = 0; j < y; j++) {
			if (i * 2 + j * 4 == y && i + j == x) {
				count += 1;
			}
		}
	}
  	
  	if (count >= 1) {
      	printf("Yes");
    }
  	else {
      	printf("No");
    }
  
  	return 0;
}
//  [javascript]
function Main(input) {
  const setting = input.trim().split(' ')
  const animal_sum = setting[0] - 0
  const leg_sum = setting[1] - 0

  let answer = false

  for (let crane = 0; crane <= animal_sum; crane++) {
    let turtle = animal_sum - crane
    if (((crane * 2) + (turtle * 4)) === leg_sum) {
      answer = true
      break
    }
  }

  if (answer) {
    console.log('Yes')
  } else {
    console.log('No')
  }
  }

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";

const main = (arg) => {
  const array = arg.trim().split(" ");
  const X = parseInt(array[0], 10);
  const Y = parseInt(array[1], 10);
  if (X * 4 < Y) {
    console.log("No");
    return;
  }
  for (let i = 0; i <= X; i++) {
    let kameLegs = i * 2;
    let toriLegs = (X - i) * 4;
    let tolalLrgs = kameLegs + toriLegs;
    if (tolalLrgs == Y) {
      console.log("Yes");
      return;
    }
  }
  console.log("No");
};
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const main = input => {
    const [X, Y] = input.trim().split(' ').map(x => parseInt(x));
    for (let i = 0; i <= X; i++) {
        const tsuru = i
        const kame = X - i
        if (tsuru * 2 + kame * 4 === Y) {
            console.log('Yes')
            return
        }
    }
    console.log('No')
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e10
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)

	x, y := nextInt(), nextInt()

	for i := 0; i <= x; i++ {
		if i*4 + 2*(x-i) == y {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

func intSlicePrint(el ...int) {
	first := true
	for _, v := range el {
		if v < 0 {
			continue
		}
		if !first {
			fmt.Printf(" ")
		}
		fmt.Printf("%v", v)
		first = false
	}
	fmt.Println("")
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
//  [ruby]
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
x,y = gets.chomp.split.map(&:to_i)

if y.odd?
  puts 'No'
else
  b = y / 2 - x
  if b < 0
    puts 'No'
  else
    a = x - b
    if a < 0
      puts 'No'
    else
      puts 'Yes'
    end
  end
end
//  [ruby]
require 'pp'

x, y = gets.split.map(&:to_i)

0.upto(100) do |i|
    0.upto(100) do |j|
        next if i + j != x 

        if i * 2 + j * 4 == y
            puts "Yes"
            exit 0
        end
    end
end

puts "No"
//  [ruby]
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
x, y = gets_i_list

0.upto(x) do |a|
  b = x - a
  if (2 * a + 4 * b) == y
    puts "Yes"
    exit
  end
end

puts "No"
//  [swift]
import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

let x = Int(split[0])!
let y = Int(split[1])!
let a = y - 2*x

if(a % 2 == 0 && a >= 0 && a <= 2*x){
  print("Yes")
}else{
  print("No")
}
//  [swift]
import Foundation

func readInts () -> [Int]{
   return readLine()!.split(separator: " ").map { Int($0)! }
}

func main(){
    let xy = readInts()
    for i in 0...xy[0] {
        if i*2 + (xy[0]-i)*4 == xy[1]{
            print("Yes")
            return
        }
    }
    print("No")
}

main()
//  [swift]
import Foundation

let values = readLine()!.components(separatedBy: " ").map{Int($0)!}
assert(values.count == 2)
let X = values[0]
let Y = values[1]

for turu in 0...X {
    let kame = X - turu
    let legs = turu * 2 + kame * 4
    if legs == Y {
        print("Yes")
        exit(0)
    }
}

print("No")
//  [typescript]
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let [x, y] = lines[0].split(' ').map( _ => parseInt(_))

    if(y % 2 == 1) {
        console.log('No')
    } else {
        if(x * 4 >= y && 2 * x <= y) {
            console.log('Yes')
        } else {
            console.log('No')
        }
    }

});
//  [typescript]
import * as fs from "fs";

function main() {
    const [x, y] = fs.readFileSync("/dev/stdin", "utf8").split(" ").map(i => parseInt(i));


    for (let i = 0; i <= 100; i++) {
        for (let j = 0; j <= 100; j++) {
            if ((i + j == x ) && (i * 2 + j * 4 == y)) {
                console.log("Yes");
                return
            }

        }
    }
    console.log("No");
}

main();
//  [python]
import sys


def main():
    args = sys.stdin.readline().split()
    H = int(args[0])
    W = int(args[1])
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = list(map(int, input().split()))

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

    switch = True
    num_of_cells = 0
    color_num = 1
    index = 0
    for row in range(H):
        for col in range(W):
            if switch:
                color_matrix[row][col] = color_num
            else:
                color_matrix[row][(W - 1) - col] = color_num
            num_of_cells += 1
            if num_of_cells == A[index]:
                num_of_cells = 0
                color_num += 1
                index += 1

        switch = not switch

    # answer
    for array in color_matrix:
        print(' '.join(map(str, array)))

main()
//  [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()
//  [python]
def d_grid_coloring():
    H, W = [int(i) for i in input().split()]
    N = int(input())
    A = [int(i) for i in input().split()]

    # 方針: 数字を「うなぎ」のように並べればそれが条件を満たす
    # a) 1から順にその数字をそれで塗る回数だけ書き込む
    # b) W 個ごとに分割し，奇数番目は逆にする
    tmp = []
    for k, a in enumerate(A, 1):
        tmp.extend([k] * a)
    ans = [tmp[r * W:(r + 1) * W][::(-1)**r] for r in range(H)]
    return '\n'.join(' '.join(map(str, row)) for row in ans)

print(d_grid_coloring())
//  [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
#print(colored)
for i in range(h):
    print(*colored[i])
//  [python]
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))

c=[[0 for i in range(W)]for j in range(H)]
for k in range(N):
    count=0
    flag=True
    for i in range(H):
        for j in range(W):
            if i%2==0:
                if c[i][j]==0:
                    if count!=a[k]:
                        c[i][j]=k+1
                        count+=1
                    else:
                        flag=False
                        break
            else:
                if c[i][W-1-j]==0:
                    if count!=a[k]:
                        c[i][W-1-j]=k+1
                        count+=1
                    else:
                        flag=False
                        break
        if not flag:
            break
for i in range(H):
    print(*c[i])
//  [python]
#!/usr/bin/env python3
#ABC69 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

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

ans = [[None]*w for _ in range(h)]
for i in range(h):
    if i % 2:
        for j in range(w)[::-1]:
            for k in range(n):
                if a[k] > 0:
                    ans[i][j] = k+1
                    a[k] -= 1
                    break
    else:
        for j in range(w):
            for k in range(n):
                if a[k] > 0:
                    ans[i][j] = k+1
                    a[k] -= 1
                    break
for i in range(h):
    print(*ans[i])
//  [java]
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int N = in.nextInt();
            int[] colors = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                colors[i] = in.nextInt();
            }
            int[][] ans = new int[H][W];
            int i = 0, j = 0;
            int incj = 1;
            for (int k = 1; k <= N; k++) {
                if (colors[k] > 0) {
                    while (colors[k]-- > 0) {
                        ans[i][j] = k;
                        j += incj;
                        if (j == -1 || j == W) i = (i + 1) % H;
                        if (j == W) {
                            j--;
                            incj = -1;
                        } else if (j == -1) {
                            j++;
                            incj = 1;
                        }
                    }
                }
            }
            for (i = 0; i < H; i++) {
                for (j = 0; j < W; j++) {
                    if (j > 0) out.print(" ");
                    out.print(ans[i][j]);
                }
                out.println();
            }
        }

    }

    static class InputReader {
        private int lenbuf = 0;
        private int ptrbuf = 0;
        private InputStream in;
        private byte[] inbuf = new byte[1024];

        public InputReader(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}
//  [java]
import java.util.Scanner;

public class Main {

	static int h, w, n, a[];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		h = sc.nextInt();
		w = sc.nextInt();
		n = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		sc.close();

		int ans[][];
		ans = new int[h][w];
		int key = 0, max;

		for (int i = 0; i < h; ++i) {
			max = a[key];
			for (int j = 0; j < w; ++j) {
				if (i % 2 == 0) {
					if (max > j) {
						ans[i][j] = key + 1;
						a[key]--;
					} else {
						++key;
						max = a[key] + j;
						ans[i][j] = key + 1;
						a[key]--;
					}
				} else {
					if (max > j) {
						ans[i][w - j - 1] = key + 1;
						a[key]--;
					} else {
						++key;
						max = a[key] + j;
						ans[i][w - j - 1] = key + 1;
						a[key]--;
					}
				}
			}
		}

		for (int i = 0; i < h; ++i) {
			for (int j : ans[i])
				System.out.print(j + " ");
			System.out.println();
		}
	}

}
//  [java]
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = 0, M = 0;
		N = scan.nextInt();
		M = scan.nextInt();

		int K = 0;
		int[] arr = new int[100000];
		K = scan.nextInt();
		int l = 0;
		for (int i = 0; i < K; i++) {
			arr[i] = scan.nextInt();
		}

		int[][] A = new int[N][M];
		int flag = 1;
		for (int i = 0; i < N; i++) {
			if (flag == 1) {
				for (int j = M - 1; j >= 0; j--) {
					if (arr[l] == 0) {
						l++;
						arr[l]--;
					} else {
						arr[l]--;
					}
					A[i][j] = l + 1;
				}
			} else {
				for (int j = 0; j < M; j++) {
					if (arr[l] == 0) {
						l++;
						arr[l]--;
					} else {
						arr[l]--;
					}
					A[i][j] = l + 1;
				}
			}

			flag *= -1;
		}
		flag = 1;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				System.out.print(A[i][j] + " ");
			}
			System.out.println();
		}

	}

}
//  [java]
import java.util.*;
 
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int n = sc.nextInt();
    int a[] = new int[n];
    int x = 0;
 
    for(int i=0;i<n;i++){
      a[i] = sc.nextInt();
    }
    int answer1[] = new int[h*w];
    for(int i=0;i<n;i++){
      for(int j=0;j<a[i];j++){
        answer1[x] = i+1;
        x = x + 1;
      }
    }
    x = 0;
    int answer2[][] = new int[h][w];
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(i%2==0){
          answer2[i][j] = answer1[x];
          x = x + 1;
        }else{
          answer2[i][w-1-j] = answer1[x];
          x = x + 1;
        }
      }
    }
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          System.out.print(answer2[i][j] + " ");
        }
        System.out.println("");
      }
 
  }
}
//  [cpp]
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <tuple>

using namespace std;

int arr[10010];
int res[110][110];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int h, w, n, p, c, i, j;
    scanf("%d%d%d", &h, &w, &n);
    for(i = 1; i<=n; i++)
        scanf("%d", &arr[i]);

    p = 1;
    c = 0;
    for(i = 0; i<h; i++)
    {
        if(i%2 == 0)
        {
            for(j = 0; j<w; j++)
            {
                res[i][j] = p;
                c++;
                if(c == arr[p])
                {
                    p++;
                    c = 0;
                }
            }
        }
        else
        {
            for(j = w-1; j>=0; j--)
            {
                res[i][j] = p;
                c++;
                if(c == arr[p])
                {
                    p++;
                    c = 0;
                }
            }
        }
    }

    for(i = 0; i<h; i++)
    {
        for(j = 0; j<w; j++)
            printf("%d ", res[i][j]);
        printf("\n");
    }

    return 0;
}
//  [cpp]
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX],b[200][200];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll h,w,n;
	cin>>h>>w>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	ll x=1,y=1;
	for(int i=0;i<n;i++){
		while(a[i]>0){
			if(x%2==1){
				while(a[i]>0&&y<=w){
					a[i]--;
					b[x][y]=i;
					y++;
				}
			}
			if(y==w+1){
				x++;
				y=w;
			}
			if(x%2==0){
				while(a[i]>0&&y>0){
					a[i]--;
					b[x][y]=i;
					y--;
				}
			}
			if(y==0){
				x++;
				y=1;
			}
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)
			cout<<b[i][j]+1<<" ";
		cout<<"\n";
	}
	return 0;
}
//  [cpp]
#include<iostream>
#include<string>
using namespace std;
int a[10010];
int c[150][150];
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    int H,W,N;
    cin >> H;
    cin >> W;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int count=1,color=1;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(i%2==0){
                c[i][j]=color;
            }
            else{
                c[i][W-1-j]=color;
            }
            if(count==a[color-1]){
                count=1;
                color++;
            }
            else{
                count++;
            }
        }
    }

    for(int i=0;i<H;i++){
        cout << c[i][0];
        for(int j=1;j<W;j++){
            cout << " "<< c[i][j];
        }
        cout << "\n";
    }
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int H,W,N;
  cin >> H >> W >> N;
  vector<int> A(N);
  vector<int> B(N);
  int sum = 0;
  REP(i, N){
    cin >> A[i];
    sum+=A[i];
    B[i]=sum;
  }
  
  vector<vector<int>> ans(H,vector<int> (W));
  int cnt = 0;
  REP(i,H){
    if(i%2==0){
      REP(j,W){
        if(cnt<=B[0]-1){
          ans.at(i).at(j)=1;
        }
        REP(k,N-1){
          if(cnt>B[k]-1&&cnt<=B[k+1]-1){
            ans.at(i).at(j)=k+2;
          }
        }
        cnt++;
      }
    }else{
      REPR(j,W-1){
        if(cnt<=B[0]-1){
          ans.at(i).at(j)=1;
        }
        REP(k,N-1){
          if(cnt>B[k]-1&&cnt<=B[k+1]-1){
            ans.at(i).at(j)=k+2;
          }
        }
        cnt++;
      }
    }
  }

  REP(i,H){
    REP(j,W){
      if(j!=W-1){
        cout << ans.at(i).at(j) <<" ";
      }else{
        cout << ans.at(i).at(j);
      }
    }
    cout << endl;
  }
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int h, w, n;
  int a[MAX];
  scanf("%d%d%d", &h, &w, &n);
  rep(i, 0, n) scanf("%d", &a[i]);

  int now = 0;
  int line[101];
  rep(hi, 0, h) {
    if ( hi % 2 == 0 ) {
      for ( int wi = 0; wi < w; wi++ ) {
        line[wi] = now+1;
        a[now]--;
        if ( a[now] == 0 ) now++;
      }
    } else {
      for ( int wi = w-1; wi >= 0; wi-- ) {
        line[wi] = now+1;
        a[now]--;
        if ( a[now] == 0 ) now++;
      }
    }
    rep(wi, 0, w) {
      printf("%d ", line[wi]);
    }
    printf("\n");
  }
  return 0;
}
//  [c]
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int h, w, n, i, j;
	int d[10000];
	scanf("%d%d%d", &h, &w, &n);
	j=0;
	for(i=1; i<=n; i++){
		int a;
		scanf("%d", &a);
		for(a+=j; j<a; j++){
			d[j]=i;
		}
	}
	for(i=0; i<h; i++){
		if(i&1){
			for(j=0; j<w; j++){
				printf("%d ", d[i*w+j]);
			}
		}else{
			for(j=0; j<w; j++){
				printf("%d ", d[i*w+(w-j-1)]);
			}
		}
		putchar(10);
	}
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define ROW_MAX 100
#define COL_MAX 100
#define NUM_MAX (ROW_MAX*COL_MAX)

int main(void) {
    int row, col;
    get_int2(&row, &col);
    int num = get_int();
    // 1-indexed
    static int arr[NUM_MAX];
    fget_array(&arr[1], num);
    int aidx = 1;

    int i, j;
    int norm[NUM_MAX];
    int rev[NUM_MAX];
    for(i = 0; i < col; i++) {
        norm[i] = i;
        rev[i] = col-i-1;
    }
    static int map[ROW_MAX][COL_MAX];
    for(i = 0; i < row; i++) {
        int *order = (i%2==0) ? norm : rev;
        for(j = 0; j < col; j++) {
            if(!arr[aidx]) aidx++;
            int jdx = order[j];
            map[i][jdx] = aidx;
            arr[aidx]--;
        }
    }

    // presentation
    for(i = 0; i < row; i++) {
        for(j = 0; j < col; j++) {
            printf("%d%c", map[i][j], j==(col-1) ? '\n' : ' ');
        }
    }
    return 0;
}
//  [c]

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
	int H,W;
	scanf("%d%d",&H,&W);
	int *a;
	a = (int*)malloc(H*W*sizeof(int));
	int num=0;
	int n=0;
	int y=0;
	int *b;
	b = (int*)malloc((H*W)*sizeof(int));


	scanf("%d",&num);
	for(int i=0;i<num;i++){
		scanf("%d",&a[i]);
	}

	for(int u=0;u<num;u++){
		y = a[u];
		for(int m=0;m<y;m++){
			b[n] = u+1;
			n++;
		}
	}
	int k=0,Line=0;
	while(Line<H){
		if(Line%2==0){
			k=Line*W;
			for(int i=0;i<W;i++){
				printf("%d ",b[k+i]);
				fflush(0);	/*バッファにためている分を出力*/
			}
		}else{
			k=Line*W+W-1;
			for(int i=0;i<W;i++){
				printf("%d ",b[k-i]);
				fflush(0);	/*バッファにためている分を出力*/
			}
		}
	printf("\n");
	Line++;
	}


	free(a);
	free(b);

	return 0;
}
//  [c]
#include<stdio.h>
int main(){
  int h,w,n,i,j,num=0;
  scanf("%d%d%d",&h,&w,&n);
  int a,mass[h+1][w+1];
  for(i=0;i<n;i++){
    scanf("%d",&a);
    while(a!=0){
      if((num/w)%2==0)
        mass[num/w][num%w]=i+1;
      else
        mass[num/w][w-1-num%w]=i+1;
      a--;
      num++;
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++)
      printf("%d ",mass[i][j]);
    puts("");
  }
  return 0;
}
//  [c]
#include <stdio.h>
int main(){
	int	h, w, n, a, idx=0;
	int	x[10201]={0}, col[101][101]={0};
	scanf("%d %d %d", &h, &w, &n);

	for(int i=1; i<=n; i++){
		scanf("%d", &a);
		for(int j=0; j<a; j++){ x[idx+j]=i; }
		idx += a;
	}

	idx = 0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			col[i][j] = x[idx];
			idx++;
		}
	}
	
	for(int i=0; i<h; i++){
		if(i%2){
			for(int j=w-1; j>=0; j--){ printf("%d ", col[i][j]); }
          	printf("\n");
		}else{
			for(int j=  0; j< w; j++){ printf("%d ", col[i][j]); }
          	printf("\n");
		}
	}
	return 0;
}
//  [javascript]
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var H = myconv(input[0],4)[0];
  var W = myconv(input[0],4)[1];
  var N = myconv(input[1],1);
  var list = myconv(input[2],4);
  
  var output = new Array(H);
  for(var i = 0; i < H; i++){
    output[i] = new Array(W);
  }
  
  var getNo = 1;
  for(var i = 0; i < H; i++){
    if(i % 2 == 0){
    for(var j = 0; j < W; j++){
      if(list[getNo-1] == 0){
        getNo++;
      }
      list[getNo-1]--;
      output[i][j] = getNo;
    }
  	}else{
    for(var j = W-1; j >= 0; j--){
      if(list[getNo-1] == 0){
        getNo++;
      }
      list[getNo-1]--;
      output[i][j] = getNo;
    }  
    }
  }
  for(var i = 0; i < H; i++){
    output[i] = output[i].join(" ");
  }
  myout(output.join("\n"));
}

Main(myin());
//  [javascript]
function Main(input) {
  input = input.split("\n");
  var h = parseInt(input[0].split(" ")[0]);
  var w = parseInt(input[0].split(" ")[1]);
  var n = parseInt(input[1]);
  tmp = input[2].split(" ");
  a= new Array();
  for(i=0;i<n;i++){
    var x = parseInt(tmp[i]);
    for(j=0;j<x;j++){
      a.push(i+1);
    }
  }
  var ans="";
  anssub=new Array(h).fill("");
  for(i=0;i<h;i++){
    anssub[i]=a[i*w];
    for(j=1;j<w;j++){
      if(i%2==0){
        anssub[i]=anssub[i]+" "+a[i*w+j];
      }else{
        anssub[i]=a[i*w+j]+" "+anssub[i];
      }
    }
    anssub[i]=anssub[i]+"\n";
    ans+=anssub[i];
  }
  if(ans.slice(-1)=="\n"){
  ans=ans.slice(0,-1);
  }
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  input = input.split("\n");
  var h = parseInt(input[0].split(" ")[0]);
  var w = parseInt(input[0].split(" ")[1]);
  var n = parseInt(input[1]);
  tmp = input[2].split(" ");
  a=new Array(n).fill(0);
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
  }
  var ans ="";
  d = new Array();
  for(i=0;i<n;i++){
    for(j=0;j<a[i];j++){
      d.push(i+1);
    }
  }
  for(i=0;i<h;i++){
    if(i%2!=1){
      for(j=0;j<w;j++){
        if(j%w!=w-1){
        ans+=d[i*w+j]+" ";
        }else{
        ans+=d[i*w+j]+"\n";
        }
      }
    }else{
      for(j=0;j<w;j++){
        if(j%w!=w-1){
        ans+=d[(i+1)*w-j-1]+" ";
        }else{
          ans+=d[(i+1)*w-j-1]+"\n";
        }
      }
    }
  }
  ans=ans.substr(0,ans.length-1);
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  input = input.split("\n");
  var h = parseInt(input[0].split(" ")[0]);
  var w = parseInt(input[0].split(" ")[1]);
  var n = parseInt(input[1]);
  tmp = input[2].split(" ");
  a=new Array(n).fill(0);
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
  }
  var ans ="";
  c = new Array(h).fill(0);
  for(i=0;i<h;i++){
    csub = new Array(w).fill(0);
    c[i]=csub;
  }
  d = new Array();
  for(i=0;i<n;i++){
    for(j=0;j<a[i];j++){
      d.push(i+1);
    }
  }
  for(i=0;i<h;i++){
    if(i%2!=1){
      for(j=0;j<w;j++){
        c[i][j]=d[i*w+j];
      }
    }else{
      for(j=0;j<w;j++){
        c[i][j]=d[(i+1)*w-j];
      }
    }
  }
  for(i=0;i<h;i++){
    if(i%2!=1){
      for(j=0;j<w;j++){
        if(j%w!=w-1){
        ans+=d[i*w+j]+" ";
        }else{
        ans+=d[i*w+j]+"\n";
        }
      }
    }else{
      for(j=0;j<w;j++){
        if(j%w!=w-1){
        ans+=d[(i+1)*w-j-1]+" ";
        }else{
          ans+=d[(i+1)*w-j-1]+"\n";
        }
      }
    }
  }
  ans=ans.substr(0,ans.length-1);
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	h, w, n := scanInt(), scanInt(), scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}

	ans := make([][]int, h)
	for i := range ans {
		ans[i] = make([]int, w)
	}

	x, y, d := -1, 0, 1
	for i, v := range a {
		for j := 0; j < v; j++ {
			if d == 1 {
				x++
				if x == w {
					x--
					y++
					d = -1
				}
			} else {
				x--
				if x == -1 {
					x++
					y++
					d = 1
				}
			}
			ans[y][x] = i + 1
		}
	}

	var wr = bufio.NewWriter(os.Stdout)
	for i := range ans {
		for j := range ans[i] {
			wr.WriteString(strconv.Itoa(ans[i][j]))
			if j < len(ans[i])-1 {
				wr.WriteString(" ")
			} else {
				wr.WriteString("\n")
			}
		}
	}
	wr.Flush()
}
//  [go]
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	H, W := sc.nextInt(), sc.nextInt()
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	G := make([][]int, H)
	for i := 0; i < H; i++ {
		G[i] = make([]int, W)
	}
	h, w := 0, 0
	rev := false
	for i := 0; i < N; i++ {
		for j := 0; j < A[i]; j++ {
			G[h][w] = i + 1
			if !rev {
				if w < W-1 {
					w++
				} else {
					h++
					rev = !rev
				}
			} else {
				if w > 0 {
					w--
				} else {
					h++
					rev = !rev
				}
			}
		}
	}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if j != 0 {
				fmt.Fprint(wtr, " ")
			}
			fmt.Fprint(wtr, G[i][j])
		}
		fmt.Fprintln(wtr)
	}
}
//  [go]
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Jan 10 09:47:06 2019
//
package main

import "fmt"

func main() {
	var H, W, N int
	fmt.Scan(&H, &W, &N)
	arr := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
	}

	board := make([][]int, H)
	for i := range board {
		board[i] = make([]int, W)
	}

	h, w := 0, 0
	for i := range arr {
		for arr[i] > 0 {
			board[h][w] = i + 1
			w++
			if w == W {
				h++
				w = 0
			}
			arr[i]--
		}
	}

	for i := range board {
		if i%2 == 0 {
			for j := range board[i] {
				if j != 0 {
					fmt.Print(" ")
				}
				fmt.Print(board[i][j])
			}
		} else {
			for j := len(board[i]) - 1; j >= 0; j-- {
				if j != len(board[i])-1 {
					fmt.Print(" ")
				}
				fmt.Print(board[i][j])
			}
		}
		fmt.Println()
	}
}
//  [go]
package main

import "fmt"

const maxn = 1e5 + 5

var (
	sto [maxn]int
	gra [105][105]int
)

func main() {
	var h, w int
	fmt.Scanf("%d %d\n", &h, &w)
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &sto[i])
	}
	cnt := 1
	for i := 1; i <= h; i++ {
		if i%2 == 0 {
			for j := 1; j <= w; j++ {
				if sto[cnt] > 0 {
					gra[i][j] = cnt
					sto[cnt]--
				} else if sto[cnt] == 0 {
					cnt++
					gra[i][j] = cnt
					sto[cnt]--
				}
			}
		} else {
			for j := w; j >= 1; j-- {
				if sto[cnt] > 0 {
					gra[i][j] = cnt
					sto[cnt]--
				} else if sto[cnt] == 0 {
					cnt++
					gra[i][j] = cnt
					sto[cnt]--
				}
			}
		}
	}
	for i := 1; i <= h; i++ {
		for j := 1; j <= w; j++ {
			if j != w {
				fmt.Printf("%d ", gra[i][j])
			} else {
				fmt.Printf("%d\n", gra[i][j])
			}
		}
	}
}
//  [go]
package main

import "fmt"

func main() {
	var h, w, n int
	fmt.Scan(&h, &w, &n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	grid := make([][]int, h)
	for i := range grid {
		grid[i] = make([]int, w)
	}

	idx := 0
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			for as[idx] == 0 {
				idx++
			}
			if y%2 == 0 {
				grid[y][x] = idx + 1
			} else {
				grid[y][w-1-x] = idx + 1
			}
			as[idx]--
		}
	}

	for y := range grid {
		for x := range grid[y] {
			if x == w-1 {
				fmt.Printf("%d\n", grid[y][x])
			} else {
				fmt.Printf("%d ", grid[y][x])
			}
		}
	}
}
//  [ruby]
h, w = gets.chomp.split(' ').map(&:to_i)
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
total = []

a.each_with_index do |num, index|
  num.times do
    total.push (index + 1).to_s
  end
end

h.times do |index|
  if index % 2 == 0
    print total.shift(w).join(' ')
    print "\n"
  else
    print total.shift(w).reverse.join(' ')
    print "\n"
  end
end
//  [ruby]
h, w = gets.split.map(&:to_i)
n = gets.to_i
nums = gets.split.map(&:to_i)
array = []
nums.each.with_index(1) { |num, i| num.times { array << i.to_s } }
sliced = array.each_slice(w).to_a
1.step(h - 1, 2) { |i| sliced[i].reverse! }
sliced.each { |row| puts row.join(" ") }
//  [ruby]
h,w = gets.chomp.split.map(&:to_i)
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

t = []
a.each_with_index do |v, i|
    v.times {t << i+1}
end

h.times do |i|
    if i % 2 == 0
        puts t[i*w, w].join(" ")
    else
        puts t[i*w, w].reverse.join(" ")
    end
end
//  [ruby]
h,w = gets.split.map(&:to_i)
n = gets.to_i
a = gets.split.map(&:to_i)

x = []
a.each_with_index do |e,i|
    x += [i+1] * e
end

h.times do |i|
    y = x[i*w,w]
    y.reverse! if i.odd?
    puts y.join(" ")
end
//  [ruby]
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

h, w = inp
n = inp[0]
a = inp
s  = []
a.each.with_index do |d,i|
  s += [(i+1)] * d
end
c = 0
ans = na2(h,w,"")
h.times do |i|
  w.times do |j|
    j=w-1-j if(i.even?)
    ans[i][j] = s[c]
    c += 1
  end
end
ans.each do |aa|
  puts aa.join(" ")
end
//  [ruby]
H,W=gets.split.map(&:to_i)
N=gets.to_i
a=gets.split.map(&:to_i)
n=0
r=Array.new(H){Array.new(W)}
H.times{|h|
    W.times{|w|
        if h%2==1
            w=W-1-w
        end
        r[h][w]=n+1
        a[n]-=1
        if a[n]==0
            n+=1
        end
    }
}
#warn r.inspect
puts r.map{|a|a*" "}*"\n"
//  [rust]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (h, w) = get!(usize, usize);
    let _n = get!(usize);

    let mut mm = vec![vec![0; w]; h];
    let mut i = 0;
    let mut j = 0;
    let mut d = 0;
    let mut c = 0;
    for a in get!(String).split_whitespace().map(|i| i.parse::<i32>().unwrap()) {
        c += 1;
        for _ in 0..a {
            mm[i][j] = c;
            match (d, j) {
                (0, _) if j+1 == w => { i += 1; d = 1; },
                (0, _) => j += 1,
                (_, _) if j == 0 => { i += 1; d = 0; },
                _ => j -= 1,
            }
        }
    }
    for line in mm.iter() {
        println!("{}", line.iter().map(ToString::to_string).collect::<Vec<_>>().join(" "));
    }
}
//  [rust]
use std::io::*;
// hは最終的に0未満になってる可能性があることに注意!

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans: Vec<Vec<usize>> = vec![vec![0; w]; h];
    let mut idx = 0;

    for i in 0..h {
        if i % 2 == 0 {
            for j in 0..w {
                ans[i][j] = idx + 1;
                a[idx] -= 1;
                if a[idx] == 0 {
                    idx += 1;
                }
            }
        } else {
            for j in (0..w).rev() {
                ans[i][j] = idx + 1;
                a[idx] -= 1;
                if a[idx] == 0 {
                    idx += 1;
                }
            }
        }
    }
    let mut out = Vec::new();

    for i in 0..h {
        for j in 0..w - 1 {
            write!(out, "{} ", ans[i][j]).ok();
        }
        writeln!(out, "{}", ans[i][w - 1]).ok();
    }
    stdout().write_all(&out).unwrap();
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        n: usize,
        a: [usize; n],
    }

    let v: Vec<_> = a
        .iter()
        .zip(1..)
        .flat_map(|(&c, i)| std::iter::repeat(i).take(c))
        .collect();

    let v: Vec<Vec<_>> = v
        .chunks(w)
        .zip([0, 1].iter().cycle())
        .map(|(x, &i)| {
            if i == 0 {
                x.iter().collect::<Vec<_>>()
            } else {
                x.iter().rev().collect::<Vec<_>>()
            }
        }).collect();

    v.iter()
        .map(|l| {
            println!(
                "{}",
                l.iter()
                    .map(|&x| x.to_string())
                    .collect::<Vec<_>>()
                    .join(" ")
            )
        }).count();
}
//  [rust]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		h: usize,
		w: usize,
		n: usize,
		a: [usize; n],
	}

	let mut v: Vec<Vec<usize>> = vec![vec![0; h]; w];
	let mut x = 1;
	let mut y = 0;
	for i in 0..n {
		for _j in 0..a[i] {
			if y % 2 == 0 {
				v[x-1][y] = i;
				x += 1;
				if x == w+1 {
					x = w;
					y += 1;
				}
			}
			else {
				v[x-1][y] = i;
				x -= 1;
				if x == 0 {
					x = 1;
					y += 1;
				}
			}
		}
	}
	for i in 0..h {
		for j in 0..w {
			print!("{} ", v[j][i]+1);
		}
		println!("");
	}
}