#C252. Count 'ab' Occurrences in Repeated String
Count 'ab' Occurrences in Repeated String
Count 'ab' Occurrences in Repeated String
Given a string (s) and an integer (n), construct a new string by repeating (s) until its length reaches (n) (if necessary, take only the first few characters of an extra copy so that the final string has exactly (n) characters). Your task is to count the number of occurrences of the substring 'ab' in the resulting string.
Formally, if (L = |s|), then the resulting string (T) is defined as follows:
(T = s \times \left\lfloor \frac{n}{L} \right\rfloor + s[0:(n \bmod L)]).
Count how many times the pattern "ab" appears in (T).
inputFormat
The input is read from standard input. The first line contains the string (s). The second line contains the integer (n), the desired length of the repeated string.
outputFormat
Output a single integer, which is the count of occurrences of the substring "ab" in the repeated string.## sample
abab
10
5