You are playing the game Pacman. You are in a labyrinth with some monsters. You need to reach one of the boundary squares of the labyrinth without sharing a square with a monster.
On each move, you move in some direction (up, left, right, or down) and the monsters move in some direction as well.
If it’s possible to get out of the labyrinth safely, you should print the path that you can follow. The strategy needs to work even if the monsters know your plan.
Input
The first line of the input contains two integers h and w (1 ≤ h, w ≤ 1000) the height and the width of the labyrinth.
The next h lines contain w symbols describing the labyrinth:
. - floor
# - wall
M - monster
Y - your initial position
Output
The first line of the output should contain the number of steps to get out of the maze, and Impossible if it’s not possible to do so.
If it’s possible, the next line should contain any valid path to do so.