Under construction

Still being built. Things may change

Vera and LCS

Time limit2sMemory limit256 MB

Summary
Given string A and target K, find the smallest i where A's prefix of length i plus N-i copies of A's least frequent letter has LCS exactly K with A.
Level

Medium7 of 10

Topics
String, Dynamic programming, Greedy
Solved
No attempts yet

Problem

Vera is studying the longest common subsequence (LCS) problem.

A string is a sequence of lowercase letters and may be empty. A subsequence of a string SS is what is left after deleting some letters of SS, possibly none of them and possibly all of them. For example vra, a, the empty string, and vera are all subsequences of vera. A longest common subsequence of two strings AA and BB is a string that is a subsequence of both and is as long as possible. Two strings can have several longest common subsequences. Since ea is a longest common subsequence of vera and eats, the LCS length of that pair is 2.

Vera's homework gave her two strings AA and BB, both of length NN, and asked for the LCS length of AA and BB. She wrote the answer KK and then lost BB. You are given AA and KK. Find a string BB of length NN whose LCS length with AA is exactly KK. Vera may have made a mistake, in which case no such BB exists.

Input

The input has the following format.

N K
A
  • 1≤N≤20001 \le N \le 2000
  • 0≤K≤20000 \le K \le 2000
  • NN and KK are integers
  • AA consists of NN lowercase letters

Output

Several strings can have LCS length KK with AA, so only the string fixed by the following rule is accepted.

Let cc be the letter that occurs the fewest times in AA. If several letters tie, take the alphabetically smallest of them. A letter that never occurs in AA occurs 0 times. For i=0,1,…,Ni = 0, 1, \dots, N let BiB_i be the first ii letters of AA followed by N−iN - i copies of cc. Find the smallest ii such that the LCS length of AA and BiB_i is exactly KK, and print BiB_i on one line. If no such ii exists, print WRONGANSWER.

Notes

Whether a valid BB exists is not decided by NN and KK alone. It also depends on how many times each letter occurs in AA.

Examples2

  1. Example 1

    Input
    4 2
    vera
    
    Expected output
    vebb
    
  2. Example 2

    Input
    4 5
    vera
    
    Expected output
    WRONGANSWER