Hide

Problem B
Amazing Race Atlantic

/problems/atlantic-canada23.amazingraceatlantic/file/statement/en/img-0001.jpg
Image by sanchesnet1 (iStock); Used under license

The Amazing Race: Atlantic Canada Edition (ARACE) decides to do preselection to narrow down the thousands of registrant teams. To select only the best ones, teams must qualify by racing to the next location on a path of road segments, each of which is marked with one of the following colors: red, green, yellow, blue. Each time a team races along a road segment, the team gets a sticker with the color of that segment. At the end, the organizers will record the team’s stickers (in the order they were received) and then check that the path adhered to the ARACE preselection rules:

  1. the path must start with the sequence yellow, red, red, green, red

  2. the path must end with the sequence red, green, red, yellow

  3. between the first yellow and the last yellow, the number of greens must be $2~ \textrm{more}$ than a multiple $\textrm{of}~ 4$

  4. if the number of greens is more $\textrm{than}~ 2,$ then between the second green and the second-last green the number of reds must be a multiple $\textrm{of}~ 3$

A team is selected if it follows all these rules; otherwise, it is eliminated. Your challenge is to write a program to automate the process of determining whether a team is selected or eliminated.

The sequence of stickers for a team is recorded as a string consisting only of the four characters ‘R’ (for red), ‘G’ (for green), ‘Y’ (for yellow), and ‘B’ (for blue). However, to your dismay the file containing these strings has been corrupted! Fortunately, none of the characters were deleted, but additional characters (not in $\{ \texttt{R}, \texttt{G}, \texttt{Y}, \texttt{B} \} )$ were randomly inserted. Despite this setback, the ARACE organizers still want you to write your program to correctly check each team’s path.

Input

The first line of input contains an integer, $n,$ the number of teams $(1 \leq n \leq 100).$ Each of the following $n$ lines contains a (possibly corrupted) string recording the stickers received by one of the teams (in order). Each string is nonempty, has length at most $7\, 000,$ and consists entirely of printable characters (i.e., characters with ASCII values in $[32,126]).$ Every string ends with an underscore (‘_’), and no underscore appears anywhere else in the string (the underscore was intentionally used as a delimiter, and fortunately it survived the file corruption process).

Output

For each string in the input, output a line containing either “selected” or “eliminated”, as appropriate.

Sample Input 1 Sample Output 1
4
YRRGRBBRGRY_
*HYDRA*RANGER*BIEBER*ANGRY_
THIS ONE IS CORRECT_
YRRG&RGB&RGB&RG&RY_
selected
selected
eliminated
eliminated

Please log in to submit a solution to this problem

Log in