Country H upgrades the tank in order to defeat Country T in world war.
You're a soldier in great Country H and have received secret tasks : Collect the military secrets related to Country T.
You wil get a map of Country T like this:
is your tank with size 3x3 (xox is the head of the tank).
'$' represents a military secrets, '#' represents the wall, '^' represents the hill.
If you tank (3x3 body) is overlaped with the '$', you will pick it up ($ can't be counted again). If '#' or '^' is in front of the tank(in front of the xox, tank's front part), you can not move. Military secrets' position don't appear at initial tank's position.
The tank has four forward directions(South, East, North, West). Its direction is where xox heads. Notice that the upper of the map is the North, and the initial direction of tank is not always North.
And you will receive a sequence of instructions, which contains F (takes a step along the tank's head direction), R(tank's head turns right), and L(tank's head turns left). Instructions like R and L only change tank's head direction, and don't affect tank's position(would not cause moving).
Since the tank is upgraded, the tank can now execute instruction J (takes two step along the tanks head direction). However, you should NOT execute J when the tank may collides with hill or wall (in this case, you pick up nothing, and stand still at the original position).
Your will collect the military secrets within the valid instruction as many as possible. Then report the number of it to your boss, HT, immediately !
Fighting !
There are sample codes for you:
The first line of the input contains four things:
1. The rows of the map (0 < rows < 100)
2. The columns of the map (0 < cols < 100)
3. The total length of instructions (0 < instructions's length < 100)
4. The initial tank's direction(N, S, E, W)
The second line is the content of instructions.
For the next lines, they illustrate the map.
The number of military informations you get. (printf "\n" in the end)