eolymp
bolt
Try our new interface for solving problems
Problems

Pattern Matching

Pattern Matching

\textit{Pattern} is a nonempty string that may contain lowercase letters of the Latin alphabet and the special character '\textbf{*}' (star). We will say that a string \textbf{T} \textit{matches} the pattern \textbf{P} if and only if there is a way to replace the stars in \textbf{P} with (possibly empty) sequences of lowercase letters so that the result equals \textbf{T}. For example, the string \textbf{aadbc} matches the pattern \textbf{a*b*c}, as we can obtain the string from the pattern by replacing the first star in the pattern with \textbf{ad} and the second one with the empty string. On the other hand, the string \textbf{abcbcb} does not match this pattern. Given a non-empty string \textbf{S} count the number of cyclic shifts of \textbf{S} that match the given pattern \textbf{P}. \InputFile The first line of input contains the pattern \textbf{P} (\textbf{1} to \textbf{100} characters long). The second line contains the string \textbf{S} (\textbf{1} to \textbf{100000 characters long}). \OutputFile The output should consist of a single integer, the number of cyclic shifts of \textbf{S} that match the pattern \textbf{P}.
Time limit 5 seconds
Memory limit 256 MiB
Input example #1
aaaa
aaaa
Output example #1
4
Source NEERC Western Subregional Contest 2012