A choir director writes down a row of seat codes as a string of lowercase letters. Any seat whose code is one of the vowels a, e, i, o, u belongs to the soprano family; every other seat belongs to the alto family. Given a tuning number k, a contiguous block of seats is called acoustically balanced when (1) the block contains exactly as many soprano-family seats as alto-family seats, and (2) the product of the soprano-family count and the alto-family count in that block is divisible by k. Count how many contiguous blocks of the row are balanced.
Print a single integer: the number of balanced contiguous blocks of s.
Example 1
Input
baeb 1
Expected
3
Explanation
s = "baeb" has seats b(alto), a(soprano), e(soprano), b(alto). With k=1 every substring with equal soprano/alto counts qualifies automatically. "ba" (1 soprano, 1 alto) and "eb" (1 soprano, 1 alto) each qualify, and the full string "baeb" (2 soprano, 2 alto) also qualifies. No other substring has equal counts. Total: 3.
Example 2
Input
iouqz 2
Expected
1
Explanation
s = "iouqz" has seats i,o,u (soprano) then q,z (alto). The only substrings with equal soprano/alto counts are "uq" (1 soprano, 1 alto; product 1, not divisible by 2 -- rejected) and "ouqz" (2 soprano, 2 alto; product 4, divisible by 2 -- accepted). Total: 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →