10251: CF EDU - Two Pointer Method - Step 3 - G. Not Very Rude Substring
[Creator : ]
Description
You are given a string $s$, consisting of $n$ lowercase English letters.
Rudeness of a string $t$ of length $k$ is the number of pairs of integers $(i,j)$, where $1≤i<j≤k$, for which $t_i=$«a» and $t_j=$«b». In other words, the rudeness of a string is the number of ways to delete all but two of its characters, so that the string «ab» remains.
Your task is to find a substring $s_ls_{l+1}…s_r$, the rudeness of which does not exceed $c$, of maximum length.
Input
The first line of the input contains two integers $n, c\ (1≤n≤10^6,\ 0≤c≤10^{18})$.
The second line contains the string $s$. The string consists of $n$ lowercase English letters.
Output
Print a single integer, the maximum length of a substring of a string that has rudeness at most $c$.
Sample 1 Input
3 1
aab
Sample 1 Output
2
Sample 2 Input
6 2
aabcbb
Sample 2 Output
4