#P6816. [PA 2009] Quasi-template
[PA 2009] Quasi-template
Description
Define that a string can match if and only if can cover while being allowed to extend beyond both the beginning and the end of , and , and must be a substring of .
As shown in the figure below.

Given , find the number of distinct strings and the shortest such . If there are multiple answers, output the lexicographically smallest one.
Input Format
One line containing a string .
Output Format
The first line contains an integer indicating the number of solutions.
The second line contains a string, the shortest . If there are multiple answers, output the lexicographically smallest one.
aaaabaabaaaba
10
aabaa
Hint
Valid strings are: aaaabaabaaab, aaaabaabaaaba, aaabaaba, aaabaabaa, aaabaabaaa, aaabaabaaaba, aabaa, aabaabaa, aabaabaaa, abaabaaa.
Constraints: .
Translated by ChatGPT 5
京公网安备 11011102002149号