Oh no! You got electrocuted by spilling coffee on your laptop and you are now reincarnated as a Roomba. You look at your surroundings, and it's a normal living room, but it's dirty. As a good Roomba, you need to help your owner clean it up. Your owner is bossy, so he just tells you the living room's grid dimension and the direction of the path you need to take.
You have a bumper sensor, so when a command would put you outside the room, you refuse to move and wait for the next one. Every tile you enter gets cleaned, and you keep a running total of everything you've absorbed. Here are the exact rules:
STOP, your shift ends immediately. Every command after STOP counts as skipped. STOP itself is not counted.<steps> tiles, you clean every tile you pass through, including the one you land on. You absorb that tile's dirt, and it becomes 0. Your starting tile is not cleaned at the start of the shift; you only clean tiles you enter.Note: Crash Course about Loop: https://hackmd.io/@gladysvalerie/S1wWLYCYze
In the first line, you will input five integers: com R C sr sc . com is the number of commands you will receive from your owner, R C are the dimension of the room’s grid size, sr sc are your starting point in the grid.
The next R lines describe the room: C digits each, where each digit (0-9) is that tile’s dirt level.
The next com lines are each either <dir> <steps>, where <dir> is one of N, S, E, W and <steps> is a positive integer, or the single word STOP.
Constraints
com ≤ 100R, C ≤ 100sr < R, 0 ≤ sc < C (the start is always inside the room)<dir> is one of N, S, E, W<steps> ≤ 100<dir> <steps> or STOP, and there are exactly com of themIn the first line, output your final position fr fc final row and final column.
The second line, output the total dirt you collected.
The third line, output the number of commands skipped.