

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
高橋君は英小文字からなる長さ の文字列 を持っています。 高橋君は に対して以下の操作を 回行うことにしました。
- を反転した文字列を として、 と をこの順に連結して得られる文字列を とする。
- ある の連続する長さ の部分文字列を として、 を で置き換える。
最終的な として考えられる文字列の内、辞書順で最小のものを求めてください。
制約
- は英小文字からなる
入力
入力は以下の形式で標準入力から与えられる。
出力
最終的な として考えられる文字列の内、辞書順で最小のものを出力せよ。
入力例 1Copy
5 1 bacba
出力例 1Copy
aabca
bacba
のとき、abcab
, bacbaabcab
であるので aabca
とするのが最適です。
入力例 2Copy
10 2 bbaabbbaab
出力例 2Copy
aaaabbaabb
Score : points
Problem Statement
Takahashi has a string of length consisting of lowercase English letters. On this string, he will perform the following operation times:
- Let be the string obtained by reversing , and be the string obtained by concatenating and in this order.
- Let be some contiguous substring of with length , and replace with .
Among the strings that can be the string after the operations, find the lexicographically smallest possible one.
Constraints
- consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
Print the lexicographically smallest possible string that can be the string after the operations.
Sample Input 1Copy
5 1 bacba
Sample Output 1Copy
aabca
When bacba
, abcab
, bacbaabcab
, and the optimal choice of is aabca
.
Sample Input 2Copy
10 2 bbaabbbaab
Sample Output 2Copy
aaaabbaabb