#P3181. Counting Common Substrings
Counting Common Substrings
Counting Common Substrings
Given two strings, count the number of ways to pick one substring from each such that the two chosen substrings are identical. Two ways are considered different if and only if there is at least one position in the substring that differs between the two selections.
Let \(f_S(X)\) be the number of times a substring \(X\) appears in the first string and \(f_T(X)\) the number of times \(X\) appears in the second string. The answer is given by:
\[ \text{Answer} = \sum_{X} f_S(X) \times f_T(X), \]
Here, the summation is over all possible substrings \(X\>.
inputFormat
The input consists of two lines. The first line contains the first string, and the second line contains the second string.
Both strings consist of lowercase English letters.
outputFormat
Output a single integer — the number of pairs of substrings (one from each string) that are identical.
sample
abc
abc
6