tetris

Time limit: 1s Memory limit: 256MB Input: Output:

Tommaso is one of the best Tetris players in the world. Today he became bored of playing the game and decided to create a different version. He wants to fill a N×MN \times M grid with the standard Tetris pieces.

The pieces can be rotated, but they cannot overlap or go outside the grid. Help Tommaso by writing a program that, given the size of the grid, finds a way to completely fill it with tetris pieces.

Input data

The first line contains the integers NN and MM.

Output data

If it is not possible to fill the grid, you need to write a single line with the number 1-1. Otherwise on the first line you need to write the number KK of pieces used to fill the grid.

Then, you need to write NN lines with MM numbers each, where the jj-th number of the ii-th line is the number of the piece used to fill the cell (i,j)(i,j). The different pieces must be numbered from 00 to K1K-1.

Constraints and Clarifications

  • 1N5001 \le N \le 500.
  • 1M5001 \le M \le 500.
  • If there are multiple solutions, you can print any of them.
  • Tommaso has an infinite amount of pieces of each type.
# Score Restrictions
1 0 Examples.
2 20 N,M4N,M \le 4.
3 30 N,M50N,M \le 50.
4 50 No additional limitations.

Example 1

stdin

2 3

stdout

-1

Explanation

In the first sample case there is no way to completely fill a 2×32 \times 3 grid.

Example 2

stdin

4 3

stdout

3
0 0 0
1 2 0 
1 2 2 
1 1 2 

Explanation

In the second sample case a possible way to fill the grid is shown in the image below:

Log in or sign up to be able to send submissions!