You have a rectangular grid with R rows and C columns. Every cell is empty, holds an apple, or holds an obstacle. An empty cell is written as ., an apple as a, and an obstacle as #.
Apply gravity by these rules.
- Obstacles never move.
- If the cell directly below an apple is empty, that apple moves down into it.
Apply the rules until no apple can move any further, then print the final state of the grid. Stepping the rule one cell at a time is too slow for the largest inputs.