You are simulating a classic Snake game on an $$$n \times n$$$ grid.
Grid
Cells are addressed by coordinates $$$(x, y)$$$, where:
The snake initially consists of a single cell:
Moves
You are given a string $$$s$$$ of length $$$k$$$. Each character represents a move:
Wrapping
The grid is toroidal. If the head moves outside the grid, it reappears on the opposite side:
Food
There are $$$m$$$ foods given in a fixed order at positions $$$(x_i, y_i)$$$.
Snake Movement
Each move is processed as follows:
Death Rule
The snake dies if after moving, its head occupies a cell that is currently part of its body. If the snake does not eat during this move, moving into the current tail cell is allowed, because the tail leaves at the same time.
Task
Simulate the game for at most $$$k$$$ moves.
3 10 3 LLDRRUURRD 1 3 2 3 3 3
ALIVE 4
3 5 3RDLLL1 22 22 1
DEAD
In the first sample, the grid is $$$3 \times 3$$$. The snake starts at $$$(1,1)$$$ with length $$$1$$$. Food $$$1$$$ is initially located at $$$(1,3)$$$.
The moves are: [ L, L, D, R, R, U, U, R, R, D ]
The snake survives all $$$10$$$ moves, so the answer is ALIVE 4.
In the second sample, the snake dies before all $$$k$$$ moves are performed.
| Name |
|---|


