We are building an old-school, back-to-basics computer game: a simple text-based adventure where you walk around a grid, collecting treasure (gold) while avoiding traps.
The game is played on a rectangular grid, and the player is given only very limited information about her surroundings. She may move up, down, left, or right (never diagonally) and may keep moving for as long as she likes — until she falls into a trap.
For scoring, we want to know how much gold the player could collect while always being certain that every square she steps into is safe. The map is randomly generated and unknown to her in advance, so she has no prior knowledge of its layout.
The first line contains two integers W and H ($3 \le W, H \le 50$): the width and height of the map. The next H lines each contain W characters describing the map, using these symbols:
P — the player's starting positionG — a piece of goldT — a trap# — a wall. — ordinary floorThere is exactly one P, and the border of the map is always made of walls.
Print the number of pieces of gold the player can collect without ever risking falling into a trap.