There are several strange rooms in Binary Casino and one of them is a locker room. You have to enter the locker room several times a day, two times being a minimum (before and after your shift). There is no key or access code needed to enter the locker room. There is a brand new security lock system instead.
The lock system presents you with a generated puzzle which you have to solve every time you want to enter the locker room. This system prevents possible intruders to enter the locker room, as the puzzle takes them a long time to solve. Only employees, after working in the casino for some time, manage to master the puzzle.
It is your second week in the casino and you have already been late three times because you didn't manage to solve the puzzle quickly enough. You therefore decided to write a program which solves the puzzle. The puzzle is as follows:
You are given a cyclic string of
For example, let acdb
be the given string of length acd
and bac
to mark the whole string. The puzzle solution is bac
.
Input Specification
The first line of input contains two integers
Output Specification
Output the lexicographically maximal substring among chosen substrings under the condition the result is lexicographically minimal possible.
Sample Input 1
4 3
acdb
Sample Output 1
bac
Sample Input 2
6 2
aababa
Sample Output 2
ab
Sample Input 3
10 4
abaaabaaba
Sample Output 3
aaba
Comments