Color matrix
Given a field of size , consisting of rows and columns.
Kozak Vus wants to color the cells using the minimum number of colors. However, he wants to ensure that no two cells of the same color are exactly units apart in terms of Manhattan distance.
Recall that the Manhattan distance between two cells and is calculated as .
Determine the minimum number of colors needed to achieve this, and provide the colored field as output.
Input
The first line contains three integers , , (, ) — representing the number of rows, columns, and the specified Manhattan distance.
Output
On the first line, output the minimum number of colors required.
For each of the following lines, output numbers — representing the color numbers assigned to each cell in the table ().
If multiple valid colorings exist, any one of them can be provided.
Examples
Note
In the first example, positions (1,1) and (2,2) are both colored with 0, while positions (1,2) and (2,1) are colored with 1. The Manhattan distance between positions (1,1) and (1,2) is . Since , these two positions must have different colors. However, the distance between positions (1,2) and (2,1) is , allowing them to share the same color.
Scoring
( points): ;
( points): ;
( points): ;
( points): ;
( points): is odd;
( points): no additional constraints.