406477: GYM102419 J Jaber The policeman
Description
Jaber is a policeman of a city that can be described by a grid of size $$$n \times m$$$, where every cell in that grid contains a house of one of the civilians.
At night every person in the city should go sleep and should turn the lights of their house off.
As a policeman Jaber should check the lights of every house in that city.
Jaber checks every row and every column in that city exactly once, in the order written on a paper with Jaber.
Every time Jaber checks a row or a column, he counts the number of houses that has their lights turned on. If he found more than one house with lights turned on he becomes sad.
Also every time he checks a row or a column, he makes sure that every house in that row or column will turn off their lights.
Ayoub doesn't remember exactly the description of the city, but he remembers in every row the number of houses that will have their lights on.
Ayoub wants to know if it is possible to have a city with that description and has at least one correct order.
InputThe first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \leq n , m \leq 1000)$$$.
The second line contains $$$n$$$ integers, the $$$i_{th}$$$ one is $$$a_i$$$ $$$(0 \leq a_i \leq m)$$$, which is the number of houses that will have their lights on in the $$$i_{th}$$$ row.
OutputIf there is no possible answer print NO on a line, otherwise print YES.
if there is an answer you should print $$$n$$$ lines, the $$$i_{th}$$$ line should contain $$$m$$$ characters, the $$$j_{th}$$$ character should be 1 if the house in the $$$i_{th}$$$ row $$$j_{th}$$$ column has their lights on, and 0 otherwise.
make sure that the number of 1's in the $$$i_{th}$$$ row is equal to $$$a_i$$$.
then you should print $$$n + m$$$ lines, which is a correct order of rows and columns that won't make Jaber sad.
in every line you should print
row $$$x$$$ or col $$$x$$$.
make sure that every row and column appears exactly once.
ExamplesInput4 4 1 0 0 0Output
YES 1000 0000 0000 0000 row 1 col 1 row 2 col 2 row 3 col 3 row 4 col 4Input
4 4 2 1 1 1Output
YES 1010 1000 0100 0001 col 3 row 1 col 1 row 2 col 2 row 3 row 4 col 4