Codeforces Round 206 (Div. 2)
D
Game with Strings
Codeforces
未评级
原题
← CE →
翻译中…

Given an $*n* × *n*$ table $*T*$ consisting of lowercase English letters. We'll consider some string $*s*$ good if the table contains a correct path corresponding to the given string. In other words, good strings are all strings we can obtain by moving from the left upper cell of the table only to the right and down. Here's the formal definition of correct paths:

翻译中…

Consider rows of the table are numbered from 1 to $*n*$ from top to bottom, and columns of the table are numbered from 1 to $*n*$ from left to the right. Cell $(*r*, *c*)$ is a cell of table $*T*$ on the $*r*$-th row and in the $*c*$-th column. This cell corresponds to letter $*T*_{*r*, *c*}$.

翻译中…

A path of length $*k*$ is a sequence of table cells $[(*r*_{1}, *c*_{1}), (*r*_{2}, *c*_{2}), ..., (*r*_{*k*}, *c*_{*k*})]$. The following paths are correct:

翻译中…
  1. There is only one correct path of length $1$, that is, consisting of a single cell: $[(1, 1)]$;
  2. Let's assume that $[(*r*_{1}, *c*_{1}), ..., (*r*_{*m*}, *c*_{*m*})]$ is a correct path of length $*m*$, then paths $[(*r*_{1}, *c*_{1}), ..., (*r*_{*m*}, *c*_{*m*}), (*r*_{*m*} + 1, *c*_{*m*})]$ and $[(*r*_{1}, *c*_{1}), ..., (*r*_{*m*}, *c*_{*m*}), (*r*_{*m*}, *c*_{*m*} + 1)]$ are correct paths of length $*m* + 1$.
翻译中…

We should assume that a path $[(*r*_{1}, *c*_{1}), (*r*_{2}, *c*_{2}), ..., (*r*_{*k*}, *c*_{*k*})]$ corresponds to a string of length $*k*$: $*T*_{*r*_{1}, *c*_{1}} + *T*_{*r*_{2}, *c*_{2}} + ... + *T*_{*r*_{*k*}, *c*_{*k*}}$.

翻译中…

Two players play the following game: initially they have an empty string. Then the players take turns to add a letter to the end of the string. After each move (adding a new letter) the resulting string must be good. The game ends after $2*n* - 1$ turns. A player wins by the following scenario:

翻译中…
  1. If the resulting string has strictly more letters "a" than letters "b", then the first player wins;
  2. If the resulting string has strictly more letters "b" than letters "a", then the second player wins;
  3. If the resulting string has the same number of letters "a" and "b", then the players end the game with a draw.
翻译中…

Your task is to determine the result of the game provided that both players played optimally well.

翻译中…

Input

翻译中…

The first line contains a single number $*n*$ $(1 ≤ *n* ≤ 20)$.

翻译中…

Next $*n*$ lines contain $*n*$ lowercase English letters each — table $*T*$.

翻译中…

Output

翻译中…

In a single line print string "FIRST", if the first player wins, "SECOND", if the second player wins and "DRAW", if the game ends with a draw.

翻译中…

Note

翻译中…

Consider the first sample:

翻译中…

Good strings are strings: a, ab, ac, abd, acd.

翻译中…

The first player moves first and adds letter a to the string, as there is only one good string of length $1$. Then the second player can add b or c and the game will end with strings abd or acd, correspondingly. In the first case it will be a draw (the string has one a and one b), in the second case the first player wins. Naturally, in this case the second player prefers to choose letter b and end the game with a draw.

翻译中…

Consider the second sample:

翻译中…

Good strings are: x, xa, xay.

翻译中…

We can see that the game will end with string xay and the first player wins.

翻译中…

样例

Input #1
2
ab
cd
Output #1
DRAW
InputCopy OutputCopy
Input #2
2
xa
ay
Output #2
FIRST
InputCopy OutputCopy
Input #3
3
aab
bcb
bac
Output #3
DRAW
InputCopy OutputCopy
题目信息
题号
355D
时间限制
1 s
内存限制
512 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。