Filipp Rukhovich
Time limit6sMemory limit512 MB
Sum the palindromicity of every subsequence of a string, counting each occurrence of a subsequence, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Math, String
- Solved
- No attempts yet
Problem
The palindromicity of a sequence of characters of length is the number of indices such that and . Indexing is 0-based.
You are given a string . Count the sum of palindromicities over all its subsequences. Sequences that occur multiple times as a subsequence are counted multiple times. That is, you sum palindromicities over all subsequences, whether they are distinct or not.
Output the answer modulo . Formally, if the actual answer is and your answer is , it is considered correct when and is divisible by .
Input
The only line contains a non-empty string of lowercase Latin letters with length not exceeding .
Output
Output a single integer, the sum of palindromicities over all subsequences of modulo .