#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 aa represents the color at each position.
The desired result is represented by string bb. The character set is lowercase letters.

You may perform any number of operations. Each time, choose a sub-interval of aa with length LL and a string cc with length LL, and assign that interval to be cc.
For efficiency reasons, the LL you choose must satisfy L3L \ge 3.
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 220220 “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 bb allow you to get the reward.
Alice reminds you that this number is too large, so you decide to take it modulo 998244353998244353.

Problem Description

Formal statement:
The character set is lowercase letters.
Given strings a,ba, b of length nn, define one operation as choosing a sub-interval [l,r][l, r] of aa whose length is odd and 3\ge 3, and assigning it to be a palindrome string.
If aa can be transformed into bb through a finite number of operations, then aa is called “good”.

Now you are given aa and a string bb consisting of lowercase letters and ? (note that the number of ? can be any integer in [0,n][0, n]). If each ? in bb can be replaced by any lowercase letter, how many possible assignments make aa “good”?

Output the answer modulo 998244353998244353.

Input Format

The first line contains a positive integer nn, the length of the strings.
The second line contains a string aa of length nn, consisting only of lowercase letters.
The third line contains a string bb of length nn, consisting of lowercase letters and ?.

Output Format

Output one integer, the number of valid assignments modulo 998244353998244353.

5
alice
alic?

2

Hint

This problem uses bundled testdata.

::cute-table{tuack} | Subtask | nn\le | Special Property | Score | |:-:|:-:|:-:|:-:| | 11 | 55 | None | 1010 | | 22 | 10510^5 | bb contains only lowercase letters | 1010 | | 33 | 10510^5 | bb contains only ? | 2020 | | 44 | 2×1032 \times 10^3 | None | 2020 | | 55 | 10610^6 | None | 4040 |

Translated by ChatGPT 5