Map

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

The 2D map of the world has the shape of a matrix with mm lines and nn columns. On this map, the countries are labelled with numbers 1,2,3,1, 2, 3, \dots. The countries have the shape of a square with the side 11 or a rectangle made of two adjacent squares with the side 11. There can be only one superpower, a country which is made of 33 adjacent squares of side 11. Two countries can be considered neighbours if they have at least a common side.

In the scheme on the right, we have a 4×54 \times 5 sized map, which contains 1111 countries (the country 11 is a superpower). Our purpose is to paint the countries on the map, so that each country should have a different colour from all its neighbours. A possible colouring is presented in the scheme on the right.

Task

Paint the countries on the map in maximum four colours, codified with 11, 22, 33, 44, so that two neighbouring countries should have different colours.

Input data

The first line contains the values of mm and nn separated by a space, representing the number of lines and the number of columns of the map. Each of the following mm lines contains nn natural numbers different from zero separated by one or more spaces, and together, they form the map of the world, with countries counted 1,2,3,1, 2, 3, \dots.

Output data

A matrix with mm lines and nn columns will be displayed, containing a possible painting of the map, as it is defined above. The numbers on a line will be separated from each other by a space.

Constraints and clarifications

  • 2m,n1 0002 \leq m, n \leq 1 \ 000
  • Any correct solution is accepted.
  • A valid painting can contain 44 or fewer colours.
  • The test cases are not the same as the ones used in the contest, so the scores might be slightly different from these obtained in the real contest.
# Points Constraints
0 0 Examples.
1 25 m,n10m, n \leq 10 and no superpower exists.
2 15 m,n11m, n \leq 11 and there exists a superpower.
3 30 m,n1 000m, n \leq 1 \ 000 and no superpower exists.
4 30 m,n1 000m, n \leq 1 \ 000 and there exists a superpower.

Example 1

stdin

4 5
1 1 1 2 9
3 3 4 2 9
5 6 4 7 10
5 6 8 8 11

stdout

3 3 3 4 3
1 1 2 4 3
4 3 2 3 4
4 3 4 4 1

Explanation

The countries 33 and 1111 are painted using colour 11.
The country 44 is painted using colour 22.
The countries 11, 66, 77 and 99 are painted using colour 33.
The countries 22, 55, 88 and 1010 are painted using colour 44.

Example 2

stdin

3 3
1 2 3
5 4 9
6 8 7

stdout

1 2 1
2 1 2
1 2 1

Explanation

All the countries are squares with the side 11. In this case, all the countries can be painted using only two colours.

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