#Q49. 「一本通 2.2 练习 3」似乎在梦中见过的样子
「一本通 2.2 练习 3」似乎在梦中见过的样子
Description
Original source: 2014 Hubei Provincial Team Selection Test Week2
"Madoka, don't trust QB!" With Homura's desperate cry, Madoka formed a contract with QB.
This was one of Madoka's nightmares and also an event from the previous timeline. To prevent Madoka from forming a contract with QB this time, Homura decided to eliminate QB on the very first day of school. However, QB has many avatars (though episode 8 suggests it might be infinitely respawning). Nevertheless, the determined Homura will not give up—she resolves to destroy everything that could possibly be QB. Now, she has sensed the nearby conditions and converted them into a string of length , which she has given to you, an OI student.
From her words, you now know that all substrings of the form are QB or its avatars, where and (substrings at different positions but otherwise identical are considered distinct, while substrings at the same position but split differently are considered the same). You must quickly tell Homura the answer—the count of QB and its avatars.
Note: For a string , denotes the length of .
Input Format
The first line contains a string , and the second line contains an integer .
Output Format
Only one line with an integer , representing the count of QB and its avatars.
Sample 1
aaaaa
1
6
Sample 2
abcabcabc
2
8
Data Range and Hints
For all data, , , and the character set consists of all lowercase letters.