#P5329. [SNOI2019] 字符串

[SNOI2019] 字符串

Description

Given a string aa of length nn consisting of lowercase letters, let its ii-th character be ai(1in)a_i(1\le i\le n).

Let sis_i be the string obtained after deleting the ii-th character. Sort s1,s2,,sns_1,s_2,\cdots,s_n in increasing lexicographical order. If two strings are equal, then the one with the smaller index is considered lexicographically smaller.

Input Format

The first line contains an integer nn.

The second line contains a string aa of length nn consisting of lowercase letters.

Output Format

Output one line with nn integers k1,k2,,knk_1,k_2,\cdots,k_n, separated by spaces, meaning that sk1<sk2<<skns_{k_1}<s_{k_2}<\cdots<s_{k_n}.

7
aabaaab
3 7 4 5 6 1 2

Hint

Constraints: For all testdata, 1n1061\le n\le 10^6.

For 10%10\% of the testdata, 1n20001\le n\le 2000.

For another 20%20\% of the testdata, 1n1051\le n\le 10^5 and any two adjacent characters ai,ai+1a_i,a_{i+1} are not equal.

For another 30%30\% of the testdata, 1n1051\le n\le 10^5.

For the remaining 40%40\% of the testdata, there are no special constraints.

Translated by ChatGPT 5