#C3888. Count Contiguous Substring Occurrences

    ID: 47364 Type: Default 1000ms 256MiB

Count Contiguous Substring Occurrences

Count Contiguous Substring Occurrences

You are given two strings S and P. Your task is to count the number of contiguous substrings in S that exactly match P. The matching is case sensitive and overlapping occurrences are allowed. For example, if S = "aaaa" and P = "aa", the answer is 3 (matches starting at positions 0, 1, and 2).

You can think of this problem mathematically as finding the number of indices i such that:

\(S[i:i+|P|] = P\)

where \(|P|\) represents the length of string P and the substring is taken from \(S\) starting at index \(i\). If P is longer than S, the answer is 0.

inputFormat

The input is provided via standard input (stdin) consisting of two lines:

  1. The first line contains the string S.
  2. The second line contains the pattern string P.

Both strings consist of printable characters.

outputFormat

Output a single integer to standard output (stdout) representing the number of contiguous substrings in S that exactly match P.

## sample
abracadabra
abra
2

</p>