Uncle, who is a very money-loving person, has resorted to compressing the strings to…
- User
Uncle, who is a very money-loving person, has resorted to compressing the strings to save the number of letters in his text messages.
Uncle's method for compression is as follows:
At first, he changed the numbers 1, 2, ..., k k chooses Then string your string into stacks k k divides a letter (the length of the string must be k k is divisible) and applies its permutation on each set of letters. Then it compresses the obtained string by the RLE method which will be explained later.
Apply permutation p p on a bunch of k k letter means letter p 1 p 1 M is placed in the first place, the word p 2 p 2 m in the second position and... for example, applying the permutation {2, 4, 1, 3} on the string a b c d abcd convert it to c a d b cadb does Apply this permutation by batching on the string a b c d e f g h abcdefgh, string c a d b g e h f results in cadbgehf.
The given permutation string is compressed by RLE (or run-length encoding). In order to avoid complex calculations, we consider the length of the compressed string to be equal to the number of groups of equal letters in a row. For example, the length of the string a a b c a a We consider aabcaa to be 4 after compression by RLE. (a 2-letter group a, a single-letter group b, a single-letter group c and a 2-letter group a)
Uncle wants to compress and send an SMS with the mentioned method. Obviously, the length of the final string depends on the selected permutation. With the text of your uncle's SMS, choose a replacement that minimizes the length of the SMS after compression and output this minimum length.
input The first line contains only numbers k k is
In the next line, Uncle's SMS is a string of lowercase English letters with a maximum length of 50,000.
2 ≤ k ≤ 16 2≤k≤16
output In the only output line, print a number that is equal to the smallest possible length for uncle's SMS.
Example Sample entry 1 4 abcabcabcabc Plain text Sample output 1 7 Plain text In this example, the optimal result is obtained by choosing the permutation {2, 3, 4, 1}. write in c++
- Assistant