Killbots is a turn based game about staying alive in a room full of killer robots. Nobody knows who built the robots or why they were told to destroy everything in front of them. The one certain thing is that their builder went for quantity over quality, so the robots are many and dim.
The board is a rectangular grid, and every cell holds one of the following.
A turn runs in two phases.
Cells are resolved once all of a phase's steps are taken.
Everything moves at the same time, so entering a cell that another unit leaves in the same phase costs nothing.
Turns repeat until no robot and no fastbot is left. Count how many robots and fastbots the hero destroys.
The figure below is the first turn of one game. The hero stands on E5, and junkheaps sit on D1, F3, G5 and B7.
A B C D E F G H
1 . . . * . . . .
2 . . . . . . . #
3 . . . . . * . .
4 . . . . + . . .
5 . + . . @ . * .
6 . . . . . . . +
7 . * . . . + . .
8 . + . . . . # .
In the first phase the robot on B5 shares the hero's row and steps right to C5, and the robot on E4 shares the hero's column and steps down onto E5, where the hero destroys it. The robot on B8 steps up and right to C7. The robot on H6 steps up and left to G5, hits the junkheap and is destroyed. The robot on F7 steps to E6, and in the same phase the fastbot on G8 steps to F7, so the two never share a cell. In the second phase the robots stand still and the fastbot on F7 steps to E6, where it crashes into the waiting robot. Both are destroyed and a junkheap is left on E6.
The input holds several test cases, and one test case is one grid. A grid is given as several lines of the same length. One line is one row of the grid, and one character of a line is one cell. An empty cell is ., and the other cells use the characters described above. A line holding a single $ character follows each grid. Exactly one cell of a grid holds @. Each side of a grid is at least 1 and at most 1000 cells.
For each test case print on one line the number of robots and fastbots the hero destroyed by the time the game ends, that is, once every robot and fastbot has been destroyed.