AtCoder Grand Contest 037
E
Reversing and Concatenating
AtCoder
⌀ 2667
原题
← DF →
翻译中…

Problem Statement

翻译中…

Takahashi has a string $S$ of length $N$ consisting of lowercase English letters. On this string, he will perform the following operation $K$ times:

翻译中…
  • Let $T$ be the string obtained by reversing $S$, and $U$ be the string obtained by concatenating $S$ and $T$ in this order.
  • Let $S'$ be some contiguous substring of $U$ with length $N$, and replace $S$ with $S'$.
翻译中…

Among the strings that can be the string $S$ after the $K$ operations, find the lexicographically smallest possible one.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 5000$
  • $1 \leq K \leq 10^9$
  • $|S|=N$
  • $S$ consists of lowercase English letters.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N K
S

翻译中…

Output

翻译中…

Print the lexicographically smallest possible string that can be the string $S$ after the $K$ operations.

翻译中…

样例

Input #1
5 1
bacba
Output #1
aabca
When $S=$`bacba`, $T=$`abcab`, $U=$`bacbaabcab`, and the optimal choice of $S'$ is $S'=$`aabca`.
Input #2
10 2
bbaabbbaab
Output #2
aaaabbaabb
题目信息
题号
agc037_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。