atcoder#AGC037E. [AGC037E] Reversing and Concatenating
[AGC037E] Reversing and Concatenating
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.
5 1
bacba
aabca
When bacba
, abcab
, bacbaabcab
, and the optimal choice of is aabca
.
10 2
bbaabbbaab
aaaabbaabb