#K51177. Count Substring Occurrences

    ID: 29030 Type: Default 1000ms 256MiB

Count Substring Occurrences

Count Substring Occurrences

Given two strings S and P, determine the number of times that the substring P occurs in S, including overlapping occurrences. For example, if S is "ababa" and P is "aba", then the answer is 2 because "aba" appears twice (with one occurrence overlapping the other).

The problem requires reading the input from standard input and writing the output to standard output.

Examples:

  • Input: ababa and aba → Output: 2
  • Input: aaaaa and aa → Output: 4
  • Input: abcdef and gh → Output: 0

inputFormat

The input consists of two lines:

  • The first line contains the string S.
  • The second line contains the string P.

outputFormat

Output a single integer representing the number of times the substring P appears in S (including overlapping occurrences).

## sample
ababa
aba
2