Automatic Input Verifier
Tons and tons of programming contest problems contain integers separated with spaces and newlines in the input. In many cases, the amount of numbers found inside the file and in 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:
"The first/next line contains number non-negative integer(s), variable_1, variable_2, ..., variable_number.". Here, number is a positive integer between 1 and 3, and variables are arbitrary distinct variable names that have never appeared in the input description before this statement. When number is equal to 1, "integer(s)" should be replaced by "integer", otherwise it should be replaced by "integers".
"The first/next line contains variable integers.". Here, variable is a variable name that has appeared in this description before this statement.
"The first/next line contains a non-negative integer variable, followed by variable integers.". Here, variable is a variable name that has never appeared in the input description before this statement, and will never appear in the input description after this statement. Please note that the same variable name is repeated twice in this statement.
"The first/next line contains number integer(s).". Here, number is a positive integer. When number is equal to 1, "integer(s)" should be replaced by "integer", otherwise it should be replaced by "integers.
"The first/next variable lines contain number integer(s) each.". Here, variable is a variable name that has appeared in this description before this statement, and number is a positive integer. When number is equal to 1, "integer(s)" should be replaced by "integer", otherwise it should be replaced by "integers".
"The first/next variable_1 lines contain variable_2 integers each.". Here, variable_1 and variable_2 are (possibly the same) variable names that have appeared in this description before this statement.
"The first/next variable_1 lines contain a non-negative integer variable_2, followed by variable_2 integers each.". Here, variable_{1 }is a variable name that has appeared in this description before this statement. variable_2 is a variable name that has never appeared in this description before this statement, and will never appear in this description after this statement, and is different from variable_1. Please note that, unlike all other variables, variable_2 may have different values for each line described by this statement. This is useful, for example, for listing several heaps with varied amount of items in each heap.
Each occurrence of "first/next" in the above statements should be subsituted by "first" in the first statement of the input description, and by "next" in all other statements.
Given several input files, you need to verify whether there exists an input description containing not more than 4 statements that fits most of the given input files, and highlight the input files that don’t fit this description.
Input
The first line of the input file contains an integer n, 1 ≤ n ≤ 10, the number of input files given. Please note, that the meaning of words "input file" below corresponds to the second meaning of that term in this paragraph, not the first one.
The description of each given input file starts with a line containing a dash ("-"). The actual given input file follows, with each line appended a exclamation mark ("!") to avoid difficulties in processing empty lines.
After excluding the exclamation mark at the end, each line of each given input file will contain between 0 and 1000 integers, each between -1000 and 1000, separated with single spaces. Each given input file will contain at most 10000 lines and at most 100000 integers.
Output
In case there exists an input description with not more than 4 statements describing all given input files, output "All good!" (without quotes) to the first line of the output file, followed by the input description itself, one statement per line. Use non-empty strings of at most 10 lowercase English letters to denote variables. In case there are several possible descriptions, output any.
In case there exists an input description with not more than 4 statements describing at least one given input file, find any such description that describes the most given input files. Output "Bad format: numbers." (without quotes) to the first line of the output file, where numbers is a single-space separated list of input file numbers that don’t fit the given input description. The input files are numbered from 1 to n in the order they are given. Then output the input description itself.
In case no input description with not more than 4 statements fits any given input file, output "FAIL." to the only line of the output file.