Junpyo's Pebbles

Time limit1sMemory limit512 MB

Summary
Find the longest contiguous segment containing at most B black pebbles and at least W white pebbles.
Level

Medium6 of 10

Topics
Two pointers, Sliding window, Prefix sum
Solved
No attempts yet

Problem

NN pebbles stand in a row, numbered from 11 to NN. Each pebble is black or white.

Junpyo chooses one contiguous segment and picks up every pebble inside it. The segment may be empty, which means going straight home. Its length is the number of pebbles it contains.

A segment is valid when it holds at most BB black pebbles and at least WW white pebbles. If no valid segment exists, the answer is 00. Find the length of the longest valid segment.

Input

The first line contains NN, the upper bound BB for black pebbles, and the lower bound WW for white pebbles, separated by spaces.

The second line contains a string of length NN. Its ii-th character describes pebble ii: B means black and W means white.

Output

Print the length of the longest valid segment on one line. If no segment satisfies the conditions, print 00.

Examples2

  1. Example 1

    Input
    10 1 2
    WBBWWBWWBW
    
    Expected output
    5
    
  2. Example 2

    Input
    7 2 4
    WBBBBBW
    
    Expected output
    0