Substring Problem

4.7

3 votes
Medium, Algorithms, String, KMP Algorithm, Hashing algorithm
Problem

You are given 3 strings A,B and S.

You have to count the number of substrings of S which contains both A and B as substring.

Note : A substring is a contiguous sequence of characters within a string. For example, the substrings of the string "abc" are "a", "b", "c", "ab", "bc" and "abc".

Input Format:

The first line contains the string A(1|A|100,000).

The second line contains the string B(1|B|100,000).

The third line contains the string S(1|S|200,000).

The strings will contain English lowercase letters only.

Output Format:

Print the answer in a single line.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

"cabc" has substrings which contain both "ab" and "c" as substring , which are "cab" , "cabc" and "abc".

Editor Image

?