#P1313E. Concatenation with intersection
Concatenation with intersection
No submission language available for this problem.
Description
Vasya had three strings , and , which consist of lowercase English letters. The lengths of strings and are equal to , the length of the string is equal to .
Vasya decided to choose a substring of the string , then choose a substring of the string and concatenate them. Formally, he chooses a segment () and a segment (), and after concatenation he obtains a string .
Now, Vasya is interested in counting number of ways to choose those segments adhering to the following conditions:
- segments and have non-empty intersection, i.e. there exists at least one integer , such that and ;
- the string is equal to the string .
The first line contains integers and () — the length of strings and and the length of the string .
The next three lines contain strings , and , respectively. The length of the strings and is , while the length of the string is .
All strings consist of lowercase English letters.
Print one integer — the number of ways to choose a pair of segments, which satisfy Vasya's conditions.
Input
The first line contains integers and () — the length of strings and and the length of the string .
The next three lines contain strings , and , respectively. The length of the strings and is , while the length of the string is .
All strings consist of lowercase English letters.
Output
Print one integer — the number of ways to choose a pair of segments, which satisfy Vasya's conditions.
Samples
Note
Let's list all the pairs of segments that Vasya could choose in the first example:
- and ;
- and ;
- and ;
- and ;