#P5334. [JSOI2019] 节日庆典
[JSOI2019] 节日庆典
Description
Before the celebration begins, the Martians prepare the balloons and string them onto a rope. The balloons, in order, can be seen as a string of length consisting of lowercase letters. Then, the Martians will add the balloons one by one, following the order of the string, onto a circular ring for the celebration, and perform a show to celebrate.
The figure below shows the situation for the balloon string cbbadbcd at the -th show. At this time, the balloons on the celebration ring are cbbad.

To make each show look better, the Martians want to adjust the order of the balloons on the ring before each show starts, so that the balloon arrangement for each show is the most visually pleasing. For a set of balloons (a string), the Martians define the most visually pleasing string as the lexicographically smallest string read along the rope direction on the celebration ring. For example, for cbbad, there are possible starting positions to read the string:
-
cbbad ().
-
bbadc ().
-
badcb ().
-
adcbb ().
-
dcbba ().
If there are multiple lexicographically smallest strings, the Martians want the one closest to the rope head (i.e. the smallest ). More rigorously, for a string , define
where denotes string concatenation. Define as the smallest () such that .
JYY hopes you can help him design an algorithm so that the balloon arrangement for each show is the most visually pleasing. That is, for every prefix () of the given string , compute .
Input Format
There is only one line of input, containing a string .
Output Format
In one line, for each (), output an integer . Separate the numbers with spaces.
abaacaba
1 1 3 3 3 6 3 8
Hint

Translated by ChatGPT 5
京公网安备 11011102002149号