Count paths that exit an grid in exactly moves. Each move goes up/down/left/right. = number of paths at after moves. Transitions: each cell receives from 4 neighbors.
When a move goes out of bounds, it counts as an exit. Track exits at each step. Total exits = sum of paths that exit at each step from 1 to . Take modulo as counts get large. Use modular arithmetic for counting paths. The mod operation distributes over addition correctly.