atcoder#AGC037E. [AGC037E] Reversing and Concatenating

[AGC037E] Reversing and Concatenating

Score : 13001300 points

Problem Statement

Takahashi has a string SS of length NN consisting of lowercase English letters. On this string, he will perform the following operation KK times:

  • Let TT be the string obtained by reversing SS, and UU be the string obtained by concatenating SS and TT in this order.
  • Let SS' be some contiguous substring of UU with length NN, and replace SS with SS'.

Among the strings that can be the string SS after the KK operations, find the lexicographically smallest possible one.

Constraints

  • 1N50001 \leq N \leq 5000
  • 1K1091 \leq K \leq 10^9
  • S=N|S|=N
  • SS consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

NN KK

SS

Output

Print the lexicographically smallest possible string that can be the string SS after the KK operations.

5 1
bacba
aabca

When S=S=bacba, T=T=abcab, U=U=bacbaabcab, and the optimal choice of SS' is S=S'=aabca.

10 2
bbaabbbaab
aaaabbaabb