410248: GYM103993 C Reverse and Remove

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Reverse and Removetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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$$$):

  1. 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);
  2. 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.

Input

The 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.

Output

Print the resulting string after $$$k$$$ operations are performed.

ExamplesInput
6 2
ababbb
Output
ba
Input
13 4
bababbaaababb
Output
aaabb
Input
8 2
abaaabab
Output
aaab
Input
7 1
ababbab
Output
abbab
Input
3 1
bba
Output
b
Input
6 1
aababa
Output
abab
Note

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.

加入题单

上一题 下一题 算法标签: