cho.sh
Notes
Loading...

Colored Balls

Time limit

2s

Memory limit

128 MB

Problem

Gyuwan has N balls arranged from left to right. The color of each ball is represented by one uppercase English letter.

Repeat the following process until every ball has been removed.

  1. Among the balls that remain, find the longest consecutive group of balls with the same color.
  2. If several such groups have the maximum length, choose the leftmost one.
  3. Remove all balls in the chosen group.

Determine on which operation the ball that was initially the k-th from the left is removed.

Input

The first line contains the number of balls N and the index k of the ball whose removal time must be found.

The second line contains a string of length N. Each character is an uppercase English letter describing the color of the ball at that position.

Constraint: 1 ≤ k ≤ N ≤ 10,000,000

Output

Print the operation number on which the ball that was initially the k-th from the left is removed.

Hint

After a group is removed, the remaining groups on its two sides may become adjacent. If they have the same color, they form one longer group, and later operations use this merged length when choosing the next group.