#P17236. 『STA - R10』刷墙墙刷
『STA - R10』刷墙墙刷
Background
Alice is a rabbit who likes symmetry.
Now she appoints you to help paint a wall.

There is a wall now, and string represents the color at each position.
The desired result is represented by string . The character set is lowercase letters.
You may perform any number of operations. Each time, choose a sub-interval of with length and a string with length , and assign that interval to be .
For efficiency reasons, the you choose must satisfy .
For symmetry reasons, the string you choose must be an odd-length palindrome.
If you can finish this task, you will get a reward of “feilin” (pinyin: 菲林)!
Alice has fixed the colors of some positions, and marks the unfixed ones with ?. You want to know how many possible values of allow you to get the reward.
Alice reminds you that this number is too large, so you decide to take it modulo .
Problem Description
Formal statement:
The character set is lowercase letters.
Given strings of length , define one operation as choosing a sub-interval of whose length is odd and , and assigning it to be a palindrome string.
If can be transformed into through a finite number of operations, then is called “good”.
Now you are given and a string consisting of lowercase letters and ? (note that the number of ? can be any integer in ). If each ? in can be replaced by any lowercase letter, how many possible assignments make “good”?
Output the answer modulo .
Input Format
The first line contains a positive integer , the length of the strings.
The second line contains a string of length , consisting only of lowercase letters.
The third line contains a string of length , consisting of lowercase letters and ?.
Output Format
Output one integer, the number of valid assignments modulo .
5
alice
alic?
2
Hint
This problem uses bundled testdata.
::cute-table{tuack}
| Subtask | | Special Property | Score |
|:-:|:-:|:-:|:-:|
| | | None | |
| | | contains only lowercase letters | |
| | | contains only ? | |
| | | None | |
| | | None | |
Translated by ChatGPT 5