IOI '99 - Antalya-Belek, Turkey
A set of code words and a text are given. The text is supposed to contain a message made up of the code words embedded in the text in a peculiar (and possibly ambiguous) way.
The code words and the text are sequences made up of the upper and lower
case letters of the English alphabet only. Case-sensitivity is assumed.
The length of a code word is defined in the usual way: For example,
the code word ALL has length
The letters of a code word do not have to occur consecutively in the
given text. For example, the code word ALL will always occur in the
text within a subsequence in the form of A
A covering sequence is identified by its start position (position of its
first letter) and its end position (position of its last letter) in the
text. (The first letter of the text is at position
To extract the message hidden in the text you undertake the task of forming a solution. A solution is a set of items, each consisting of a code word and a covering sequence for this code word, so that the following conditions are all satisfied:
- the covering sequences do not overlap with each other
- a covering sequence does not exceed
in length - the sum of the lengths of the code words is maximal. (Each item contributes the length of the code word it contains to the sum.)
In case there is more than one solution you are required to report only one solution.
Input Specification
The first line of input contains the number of code words,
The final line of input is the text, whose length is at least
We say that a covering sequence
It is guaranteed that in the given text:
- for each position in the text the number of right-minimal covering
sequences containing that position does not exceed
- the number of right-minimal covering sequences does not exceed
.
Output Specification
The first line of output should contain the sum obtained by your
solution. Each of the following lines will determine an item in your
solution. A line consists of three space-separated integers:
Sample Input
4
RuN
RaBbit
HoBbit
StoP
StXRuYNvRuHoaBbvizXztNwRRuuNNP
Sample Output
12
2 9 21
1 4 7
1 24 28
(Remark: The hidden message that could be extracted from the solution is
RuN RaBbit RuN
. (An alternative solution would yield RuN HoBbit RuN
).
Be reminded that the message is not to appear in the output.)
Comments