#P5446. [THUPC 2018] 绿绿和串串

[THUPC 2018] 绿绿和串串

Description

Lvlvl has a non-empty string RR consisting of lowercase letters, but Yazid does not know what it is.

We define the flip operation: flip-copy a string using its last character as the axis of symmetry. Formally, if the string to be flipped is RR, then take the first R1\left| R\right|-1 characters, reverse them, and append them to the end of the string.

For example, after applying the flip operation to abcd, we get abcdcba; if we apply the flip operation 22 times in a row to qw, we get qwqwq; for z, no matter how many times we apply the flip operation, it will not change.

The playful Lvlvl performed the flip operation several times (possibly 00 times).

Then the naughty Lvlvl showed a non-empty string SS, and said that SS is a prefix of the final string RR. Now he wants to test Yazid: what lengths could the initial string RR have?

Yazid asked you, who are participating in the Tsinghua campus contest, to help solve this problem. But the clever Yazid noticed that every integer greater than S\left| S\right| must be a possible length of RR, so you only need to tell him the possible lengths of RR that do not exceed S\left| S\right|.

To help you understand the problem, Yazid also explains some concepts and notation:

  • For a string SS, S\left| S\right| denotes its length.
  • For a string SS, we say that a string TT is its prefix if and only if TS\left| T\right|\leq\left| S\right|, and for every integer ii with 1iT1\leq i\leq\left| T\right|, the ii-th character of TT from the left is the same as the ii-th character of SS from the left. (Intuitively, TT appears at the beginning of SS.)
    • For example: abc is a prefix of abcdefg; aba is not a prefix of abba; z is a prefix of z; the empty string is a prefix of any string.

Input Format

The input contains multiple test cases. The first line contains an integer TT indicating the number of test cases. Each test case is described as follows:

  • One line contains a non-empty string SS consisting only of lowercase letters.

Output Format

For each test case, output one line:

  • Output all possible values of R\left| R\right| that do not exceed S\left| S\right|, in increasing order, separated by a single space.
4
abcdcb
qwqwq
qaqaqqq
carnation
4 6
2 3 4 5
6 7
9

Hint

Constraints

It is guaranteed that S106\left| S\right|\leq 10^6 and S5×106\sum\left| S\right|\leq 5\times 10^6.

S\sum\left| S\right| denotes the total length S\left| S\right| of all test cases in a single test point.

Notes

  • The input size is large, so please pay attention to input efficiency.
  • What does the last string in the sample mean?

From the 2018 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2018). Thanks to Pony.ai for supporting this contest.

Resources such as the editorial can be found at https://github.com/wangyurzee7/THUPC2018.

Translated by ChatGPT 5