E. Pipes
Cossack Vus aspired to become the president of Potokolandia. To achieve this, he needed to perform a good deed for the citizens, thereby enhancing his popularity. He chose to repair the country's water supply system. This system is underground and is divided into equal square sections, forming a grid of n * m. The sections are numbered from top to bottom, 1 to n, and from left to right, 1 to m. Each section can either be empty (represented by the symbol 0) or contain one of 6 types of pipes:
The water supply system is considered closed if every pipe's ends are connected to the ends of other pipes. Recently, you were appointed as Cossack Vus's deputy for water supply issues. You have the ability to rotate any pipe by angles that are multiples of 90◦. Your task is to make the water supply system closed through rotations or to determine if it is impossible.
Input Format
The first line contains three integers n, m, and g (1 ⩽ n, m ⩽ 400, 0 ⩽ g ⩽ 8) — the dimensions of the grid and the group number, respectively.
Each of the following n lines contains m integers a[i]
; 1; a[i]
; 2; ..., a[i]
;m (0 ⩽ a[i]
;j ⩽ 6)—indicating the type of pipe located in the cell with coordinates (i, j).
Output Format
Print NO if it is impossible to rotate the pipes to form a closed system. Otherwise, print YES, followed by n lines with m numbers each, describing the closed system formed by the rotations, in the format described above.
Examples
Note
Illustration for test examples: initial and closed (if it exists) state:
Evaluation Criteria:
(7 points) 1 ⩽ n, m ⩽ 3;
(9 points) 1 ⩽ n, m ⩽ 400; up to 4 corner pipes;
(12 points) 1 ⩽ n, m ⩽ 400; up to 8 corner pipes;
(13 points) 1 ⩽ n ⩽ 400; m = 2;
(13 points) 1 ⩽ n, m ⩽ 400; if a solution exists, then in at least one of them each closed loop consists of 4 corner pipes and any number of straight pipes;
(14 points) 1 ⩽ n ⩽ 400; m = 4;
(15 points) 1 ⩽ n, m ⩽ 50;
(17 points) without additional restrictions.