CF1537E1.Erase and Extend (Easy Version)

传统题 时间 2000 ms 内存 256 MiB 8 尝试 3 已通过 1 标签

Erase and Extend (Easy Version)

This is the easy version of the problem. The only difference is the constraints on nn and kk. You can make hacks only if all versions of the problem are solved.

You have a string ss, and you can do two types of operations on it:

  • Delete the last character of the string.
  • Duplicate the string: s:=s+ss:=s+s, where ++ denotes concatenation.

You can use each operation any number of times (possibly none).

Your task is to find the lexicographically smallest string of length exactly kk that can be obtained by doing these operations on string ss.

A string aa is lexicographically smaller than a string bb if and only if one of the following holds:

  • aa is a prefix of bb, but aba\ne b;
  • In the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

Input

The first line contains two integers nn, kk (1n,k50001 \leq n, k \leq 5000) — the length of the original string ss and the length of the desired string.

The second line contains the string ss, consisting of nn lowercase English letters.

Output

Print the lexicographically smallest string of length kk that can be obtained by doing the operations on string ss.

Note

In the first test, it is optimal to make one duplication: "dbcadabc" \to "dbcadabcdbcadabc".

In the second test it is optimal to delete the last 33 characters, then duplicate the string 33 times, then delete the last 33 characters to make the string have length kk.

"abcd" \to "abc" \to "ab" \to "a" \to "aa" \to "aaaa" \to "aaaaaaaa" \to "aaaaaaa" \to "aaaaaa" \to "aaaaa".

Samples

8 16
dbcadabc
dbcadabcdbcadabc
4 5
abcd
aaaaa

在线编程 IDE

建议全屏模式获得最佳体验