#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 SS of length nn 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 55-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 55 possible starting positions to read the string:

  • cbbad (i=1i=1).

  • bbadc (i=2i=2).

  • badcb (i=3i=3).

  • adcbb (i=4i=4).

  • dcbba (i=5i=5).

If there are multiple lexicographically smallest strings, the Martians want the one closest to the rope head (i.e. the smallest ii). More rigorously, for a string TT, define

Ti=T[iT]::T[1i1](1iT)T_i=T[i……|T|]::T[1……i-1](1 \leq i \leq |T|)

where :::: denotes string concatenation. Define f(T)f(T) as the smallest ii (1iT1 \leq i \leq |T|) such that Ti=min(T1,T2,,TT)T_i=min(T_1,T_2,……,T_{|T|}).

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 S[1i]S[1……i] (1iS1 \leq i \leq |S|) of the given string SS, compute f(S[1i])f(S[1……i]).

Input Format

There is only one line of input, containing a string SS.

Output Format

In one line, for each ii (1iS1 \leq i \leq |S|), output an integer f(S[1i])f(S[1……i]). Separate the numbers with spaces.

abaacaba
1 1 3 3 3 6 3 8

Hint

Translated by ChatGPT 5