A substitution rule describes how to take a sequence of symbols and convert it into a different sequence of symbols. For example, , is a substitution rule which means that can be replaced with . Using this rule, the sequence would be transformed into the sequence (the substituted symbols are in bold).
In this task, you will be given three substitution rules, a starting sequence of symbols and a final sequence of symbols. You are to use the substitution rules to convert the starting sequence into the final sequence, using a specified number of substitutions.
For example, if the three substitution rules were:
we could convert the sequence into in steps, by the following substitutions:
where the symbols to be replaced are shown in bold. More specifically, from the initial sequence , substitute rule starting at position , to get the result . From , substitute rule , starting at position , to get the result . From , substitute rule , starting at position , to get the result . From , substitute rule , starting at position , to get the result , which is the final sequence.
The first three lines will contain the substitution rules. Each substitution rule will be a sequence of
B's, followed by a space following by another sequence of
B's. Both sequences will have between one and five symbols.
The next line contains three space separated values, , and . The value is an integer specifying the number of steps that must be used, and the values (the initial sequence) and (the final sequence) are sequences of
B's, where there are at least one and at most symbols in and at least one and at most symbols in .
For of the marks available, .
For an additional of the available marks, .
Due to the official test data being weak, an additional subtask worth 15 marks has been added that consists of tests constructed to break solutions that are incorrect but AC on the official test data. Data are provided by.
The output will be lines long and describes the substitutions in order.
Line of the output will contain three space-separated values, , , and :
- is the substitution rule number (either , or ) that will be used.
- is the starting position index of where the substitution rule will be applied in the sequence. Notice that the string is -indexed (i.e., the first character of the string is at index ).
- is the sequence that results from this substitution. Specifically, is the sequence of symbols that results by applying substitution rule starting at position from the previous sequence of symbols, , where we define to be the initial sequence . Note that , the final sequence.
There will always be at least one sequence of substitutions that will convert into . If there is more than one possible sequence of substitutions, any valid sequence will be accepted.
AA AB AB BB B AA 4 AB AAAB
Possible Output for Sample Input
2 1 BB 3 1 AAB 3 3 AAAA 1 3 AAAB
Explanation of Output for Sample Input
This is the example outlined in the problem description. Note that the following is another possible valid substitution sequence:
2 1 BB 3 2 BAA 1 2 BAB 3 1 AAAB
Specifically, showing the substitutions in bold, we get .