Under construction

Still being built. Things may change

Number Grid Filling

Time limit1sMemory limit128 MB

Summary
Construct an N by M grid so that absolute differences of all adjacent cell pairs form exactly the set 1..2NM-N-M with each value used once.
Level

Hard8 of 10

Topics
Math, Combinatorics, Matrix
Solved
No attempts yet

Problem

Fill an N x M grid with integers. Two cells are adjacent if they share an edge.

If you take the absolute differences between all adjacent pairs, the integers from 1 through 2NM - N - M must each appear exactly once.

Given N and M, output any grid that satisfies the condition.

Input

The first line contains two integers N and M. (1 <= N, M <= 1,000)

Output

Print the grid in N lines. Each line must contain M integers separated by spaces.

If there are multiple valid answers, print any one of them. Every cell value must be an integer from 1 through 2 x 10^9.

Examples2

  1. Example 1

    Input
    2 2
    
    Expected output
    3 4
    5 1
    
  2. Example 2

    Input
    2 3
    
    Expected output
    3 8 1
    1 2 5