#P10694. [SNCPC2024] 双子序列

[SNCPC2024] 双子序列

Problem Description

Little L feels very uncomfortable when he sees strings he dislikes. He also feels uncomfortable when he sees them appear as subsequences.

Given a long string SS representing the text that Little L needs to read, and exactly two short strings s1s_1, s2s_2 representing the strings that Little L does not want to see. All three strings consist of lowercase letters.

Little L strongly dislikes having both of these strings appear in the text as subsequences at the same time. He defines the discomfort value of a string TT as: the product of the number of occurrences of s1s_1 as a subsequence of TT and the number of occurrences of s2s_2 as a subsequence of TT.

Since he will read every substring of SS, you now need to compute the sum of the discomfort values of all substrings of SS. Since the answer may be too large, you only need to output the result modulo 998244353998244353.

A string HH is a substring of TT if and only if HH can be obtained by deleting some characters from the beginning of TT and some characters from the end of TT (you may delete zero characters from the prefix/suffix, or delete the entire string to obtain the empty string).

A string HH is a subsequence of TT if and only if HH can be obtained by deleting some characters from TT (you may delete zero characters, or delete all characters to obtain the empty subsequence).

Input Format

The input consists of three lines, each containing a string of lowercase letters.

The first line is SS, the second line is s1s_1, and the third line is s2s_2. Here, 1S1×1051\le |S|\le 1\times 10^5, 1s1,s2201\le |s_1|,|s_2|\le 20.

Output Format

Output a single integer representing the computed answer.

iccpcicpc
icpc
ccpc

133

Hint

Substring start position Substring end position icpc count ccpc count
1 5 2 1
6
7 4 2
8
9 11 9
2 5 0 1
6
7 2
8
9 1 9
3 3
4 1
5
6 0

In all other substrings, the numbers of occurrences of the two strings as subsequences are both 00.

The answer is $(2\times 1) \times 2 + (4\times 2) \times 2 + 11\times 9 + (0\times 1)\times 2 + (0\times 2)\times 2 + 1\times 9 + 1\times 3 + (1\times 1)\times 2 + 1\times 0=133$.

Translated by ChatGPT 5