Олимпиадный тренинг

Задача 38869. Substring search


Задача

Темы:
In computer science, algorithms for finding the occurrence of a substring in a string play an important role. For example, in the string "ABRACADABRA" substring "BRA" meets¤ two times, and a substring of one character "A" meets five times. The number of occurrences is the number of ways to select several consecutive characters that match (in the same order) the desired substring. Found occurrences can overlap, that is, one character can be part of several occurrences.
Of interest are efficient algorithms for finding occurrences of a substring in a string, that is, algorithms that work quickly for large strings. Therefore, in this problem, we will consider the case when the original string is a multiple repetition of some small string.
For example, consider the string "MOM" and repeat it 3 times. The result will be the string "MAMAMAMAMAMA". In this line, the substring "AMA" occurs 5 times: "MAMAMAMAMAMA", "MAMAMAMAMAMA", "MAMAMAMAMAMA", "MAMAMAMA< u>AMAMA", "MAMAMAMAMAMA".
Answer the questions:
1. If the string "BAOBAB" repeat 100 times, then how many times will the substring "BA" occur in it?
2. If the string "REMARK" repeat 100 times, then how many times will the substring "AP" occur in it?
3. If the string "AUAUOAUAU" repeat 100 times, then how many times will the substring "AUAU" occur in it?
4. If the string "OHOY" repeat 100 times, how many times will the substring "YOYOY" occur in it?
5. If the string "A" repeat 100 times, then how many times will the substring "A" appear in it, repeated 50 times?
Write the answer to this task in the form of five numbers, each number on a separate line & nbsp; - answers   to the questions asked in that order. If you cannot find the answer to any of the five questions, write any natural number in this line.