Mathematician Andris likes different puzzles and one of his favorites
is covered box of mirrors. If we look at the horizontal cross-section of
such a box, we can see that its basement contains n*m square cells
(n rows, and m columns). In each cell there can be placed
mirror which is oriented diagonally from lower left corner to upper right
corner. Both sides of the mirror reflect light. At the box edges opposite
to each cell row or column there is a gap through which you can light a
beam into box or the beam can come out of the box. Through each gap you
can light the beam in only one direction--perpendicular to the edge containing
the gap. Therefore, beam reflecting from mirror changes its direction by
90o. When the beam goes through empty cells, its direction doesn't
change. Gaps are numbered consecutively from 1 to 2*(n+m), around
the box, counter-clockwise, starting from the gap on the left side of the
upper left cell and going downwards. Since arrangement of mirrors in the
box is not visible, the only way to determine it is by lighting beams in
some gaps and watching where light comes out.
2 3 9 7 10 8 6 5 2 4 1 3correct answer in file box.out
0 1 0 0 1 1