#P1124. 文件压缩

文件压缩

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 i1i-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 SS', whose length is also nn and which contains every character of SS. Finally, output SS' and the position pp of the first character of SS in SS'.

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 SS', which improves the compression ratio of SS'. 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 SS' and pp, and outputs the string SS.

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

Input Format

Three lines in total.

The first line contains an integer nn (1n100001 \le n \le 10000), the length of SS'.

The second line contains the string SS'.

The third line contains an integer pp.

Output Format

One line, the string SS.

7
xelpame
7

example

Hint

Translated by ChatGPT 5