B-Suffix Array
题号:NC209429
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

The -function of a string is defined as follows.

  • If there is an index where , ,
  • Otherwise, .

Given a string , sort its suffixes into increasing lexicographically order of the -function.

Formally, the task is to find a permutaion of such that holds for .

输入描述:

The input consists of several test cases terminated by end-of-file.

The first line of each test case contains an integer n.
The second line contains a string .

*
* s_i is either '`a`' or '`b`'.
* The sum of n does not exceed .

输出描述:

For each test case, print n integers which denote the result.
示例1

输入

复制
2
aa
3
aba
5
abaab

输出

复制
2 1
3 2 1
5 4 2 1 3

备注:

For s = aba, 
*
*
*
Therefore, .