#arc171f. F - Both Reversible
F - Both Reversible
Score: points
问题陈述
当一个字符串 满足以下条件时,我们称它为一个好字符串:
- 存在一对字符串 满足以下所有条件:
- 和 都不为空。
- 。
- 和 都是回文。
这里, 表示按顺序连接字符串 和 形成的字符串。 同时, 表示将字符串 中的字符顺序反转形成的字符串。
存在一个长度为 的字符串 ,由小写英文字母和字符 ?
组成。
在将 中的 ?
替换为小写英文字母的 种方式中,有多少种会得到一个好字符串?找出这个计数,并对 取模。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
A string is called a good string when it satisfies the following condition:
- There is a pair of strings that satisfies all of the following:
- Both and are non-empty.
- .
- Both and are palindromes.
Here, denotes the string formed by concatenating strings and in this order.
Also, denotes the string formed by reversing the order of the characters in string .
There is a string of length consisting of lowercase English letters and the character ?
.
Among the ways to replace the ?
s in with lowercase English letters, how many result in a good string? Find the count modulo .
Constraints
- is a string of length consisting of lowercase English letters and
?
.
Input
The input is given from Standard Input in the following format:
Output
Print the number, modulo , of ways to replace the characters that satisfy the condition in the problem statement.
Sample Input 1
4
?ba?
Sample Output 1
1
The string abab
is good, because if we set ab
and ab
, then abab
, and both abba
and baab
are palindromes.
Among the strings that can be formed by replacing the ?
s in with lowercase English letters, there is only one good string, which is abab
.
Sample Input 2
10
?y?x?x????
Sample Output 2
676
Sample Input 3
30
???a?????aab?a???c????c?aab???
Sample Output 3
193994800
Sample Input 4
36
????????????????????????????????????
Sample Output 4
363594614