A knight is on a chess board. The knight can only move following the usual chess rules (that is, moving two units in one coordinate, and one unit in the other coordinate, for a total of up to eight possible movements), as long as the knight does not leave the board, nor it visits any forbidden cell. What is the minimum number of steps to reach a carrot?
Input consists of several cases. Each case begins with the number of
rows
and the number of columns
of the board, both between 3 and 200. Follow
rows with
characters each. A ‘p’ indicates a carrot, an
‘X’ indicates a forbidden cell, and a period indicates a
free cell. Every case ends with the initial position (row and column) of
the knight. The left-most cell of the first row is (1, 1). The initial
cell is always free.
For every case, if the knight can reach some carrot, print the
minimum number of steps. Otherwise, print “no”.
Input
3 3 ... ..p ... 1 1 4 6 XXXXXX X..XXX XXXX.X pX.XXX 2 3 3 4 XXXX XXX. XXXX 2 4 3 4 ppXX p.pp ppp. 3 4
Output
1 4 no no