The World Fighting Championship is being held in the Dragon Ball Z world This time there is a tournament being held on the plant YAKOOM. This planet has some special characteristics. All the participants are eager to know about the rules and various challenges they are going to face. One such participant is Krillin the bald disc master. He is one of the most powerful heroes of Dragon Ball Z and is a strong contender.
Krillin is your friend and you know he is not good at algorithmic tasks. One of your friend is the part of the group that decides on tasks and challenges of the competitions. Krillin is very good at martial arts and he can handle the fighting himself. However, being weak at algorithms he asks you for help.
You now seek your friend for help. In spirit of competition, your friend tried to maintain the dignity of the problem setter and told you about the question that will appear as a challenge but didn’t gave you the solution. The problem is that you are given a rectangular grid of R x C square tiles that are made of glass. Each tile either glows in white light or in black light. The black tile is the area of monsters and the white tile is a healing tile. The citizens of YAKOOM can only live on healing tiles and one citizen lives on only ONE tile. There are R x C citizens. You have the power to tap(flip) a black tile but while doing so you also flip the tile above it, to its left , right and down also. That is if you flip a black/white tile then one tile above it, one tile to its left and one tile to its right and down will also flip. If the tile is a black it will flip into a white tile, if it is a white tile it will flip into a black tile. All inner tiles have 4 neighbors, which means 5 tiles are flipped over when tapped. Border tiles have less neighbours.
Now the catchy part is you have to make the grid with all white tiles so that all villagers can survive and solve this in minimum number of steps to ensure that no other participant can win the competition against Krillin. Help Krillin in solving this problem.
TimeLimit : 1 sec
Input Format
The input consists of several grid descriptions. Each description begins with a line con- taining two integer numbers R and C (1 <= R,C <= 16) specifying the grid size. Then there are R lines, each containing C characters. The characters can be either an uppercase letter "X" (black) or a dot "." (white). There is one empty line after each map. The input is terminated by two zeros in place of the board size.
Constraints
1 <= R,C <= 16
Output Format
For each grid, print one line containing the sentence "You have to tap T tiles.", where T is the minimal possible number of taps needed to make all tiles white. If the situation cannot be solved, output the string "Sorry you lose." instead.
Sample Input
5 5
.XX.X
.....
..XXX
..X.X
..X..
1 5
...XX
5 5
...X.
...XX
.XX..
..X..
.....
0 0
Sample Output
Sorry you lose.
You have to tap 1 tiles.
You have to tap 2 tiles.
Explanation
Input is taken until and unless R & C are not 0 0. So after 3 grids the input stops. The answer is pretty self explanatory.
Author - Mohit Sharma