cswork / OAOpen practice workspace

SalesforceOA #22

Get Special Substring (MTS)

Estimated MediumJudge-ready

Topics (AI-labelled)Two Pointers

The 26-character charValue corresponds to a..z in order, where 0 marks a normal character and 1 marks a special character. Find the length of the longest contiguous substring of s in which normal characters occur at most k times; repeated normal characters are counted by occurrences.

Input

The input has three lines: s, k, charValue. Original bounds: 1≤|s|≤100000, s consists of a..z, and charValue has length 26 and contains only 0/1; the original "length of k" is a typo for an integer parameter, so this site specifies 1≤k≤|s|.

Output

Output one integer answer.

Example 1

Input:

giraffe
2
01111001111111111011111111

Output:

3

Example 2

Input:

special
1
00000000000000000000000000

Output:

1

Example 3

Input:

abcde
1
10101111111111111111111111

Output:

3

Example notes

The outputs of the three public examples are, in order: 3; 1; 3. They have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…