Editorial
Number the five blocks in each layer as from one end to the other. Block is the center block.
The key is to pair blocks and answer every move by removing its paired block. From the center-of-mass condition in the statement, one can verify that in each of the paired configurations described below, whenever the opponent makes a move that does not collapse the tower, removing the paired block also does not collapse the tower. After the response, the projected center of mass above every layer boundary remains inside the convex hull of the remaining support region.
Suppose that is odd. The topmost layer cannot be used, so an even number of layers are available for removals. Pair them from the bottom as .
If Shirogane removes block from one layer of a pair, Shinomiya removes block from the other layer of the same pair. By the stability observation above, this response is always possible. Every move is matched by another move, so Shirogane is the first player who has no safe move left. Thus Shinomiya wins when is odd.
Now suppose that is even. Shirogane first removes the center block, block , from layer . The center of this block lies on the central vertical axis of the tower, so this removal does not shift the center of mass to either side and does not collapse the tower.
After that, pair layers through as and pair blocks with the same number across the two layers. Inside layer , pair block with block , and block with block . Whenever Shinomiya removes a block, Shirogane removes its paired block. Again, the stability condition guarantees that the response is safe. Except for Shirogane's first move, all moves are paired, so Shinomiya is the first player who has no safe move left.
Therefore the winner depends only on the parity of .
- If is odd, print
Shinomiya. - If is even, print
Shirogane.
Each test case is processed in time and extra space.
Solution written by GPT5.6