#P9543. Meaningful Diary Strings
Meaningful Diary Strings
Meaningful Diary Strings
Little M has a string \(S\) of length \(n\) and an important information string \(T\) of length \(m\). She decides to write her diary by choosing a prefix \(P\) of \(S\) (possibly empty) and a suffix \(Q\) of \(S\) (possibly empty), and then concatenating them to form the diary content \(A = P+Q\). There are \(n+1\) choices for a prefix and \(n+1\) choices for a suffix, so there are \((n+1)^2\) ways to form \(A\) (note that different ways may yield the same string, but here every pair \((P,Q)\) gives a unique string because the prefix is defined by its length and likewise the suffix).
However, Little M only considers a diary entry "meaningful" if it contains the string \(T\) as a substring. Even if a meaningful string can be produced by several different choices of prefix and suffix, it is only counted once.
Your task is to count how many distinct meaningful strings Little M can form in this way.
Note: A string \(X\) is a substring of \(A\) if it appears in \(A\) consecutively. The diary string is obtained by \(A = P+Q\), where \(P\) is a prefix of \(S\) and \(Q\) is a suffix of \(S\). The empty string is considered as both a prefix and a suffix.
Hint: The important occurrence of \(T\) in \(A\) might lie entirely in \(P\), entirely in \(Q\) or it may span the boundary between \(P\) and \(Q\). In the last case, there exists an integer \(k\) with \(1 \le k \le m-1\) such that the last \(k\) characters of \(P\) equal \(T[0:k]\) and the first \(m-k\) characters of \(Q\) equal \(T[k:m]\).
inputFormat
The first line contains a non-empty string \(S\).
The second line contains a non-empty string \(T\).
It is guaranteed that \(S\) and \(T\) consist of only lowercase English letters.
outputFormat
Output a single integer denoting the number of distinct meaningful strings that can be produced.
sample
abc
ab
11