Automatic Input Verifier#1919

Automatic Input Verifier

2 seconds
256 megabytes
Very hard

Tons and tons of programming contest problems use input where integers are separated by spaces and newlines. In many cases, the number of numbers in the file and on each particular line is determined by the numbers themselves.

More formally, we define an input description as a sequence of statements of the following types:

  1. "The first/next line contains non-negative integer(s), \textit{variable}_1, \textit{variable}_2, ..., \textit{variable}_\textit{number}." Here, is a positive integer between and , and s are distinct variable names that have not appeared before in the input description. When \textit{number}=1, "integer(s)" should be replaced by "integer", otherwise by "integers".

  2. "The first/next line contains integers." Here, is a variable name that has appeared in this description before this statement.

  3. "The first/next line contains a non-negative integer , followed by integers." Here, is a variable name that has not appeared before this statement and will not appear after it in the input description. Note that the same variable name appears twice in this statement.

  4. "The first/next line contains integer(s)." Here, is a positive integer. When \textit{number}=1, "integer(s)" should be replaced by "integer", otherwise by "integers".

  5. "The first/next lines contain integer(s) each." Here, is a variable name that has appeared in this description before this statement, and is a positive integer. When \textit{number}=1, "integer(s)" should be replaced by "integer", otherwise by "integers".

  6. "The first/next \textit{variable}_1 lines contain \textit{variable}_2 integers each." Here, \textit{variable}_1 and \textit{variable}_2 are (possibly the same) variable names that have appeared in this description before this statement.

  7. "The first/next \textit{variable}_1 lines contain a non-negative integer \textit{variable}_2, followed by \textit{variable}_2 integers each." Here, \textit{variable}_1 is a variable name that has appeared in this description before this statement. \textit{variable}_2 is a variable name that has not appeared before and will not appear after this statement in this description, and is different from \textit{variable}_1. Note that, unlike all other variables, \textit{variable}_2 may have different values for each line described by this statement. This is useful, for example, to list several heaps where each heap has different number of items.

Each occurrence of "first/next" in the statements above should be replaced by "first" in the first statement of the input description, and by "next" in all following statements.

Given several input files, you need to check whether there exists an input description consisting of at most statements that matches most of the given input files and highlight the input files that do not fit the description.

Input

The first line of the input file contains an integer (1 \le n \le 10), the number of input files given. Note that in the rest of this statement, the term "input file" means a different thing than in the previous sentence — it refers to the file's content, not to the physical file.

Each input file description starts with a line containing a dash ("-"). Then comes the actual input file, with an exclamation mark ("!") appended to the end of each line to ease handling of empty lines.

After removing the exclamation mark, each line of each input file will contain between and integers, each between and , separated by single spaces. Each given input file will contain at most lines and at most integers.

Output

If there exists an input description with at most statements that describes all given input files, output All good! (without quotes) on the first line, followed by the input description, one statement per line. Use non-empty strings of at most 10 lowercase English letters as variable names. If there are several possible descriptions, output any.

If there exists an input description with at most statements that describes at least one given input file, find any such description that describes the largest number of files. Output Bad format: . (without quotes) on the first line, where is a single-space separated list of input file indices (from to ) that do not fit. Then output the description.

If no input description with at most statements matches any input file, output FAIL. in the only line.

Examples

Example 1

Loading
Loading