Interesting celebrations
InterviewTime limit1sMemory limit1024 MB
Count the subsequences of string s that equal one of the words seq_1 to seq_26, modulo 998244353.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Problem
Every year the Myers family celebrates Halloween, and the celebrations start to feel repetitive. They want to vary the celebrations so Halloween does not get boring.
There are exactly known ways to celebrate Halloween, and the -th way can be denoted by the -th letter of the Latin alphabet (from a to z). The Myers family has celebrated Halloween for a long time and has kept records of how they celebrated each year.
They are curious how many subsequences of years (not necessarily contiguous) are interesting. There are exactly interesting sequences of celebration methods, defined as follows:
- <<
a>> - , where is the -th letter of the Latin alphabet.
So the first three interesting sequences are <<a>>, <<aba>>, and <<abacaba>>.
You are given a string , whose -th character is the celebration method in the -th year. Help the Myers family count the subsequences of that are interesting. Since the count can be very large, compute it modulo . A subsequence is a string obtained by deleting some, possibly zero, characters.
Input
The only line contains a string .
Output
Print the number of subsequences of this string that are of the form , modulo .
Hint
From the string <<abacaba>>, you can choose subsequences <<a>>, subsequences <<aba>>, and one subsequence <<abacaba>>.