Stronger Jovsi
Time limit1sMemory limit512 MB
Count the chains of palindromic substrings whose left ends strictly increase and right ends strictly decrease, modulo 998244353, for a string up to one million letters.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String matching, Prefix sum
- Solved
- No attempts yet
Problem
Jovsi is still a strong boy. Since childhood he loved machine guns and often imitated them, but for some reason he did not shout trtrtrt or bambambam. He shouted acacacacac.
Mr. Malnar is not impressed by Jovsi's strength. He is interested only in Jovsi's ability to solve problems. One day he gave Jovsi a stick with letters written from its left end to its right end.
Mr. Malnar finds symmetric sticks beautiful, so he is especially interested in palindrome pairs. A palindrome pair is an ordered pair of natural numbers with such that the word formed by the letters from position to position is a palindrome. A palindrome reads the same from left to right and from right to left.
Mr. Malnar then gives Jovsi a challenge. A challenge consists of a natural number and a sequence of palindrome pairs such that and .
Jovsi must be ready for any situation, so he wants to know how many different challenges he can receive from Mr. Malnar. Help Jovsi and print the number of different challenges modulo 998244353.
Input
The only line contains a word of lowercase English letters, the sequence of letters written on Mr. Malnar's stick. The word has at most one million characters.
Output
Print the number of different challenges modulo 998244353 on a single line.