This summer, ELT and his classmates went toBeijing for a training of coding. ELT have never been to Beijing before, so atthe weekend, he together with some friends went to the National Museum, it'sfree for students! TheNational Museum consists of many parts. One part of it is an exhibition ofAncient China From Xia Dynasty to Qing Dynasty, it needs a big room to show allthe things. What's more, there exist many walls to hang pictures. The boundaryof this room is walls except the entrance and exit. Withwalls, an entrance and an exit, this room can be regarded as a maze. To make itsimple, this room is a R*C grid, wall is constructed at some edges of grid. Theentrance is always at the first row, and the exit is always at the last row,just like the picture .
ELTcan't remember his direction in maze, but he is a clever boy. He knew analgorithm called "Always Turn Right", it's procedure is as follows:at any grid of this room, if we can turn right(no wall at right side), then wemust turn right; if we can't turn right but can go straight forward, then wemust go forward; if we can't go forward but can turn left, then we must turnleft; if we can't even turn left, we just turn backward. In the picture above,if we use this algorithm, we'll visit these grids in order: Entrance --> (0,1) --> (0, 0) --> (0, 1) --> (0, 2) --> (1, 2) --> (1, 1) -->(1, 0) --> (2, 0) --> (1, 0) --> (1, 1) --> (2, 1) --> (2, 2)--> Exit. Very easy, doesn't it?
ELTuses "Always Turn Right" algorithm to visit this room from entranceto exit, and then from exit to entrance. He wants to know whether he walked allgrids in the room. Now ELT is dizzy because the maze is too big, can you helphim?