Sanjay and his friends are searching for treasure in an abandoned castle. They have just entered the castle and find themselves faced with a maze of treasure-filled rooms separated by locked doors. Fortunately for them, the old owners left spare keys littered around the castle.
Sanjay find that they can use any key to help open any door in the castle. However, some doors require multiple keys in order to open them.
The floor plan of the castle can be represented as an x grid of the following characters:
.denotes an empty space
#denotes a wall.
9denote a door, with the number representing how many keys it takes to open the door.
Krepresents a key.
Trepresents a treasure.
Srepresents Sanjay's start point.
The input will contain test cases. Each test case starts with an integer . The next lines each contain characters denoting the floor plan of the castle.
For each test case, your program should output the number of treasures that Sanjay and his friends will be able to retrieve.
3 .SK #1# T.. 5 S.2.T .K##3 11##T ....# ..T.K
Note: Only cases are shown in this sample.
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org