#P10694. Substring Disgust Sum
Substring Disgust Sum
Substring Disgust Sum
Little L feels discomfort when he sees strings he dislikes – even if they appear as subsequences! You are given a long string \(S\) that Little L has to read, and exactly two short strings \(s_1\) and \(s_2\) that he dislikes. All three strings consist of lowercase letters.
For any string \(T\), define its disgust as:
\[ \text{disgust}(T)=\big( \#\text{ times } s_1 \text{ appears as a subsequence of } T \big) \times \big( \#\text{ times } s_2 \text{ appears as a subsequence of } T \big). \]Little L must read every substring of \(S\). A string \(H\) is called a substring of \(T\) if it can be obtained by removing some (possibly none or all) characters from the beginning and some (possibly none or all) characters from the end of \(T\). Note that the empty string is considered a substring.
A string \(H\) is called a subsequence of \(T\) if it can be obtained by deleting some (possibly none or all) characters from \(T\) (the empty subsequence is also allowed).
Your task is to compute the sum of the disgust values of all substrings of \(S\) and output the answer modulo \(998244353\).
inputFormat
The input consists of three lines:
- The first line contains the string \(S\).
- The second line contains the string \(s_1\).
- The third line contains the string \(s_2\).
It is guaranteed that all strings consist of lowercase letters.
outputFormat
Output a single integer: the sum of the disgust values of all substrings of \(S\) modulo \(998244353\).
sample
abc
a
b
2