int n; char s[MAXN]; int lcp[MAXN]; // lcp(i, i+1) int ans[MAXN];
boolcmp(int x, int y){ int i = x, j = y; if (i > j) swap(i, j); int t = lcp[i]; if (t >= j - i) { if (x < y) return1; else return0; } if (s[i + t + 1] < s[i + t]) { if (i == x) return1; else return0; } if (i == x) return0; else return1; }
intmain(){ scanf("%d", &n); scanf("%s", s + 1); lcp[n] = 0; for (int i = n - 1; i >= 1; --i) { if (s[i] == s[i + 1]) lcp[i] = lcp[i + 1] + 1; else lcp[i] = 0; } for (int i = 1; i <= n; ++i) ans[i] = i; sort(ans + 1, ans + n + 1, cmp); for (int i = 1; i <= n; ++i) printf("%d ", ans[i]); return0; }