#P6816. [PA 2009] Quasi-template

[PA 2009] Quasi-template

Description

Define that a string ss can match SS if and only if ss can cover SS while being allowed to extend beyond both the beginning and the end of SS, and sS|s| \le |S|, and ss must be a substring of SS.

As shown in the figure below.

Given SS, find the number of distinct strings ss and the shortest such ss. If there are multiple answers, output the lexicographically smallest one.

Input Format

One line containing a string SS.

Output Format

The first line contains an integer indicating the number of solutions.

The second line contains a string, the shortest ss. 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: S2×105|S| \le 2\times 10^5.

Translated by ChatGPT 5