#C10286. Substring Occurrences Counter

    ID: 39474 Type: Default 1000ms 256MiB

Substring Occurrences Counter

Substring Occurrences Counter

Given two strings \(S_1\) and \(S_2\), count the number of times \(S_2\) appears as a substring in \(S_1\). Occurrences can overlap. Note that if \(S_2\) is an empty string, the result is defined as \(|S_1| + 1\), because an empty string is found at the beginning, between every character, and at the end of \(S_1\). For example, if \(S_1 = \texttt{ababab}\) and \(S_2 = \texttt{ab}\), the answer is 3.

Input strings can be empty, and the comparison should be case-sensitive.

inputFormat

The input consists of two lines:

  • The first line contains the string \(S_1\).
  • The second line contains the string \(S_2\).

Both strings may be empty. Input is provided through stdin.

outputFormat

Output a single integer representing the count of occurrences of \(S_2\) in \(S_1\) as described above. The result should be printed to stdout.

## sample
hellohello
lo
2