P2724 [IOI 1998 / USACO3.1] Contact

Background

The cows have become interested in scanning outer space with a radio telescope. Recently, they noticed a very strange pulse-modulated microwave signal coming from the center of the galaxy. They want to know whether the radio waves were sent by some extraterrestrial life, or are merely emitted by ordinary stars.

Description

Help the cows by writing a tool that analyzes the records they wrote down in a file to find the truth. They are looking for the bit sequences of lengths between $A$ and $B$ (inclusive) that occur the top $n$ most times in the data file. Occurrences may overlap, and every sequence that appears at least once should be counted.

Input Format

The first line contains three integers $A, B, n$, as defined in the description. From the second line on is the string $s$, with at most $80$ characters per line. Concatenate all lines in order to obtain $s$.

Output Format

Output the $n$ most frequent sequences (in order from highest to lowest frequency). For sequences with the same frequency, order them by length from short to long; if the lengths are the same, order by binary value (ascending). If the number of distinct sequences is less than $n$, output all that exist. For each frequency that occurs, first output a line containing only that frequency, then output the sequences with that frequency, separated by spaces. Print six sequences per line (unless fewer remain).

Explanation/Hint

#### Explanation for Sample 1 In the sample, the sequence $100$ appears $12$ times, while the sequence $1000$ appears $5$ times. The most frequent sequence is $00$, which appears $23$ times. --- #### Constraints For $100\%$ of the testdata, it is guaranteed that $1 \leq n \leq 50$, $1 \leq A \leq B \leq 12$, $s$ contains only the characters `0` and `1`, and the length of $s$ is at most $2 \times 10^5$. --- The problem translation is from NOCOW. Translated by ChatGPT 5