#P1124. [ZJOI2001] 文件压缩

[ZJOI2001] 文件压缩

Problem Description

The algorithm is as follows: For a string SS of length nn, first construct nn strings, where the ii-th string is obtained by moving the first i−1i-1 characters of SS to the end. Then sort these nn strings by their first character in ascending order; if two strings have the same first character, sort them by their positions in SS in ascending order. The last characters of the sorted strings form a new string S′S', whose length is also nn and which contains every character of SS. Finally, output S′S' and the position pp of the first character of SS in S′S'.

Example: SS is example.

  1. Construct nn strings.
example
xamplee
ampleex
mpleexa
pleexam
leexamp
eexampl
  1. Sort the strings.
ampleex
example
eexampl
leexamp
mpleexa
pleexam
xamplee
  1. Compression result.

S′=xelpameS' = \texttt{xelpame},p=7p = 7。

Because of the characteristics of English words, certain letters occur very frequently, so identical letters are very likely to be grouped together in S′S', which improves the compression ratio of S′S'. Although this algorithm leverages properties of English words, in practice it is found to work for almost all file compression.

Write a program that reads S′S' and pp, and outputs the string SS.

It is guaranteed that SS contains only lowercase letters (so the input S′S' also contains only lowercase letters).

Input Format

Three lines in total.

The first line contains an integer nn (1≤n≤100001 \le n \le 10000), the length of S′S'.

The second line contains the string S′S'.

The third line contains an integer pp.

Output Format

One line, the string SS.

7
xelpame
7

example

Hint

Translated by ChatGPT 5