Little bear and strings
Practice
4 (2 votes)
Algorithms
Approved
Arrays
Data structures
Hard
Open
Problem
87% Success 2260 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Little bear has got a big string S as his birthday present. Also, he personally loves all those strings that start with T1 and end with T2, and calls them good. Now, he would like most the birthday present has maximum number of good substrings. Also, he is not the kind of "bear"(:P) that would easily get fooled by substrings with different start and end positions. He would only count a string once, irrespective of its number of occurences. More formally, he wants to determine the number of distinct good substrings.

Input:
The input file contains multiple test cases that end with EOF. Each test case comprises of 3 lines each containing S, T1 and T2 respectively.

Output:
Output the required answer in a new line for every test case.

Constraints:
1 ≤ |S| , |T1|, |T2| ≤ 300000
The maximum input file size is < 2 MB.

Note:
1. The input string contains only letters a-z.
2. A substring is any non-empty contiguous subsequence of given string. Read more here.
3. Two substrings s1 and s2 are different from one another if either their lengths are unequal or there is at least one index i such that s1[i] is not equal to s2[i]. This is irrespective of start and end points of substring.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
ApprovedArraysData StructuresHard
Points:50
6 votes
Tags:
AlgorithmsApprovedArraysData StructuresHardOpen
Points:50
10 votes
Tags:
ArraysData StructuresHardSegment TreesString Manipulation