410248: GYM103993 C Reverse and Remove
Description
Monocarp has a string $$$s$$$ of length $$$n$$$. The string consists of characters a and/or b.
Monocarp will apply the following operation to this string $$$k$$$ times ($$$2k < n$$$):
- if the first character of the string is different from the last character, then Monocarp reverses the string (so the first character becomes the last one, the second character becomes the second-to-last one, and so on);
- no matter what happens during the first step, Monocarp removes the first character and the last character.
You have to print the resulting string after these $$$k$$$ operations. Note that the constraints on $$$k$$$ guarantee that at least one character will remain in the string.
InputThe first line contains two integers $$$n$$$ and $$$k$$$ ($$$3 \le n \le 200\,000$$$, $$$1 \le k$$$, $$$2k < n$$$) — the length of the string and the number of operations Monocarp performes, respectively.
The second line contains the string $$$s$$$ consisting of $$$n$$$ characters a and/or b.
OutputPrint the resulting string after $$$k$$$ operations are performed.
ExamplesInput6 2 ababbbOutput
baInput
13 4 bababbaaababbOutput
aaabbInput
8 2 abaaababOutput
aaabInput
7 1 ababbabOutput
abbabInput
3 1 bbaOutput
bInput
6 1 aababaOutput
ababNote
In the first example, during the first operation, the string is reversed, so it becomes bbbaba. Then the first character and the last character are removed, so it becomes bbab. The string won't be reversed during the second operation, and after removing the first and the last character, it becomes ba.