Game of the Retired
Time limit1sMemory limit1024 MB
Given K grid boards fenced by two non-touching R/D paths, decide who wins the token game where Jeyeon moves right and Deokin moves down.
- Level
Hard9 of 10
- Topics
- Game theory, String, Math
- Solved
- No attempts yet
Problem
Having successfully retired from competitive programming, Jeyeon and Deokin made a new board game to ease the emptiness they felt. The game consists of boards and tokens. Board () is a grid with rows and columns. Before the game starts, the players build a fence along the boundary of each board.
The fence is built along the edges of the grid. Consider paths of length from the top-left corner to the bottom-right corner that move only right (R) or down (D) by one unit at a time. Choose two such paths that meet only at their starting and ending points, and build the fence along them. This is called a good fence layout.
Figure K.1: Good and bad fence layouts
For example, take and . In (a), the two paths RRDRDDDRD and DDRRDDDRR meet only at the start and end points, so this is a good layout. In (b), the chosen paths RDRDRDRDD and DDRRDDDRR meet at a point other than the start and end, so it is not a good layout. In (c), one of the paths does not move only right or down, so it is not a good layout either.
The game begins with each board fenced by a good layout and a token placed on the top-left cell of each board. Jeyeon moves first, and the players alternate turns. On her turn, Jeyeon picks one of the tokens and moves it one cell to the right. On his turn, Deokin picks one of the tokens and moves it one cell down. A token cannot be moved across a fence. A player who has no legal move on their turn loses.
This game has no element of luck, so if both players play their best, the winner is known before the game starts. Neither of them wants to solve another problem, so you must tell them who wins.
Input
The first line contains an integer (). Then, for each board , three lines follow. The first line contains and . The next two lines each give one of the two fence paths as a string of length . Each string consists only of R and D, and together the two strings form a good fence layout. (, , )
Output
Print First if Jeyeon wins when both players play optimally, or Second if Deokin wins.
Hint

Figure K.2: See Sample 1
The initial boards of Sample 1 are shown above. If Jeyeon moves the token on the second board to the right on her first turn, Deokin has no legal move left, so Jeyeon wins.


