All problems

Problem 843

Maximum Number of Vowels in a Substring of Given Length

Medium · 20 pts · String, Sliding Window

Problem

Find the largest number of vowels (a, e, i, o, u) in any block of exactly K consecutive characters of S. Slide a window of length K across the string: count the vowels in the first window, then for every step add one if the entering character is a vowel and subtract one if the leaving character is a vowel, keeping the maximum. This takes O(N) time.

Input

The first line contains S (lowercase letters). The second line contains K.

Output

Print the maximum number of vowels in a substring of length K.

Constraints

1 <= K <= |S| <= 100000

Example input

abciiidef
3

Example output

3

Explanation

In abciiidef with K = 3, the window iii contains 3 vowels, the most possible. So the answer is 3.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Vowels of All Substrings Next: Push Dominoes