This page is still under construction.

Parts of this page are still being built. What you see may change.

Coins

Time limit1sMemory limit128 MB

Summary
Given a string of O and R tosses, find the longest substring where the number of O equals k times the number of R.
Level

Medium6 of 10

Topics
Prefix sum, Hash map, Math
Solved
No attempts yet

Problem

Joe claims that he has telekinetic powers. This shocked Stan, a committed rationalist, who immediately asked Joe to prove it.

Joe decided to demonstrate his ability by tossing a coin. He says he can toss it so that heads come up exactly kk times as often as tails. Stan wrote down the result of every toss in order, and now he wants to find the longest run of consecutive tosses in which the number of heads is exactly kk times the number of tails.

Input

The first line contains two integers nn and kk (3≤n≤1063 \le n \le 10^6, 2≤k≤n−12 \le k \le n - 1). Here nn is the number of tosses Joe made, and kk has the meaning described above.

The second line contains a string of nn characters describing the outcome of each toss. Each character is either O for heads or R for tails.

Output

Print a single integer: the length of the longest run of consecutive tosses in which heads occur exactly kk times as often as tails. If no such run exists, print 00.

Hint

In the sample input, the tosses from position 5 through 12 and from position 6 through 13 each contain exactly 6 heads and 2 tails, that is, three times as many heads as tails. No longer consecutive run has this property, so the answer is 8.

Examples3

  1. Example 1

    Input
    15 3
    RORROOROOROOORO
    
    Expected output
    8
    
  2. Example 2

    Input
    3 2
    ORO
    
    Expected output
    3
    
  3. Example 3

    Input
    3 2
    OOO
    
    Expected output
    0