#P5420. Determining the Last Tree Label

    ID: 18652 Type: Default 1000ms 256MiB

Determining the Last Tree Label

Determining the Last Tree Label

s-quark loves the trees in Xiangshan and wants to distinguish each tree by a unique label. Each label is printed as a strip of at most N lowercase letters which is wrapped around the tree trunk. Because the label is placed in a circle, its starting position is lost. To solve that, for every label s-quark rules that the visible representation must be the lexicographically smallest rotation of the label. For example, even though the string aba may be seen on the tree, one can deduce that the intended label is aab because starting from the least rotation gives aab.

Moreover, if the lexicographically smallest rotation is not unique (for example, the label abab has two equivalent rotations even though one of them is the smallest), then s-quark will avoid using such a label. In other words, the labels that s-quark uses are exactly those strings (of length at least 1 and at most N) whose unique cyclic rotation (when arranged in a circle) is the lexicographically smallest. It turns out that these labels are exactly the Lyndon words over the 26‐letter alphabet.

s-quark has already ordered the trees. He intends to place the label S on the first tree, and then assign to the remaining trees the next valid labels in lexicographical order (according to the full set of valid labels, that is, all Lyndon words of length ≤ N). For example, when N = 3 and S = a, the labels used on the trees will be:

a, aab, aac, …, aaz, ab, abb, …, abz, ac, …

Given that there are K trees in total, your task is: if the first tree is labeled with S, determine the label that will be used on the last (i.e. the K-th) tree.


Note: A string w is called a Lyndon word if it is strictly smaller in lexicographical order than all of its non‐trivial rotations. For example, "aab" is a Lyndon word while "aa" or "aba" is not.

inputFormat

The input consists of two lines. The first line contains two integers N and K (1 ≤ N ≤ 5 is assumed so that brute force generation is feasible, and K is guaranteed to be valid within the total number of labels) separated by a space. The second line contains the string S which is the label assigned to the first tree. It is guaranteed that S is a valid label (i.e. a Lyndon word) with length at most N.

outputFormat

Output the label (a string) that will be assigned to the K-th tree.

sample

3 1
a
a