Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
縦 N マス、横 N マスのチェス盤があります。チェス盤の上から i 行目、左から j 列目のマスを (i, j) と呼びます。
これから駒を盤に並べます。駒は 2 種類あり、それぞれ ルーク, ポーン と呼びます。
駒の並び方が次の条件を満たすとき 良い配置 と呼びます。
- 1 つのマスにつき 0 個または 1 個の駒が置かれている。
- (i, j) にルークがあるとき、k \neq j であるすべての k (1 \leq k \leq N) に対して (i, k) に駒が存在しない。
- (i, j) にルークがあるとき、k \neq i であるすべての k (1 \leq k \leq N) に対して (k, j) に駒が存在しない。
- (i, j) にポーンがあり、かつ i \geq 2 であるとき、(i-1, j) に駒が存在しない。
A 個のルークと B 個のポーンを良い配置になるように全て盤に並べることは可能ですか?
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1 \leq T \leq 10^5
- 1 \leq N \leq 10^4
- 0 \leq A, B
- 1 \leq A + B \leq N^2
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。ここで、\mathrm{case}_i は i 番目のケースを意味する。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
各テストケースは以下の形式で与えられる。
N A B
出力
T 行出力せよ。i 行目では i 番目のテストケースに対する答えを出力せよ。
各テストケースでは、良い配置になるように並べることが可能ならば Yes を、そうでない場合は No を出力せよ。
入力例 1
8 5 2 3 6 5 8 3 2 2 11 67 40 26 22 16 95 91 31 80 46 56 998 2 44353
出力例 1
Yes No No No Yes No Yes Yes
1 番目のテストケースでは、例えばルークを (1, 1) と (2, 4) に、ポーンを (3, 3) と (4, 2) と (5, 3) に配置することで全ての駒を良い配置になるように並べることが可能です。
2 番目のテストケースでは、全ての駒を良い配置になるように並べることは不可能です。
Score: 400 points
Problem Statement
There is a chessboard with N rows and N columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left.
You will now place pieces on the board. There are two types of pieces, called rooks and pawns.
A placement of pieces is called a good arrangement when it satisfies the following conditions:
- Each square has zero or one piece placed on it.
- If there is a rook at (i, j), there is no piece at (i, k) for all k (1 \leq k \leq N) where k \neq j.
- If there is a rook at (i, j), there is no piece at (k, j) for all k (1 \leq k \leq N) where k \neq i.
- If there is a pawn at (i, j) and i \geq 2, there is no piece at (i-1, j).
Is it possible to place all A rooks and B pawns on the board in a good arrangement?
You are given T test cases; solve each of them.
Constraints
- 1 \leq T \leq 10^5
- 1 \leq N \leq 10^4
- 0 \leq A, B
- 1 \leq A + B \leq N^2
- All input values are integers.
Input
The input is given from Standard Input in the following format. Here, \mathrm{case}_i represents the i-th case.
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
Each test case is given in the following format.
N A B
Output
Print T lines. The i-th line should contain the answer for the i-th test case.
For each test case, print Yes if it is possible to place the pieces in a good arrangement and No otherwise.
Sample Input 1
8 5 2 3 6 5 8 3 2 2 11 67 40 26 22 16 95 91 31 80 46 56 998 2 44353
Sample Output 1
Yes No No No Yes No Yes Yes
In the first test case, for example, you can place rooks at (1, 1) and (2, 4), and pawns at (3, 3), (4, 2), and (5, 3) to have all the pieces in a good arrangement.
In the second test case, it is impossible to place all the pieces in a good arrangement.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 600 点
問題文
(1, 2, \dots, N) の順列 P = (P_1, P_2, \dots, P_N) に対して F(P) を次の手順によって定義します。
-
数列 B = (1, 2, \dots, N) がある。
B_i \lt P_{B_i} を満たす整数 i が存在する間、次の操作を行う。- B_i \lt P_{B_i} を満たす整数 i のうち最小のものを j とおく。そして、B_j を P_{B_j} に置き換える。
長さ N の数列 A = (A_1, A_2, \dots, A_N) が与えられます。 (1,2,\dots,N) の順列 P であって F(P) = A を満たすものは何個ありますか?答えを 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
F(P) = A を満たす順列 P の個数を 998244353 で割った余りを出力せよ。
入力例 1
4 3 3 3 4
出力例 1
1
例えば P = (2, 3, 1, 4) とする時、 F(P) は以下の手順で (3, 3, 3, 4) に決定します。
- はじめ、B = (1, 2, 3, 4) である。
- B_i \lt P_{B_i} を満たす整数 i のうち最小のものは 1 である。B_1 を P_{B_1} = 2 に置き換えて、B = (2, 2, 3, 4) となる。
- B_i \lt P_{B_i} を満たす整数 i のうち最小のものは 1 である。B_1 を P_{B_1} = 3 に置き換えて、B = (3, 2, 3, 4) となる。
- B_i \lt P_{B_i} を満たす整数 i のうち最小のものは 2 である。B_2 を P_{B_2} = 3 に置き換えて、B = (3, 3, 3, 4) となる。
- B_i \lt P_{B_i} を満たす i は存在しないので、操作を終了する。この時点での B = (3, 3, 3, 4) を F(P) として定義する。
F(P) = A を満たす順列 P は (2, 3, 1, 4) の 1 通りのみです。
入力例 2
4 2 2 4 3
出力例 2
0
入力例 3
8 6 6 8 4 5 6 8 8
出力例 3
18
Score: 600 points
Problem Statement
For a permutation P = (P_1, P_2, \dots, P_N) of (1, 2, \dots, N), we define F(P) by the following procedure:
-
There is a sequence B = (1, 2, \dots, N).
As long as there is an integer i such that B_i \lt P_{B_i}, perform the following operation:- Let j be the smallest integer i that satisfies B_i \lt P_{B_i}. Then, replace B_j with P_{B_j}.
You are given a sequence A = (A_1, A_2, \dots, A_N) of length N. How many permutations P of (1,2,\dots,N) satisfy F(P) = A? Find the count modulo 998244353.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
Output
Print the number, modulo 998244353, of permutations P that satisfy F(P) = A.
Sample Input 1
4 3 3 3 4
Sample Output 1
1
For example, if P = (2, 3, 1, 4), then F(P) is determined to be (3, 3, 3, 4) by the following steps:
- Initially, B = (1, 2, 3, 4).
- The smallest integer i such that B_i \lt P_{B_i} is 1. Replace B_1 with P_{B_1} = 2, making B = (2, 2, 3, 4).
- The smallest integer i such that B_i \lt P_{B_i} is 1. Replace B_1 with P_{B_1} = 3, making B = (3, 2, 3, 4).
- The smallest integer i such that B_i \lt P_{B_i} is 2. Replace B_2 with P_{B_2} = 3, making B = (3, 3, 3, 4).
- There are no more i that satisfy B_i \lt P_{B_i}, so the process ends. The current B = (3, 3, 3, 4) is defined as F(P).
There is only one permutation P such that F(P) = A, which is (2, 3, 1, 4).
Sample Input 2
4 2 2 4 3
Sample Output 2
0
Sample Input 3
8 6 6 8 4 5 6 8 8
Sample Output 3
18
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 600 点
問題文
頂点に 1 から N までの番号がついた N 頂点の木があります。i 番目の辺は頂点 u_i と頂点 v_i を結んでいます。
また、1 から N までの番号がついた N 個の駒があります。はじめ駒 i は頂点 i に置かれています。
あなたは次の操作を 0 回以上好きな回数行うことができます。
- 辺を 1 本選ぶ。辺の両端点を頂点 u, v として、頂点 u に載っている駒と頂点 v に載っている駒を入れ替える。その後、選んだ辺を削除する。
頂点 i に載っている駒を a_i とします。操作を全て終了した時点における数列 (a_1, a_2, \dots, a_N) としてあり得るものは何個ありますか?答えを 998244353 で割った余りを求めてください。
制約
- 2 \leq N \leq 3000
- 1 \leq u_i \lt v_i \leq N
- 入力で与えられるグラフは木
入力
入力は以下の形式で標準入力から与えられる。
N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}
出力
(a_1, a_2, \dots, a_N) としてあり得るものの個数を 998244353 で割った余りを出力せよ。
入力例 1
3 1 2 2 3
出力例 1
5
例えば以下の手順により (a_1, a_2, a_3) = (2, 1, 3) を得ることが出来ます。
- 1 番目の辺を選び、頂点 1 と頂点 2 に載っている駒を入れ替えて辺を削除する。(a_1, a_2, a_3) = (2, 1, 3) になる。
- 操作を終了する。
また、以下の手順により (a_1, a_2, a_3) = (3, 1, 2) を得ることが出来ます。
- 2 番目の辺を選び、頂点 2 と頂点 3 に載っている駒を入れ替えて辺を削除する。(a_1, a_2, a_3) = (1, 3, 2) になる。
- 1 番目の辺を選び、頂点 1 と頂点 2 に載っている駒を入れ替えて辺を削除する。(a_1, a_2, a_3) = (3, 1, 2) になる。
- 操作を終了する。
操作によって得られる数列は次の 5 通りです。
- (1, 2, 3)
- (1, 3, 2)
- (2, 1, 3)
- (2, 3, 1)
- (3, 1, 2)
入力例 2
5 2 5 3 4 1 3 1 5
出力例 2
34
入力例 3
8 4 5 2 5 3 6 1 3 1 8 2 7 2 8
出力例 3
799
Score: 600 points
Problem Statement
There is a tree with N vertices numbered 1 to N. The i-th edge connects vertices u_i and v_i.
Additionally, there are N pieces numbered 1 to N. Initially, piece i is placed on vertex i.
You can perform the following operation any number of times, possibly zero:
- Choose one edge. Let vertices u and v be the endpoints of the edge, and swap the pieces on vertices u and v. Then, delete the chosen edge.
Let a_i be the piece on vertex i. How many different possible sequences (a_1, a_2, \dots, a_N) exist when you finish performing the operation? Find the count modulo 998244353.
Constraints
- 2 \leq N \leq 3000
- 1 \leq u_i \lt v_i \leq N
- The graph given in the input is a tree.
Input
The input is given from Standard Input in the following format:
N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}
Output
Print the number, modulo 998244353, of possible sequences (a_1, a_2, \dots, a_N).
Sample Input 1
3 1 2 2 3
Sample Output 1
5
For example, the sequence (a_1, a_2, a_3) = (2, 1, 3) can be obtained by the following steps:
- Choose the first edge, swap the pieces on vertices 1 and 2, and delete the edge. This results in (a_1, a_2, a_3) = (2, 1, 3).
- Finish operating.
Also, the sequence (a_1, a_2, a_3) = (3, 1, 2) can be obtained by the following steps:
- Choose the second edge, swap the pieces on vertices 2 and 3, and delete the edge. This results in (a_1, a_2, a_3) = (1, 3, 2).
- Choose the first edge, swap the pieces on vertices 1 and 2, and delete the edge. This results in (a_1, a_2, a_3) = (3, 1, 2).
- Finish operating.
The operation can yield the following five sequences:
- (1, 2, 3)
- (1, 3, 2)
- (2, 1, 3)
- (2, 3, 1)
- (3, 1, 2)
Sample Input 2
5 2 5 3 4 1 3 1 5
Sample Output 2
34
Sample Input 3
8 4 5 2 5 3 6 1 3 1 8 2 7 2 8
Sample Output 3
799
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 600 点
問題文
非負整数 P, B が与えられます。P は素数で、1 \leq B \leq P-1 です。
非負整数列 X=(x_1,x_2,\dots,x_n) に対して X のハッシュ値 \mathrm{hash}(X) を次のように定義します。
M 個の整数対 (L_1, R_1), (L_2, R_2), \dots, (L_M, R_M) が与えられます。 次の条件を満たす長さ N の非負整数列 A=(A_1, A_2, \dots, A_N) は存在しますか?
- すべての i (1 \leq i \leq M) について次の条件が成り立つ。
- A の L_i 番目から R_i 番目までの要素を取り出して出来る数列 (A_{L_i}, A_{L_i + 1}, \dots, A_{R_i}) を s とおいたとき、\mathrm{hash}(s) \neq 0 である。
制約
- 2 \leq P \leq 10^9
- P は素数
- 1 \leq B \leq P - 1
- 1 \leq N \leq 16
- 1 \leq M \leq \frac{N(N+1)}{2}
- 1 \leq L_i \leq R_i \leq N
- i \neq j ならば (L_i, R_i) \neq (L_j, R_j)
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
P B N M L_1 R_1 L_2 R_2 \vdots L_M R_M
出力
問題文の条件を満たす数列が存在すれば Yes を、存在しなければ No を出力せよ。
入力例 1
3 2 3 3 1 1 1 2 2 3
出力例 1
Yes
数列 A = (2, 0, 4) は \mathrm{hash}((A_1)) = 2, \mathrm{hash}((A_1, A_2)) = 1, \mathrm{hash}((A_2, A_3)) = 1 であるため問題文の条件を満たす数列です。
入力例 2
2 1 3 3 1 1 2 3 1 3
出力例 2
No
問題文の条件を満たす数列は存在しません。
入力例 3
998244353 986061415 6 11 1 5 2 2 2 5 2 6 3 4 3 5 3 6 4 4 4 5 4 6 5 6
出力例 3
Yes
Score: 600 points
Problem Statement
You are given non-negative integers P and B. Here, P is prime, and 1 \leq B \leq P-1.
For a sequence of non-negative integers X=(x_1,x_2,\dots,x_n), the hash value \mathrm{hash}(X) is defined as follows.
You are given M pairs of integers (L_1, R_1), (L_2, R_2), \dots, (L_M, R_M).
Is there a sequence of non-negative integers A=(A_1, A_2, \dots, A_N) of length N that satisfies the condition below?
- For all i (1 \leq i \leq M), the following condition holds:
- Let s be the sequence (A_{L_i}, A_{L_i + 1}, \dots, A_{R_i}) obtained by taking the L_i-th to the R_i-th elements of A. Then, \mathrm{hash}(s) \neq 0.
Constraints
- 2 \leq P \leq 10^9
- P is prime.
- 1 \leq B \leq P - 1
- 1 \leq N \leq 16
- 1 \leq M \leq \frac{N(N+1)}{2}
- 1 \leq L_i \leq R_i \leq N
- (L_i, R_i) \neq (L_j, R_j) if i \neq j.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
P B N M L_1 R_1 L_2 R_2 \vdots L_M R_M
Output
If there is a sequence that satisfies the condition in the problem statement, print Yes; otherwise, print No.
Sample Input 1
3 2 3 3 1 1 1 2 2 3
Sample Output 1
Yes
The sequence A = (2, 0, 4) satisfies the condition because \mathrm{hash}((A_1)) = 2, \mathrm{hash}((A_1, A_2)) = 1, \mathrm{hash}((A_2, A_3)) = 1.
Sample Input 2
2 1 3 3 1 1 2 3 1 3
Sample Output 2
No
No sequence satisfies the condition.
Sample Input 3
998244353 986061415 6 11 1 5 2 2 2 5 2 6 3 4 3 5 3 6 4 4 4 5 4 6 5 6
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 800 点
問題文
縦 N マス、横 N マスのグリッドがあります。グリッドの上から i 行目、左から j 列目のマスを (i, j) と呼びます。また、 1 個の黒石と M 個の白石があります。
あなたはこれらの道具を使って 1 人でゲームをすることにしました。
ゲームのルールを説明します。はじめに、あなたは黒石を (A, B) に置きます。その後、 M 個の白石をグリッドのいずれかのマスに 1 個ずつ置きます。ただし、
- (A, B) に白石は置けません。
- 白石は 1 つの行に高々 1 個しか置けません。
- 白石は 1 つの列に高々 1 個しか置けません。
その後、あなたは操作を行えなくなるまで以下の操作を行います。
- 黒石が (i, j) にあるとする。次の 4 通りの操作のいずれかを行う。
- (i, k) (j \lt k) に白石が置いてある時、その白石を取り除いて (i, k + 1) に黒石を動かす。
- (i, k) (j \gt k) に白石が置いてある時、その白石を取り除いて (i, k - 1) に黒石を動かす。
- (k, j) (i \lt k) に白石が置いてある時、その白石を取り除いて (k + 1, j) に黒石を動かす。
- (k, j) (i \gt k) に白石が置いてある時、その白石を取り除いて (k - 1, j) に黒石を動かす。
- ただし、黒石を動かす先のマスが存在しない場合はそのような動きは出来ない。
図で例示すると以下のようになります。ここで B は黒石、 W は白石、. は何もないマス、O は黒石を動かせるマスを意味します。
..O... ..W... ...... ...... ..B.WO ......
操作を終了した時点で以下の条件を全て満たしているとき、ゲームはあなたの勝利となります。そうでない場合は敗北となります。
- グリッドから白石が全て取り除かれている。
- 黒石が (A, B) に置かれている。
はじめの M 個の白石の配置としてあり得るもののうち、その後の操作をうまく行うことでゲームに勝利することが可能である配置は何通りありますか?答えを 998244353 で割った余りを求めてください。
制約
- 2 \leq M \leq N \leq 2 \times 10^5
- 1 \leq A \leq N
- 1 \leq B \leq N
- N, M, A, B は整数
入力
入力は以下の形式で標準入力から与えられる。
N M A B
出力
ゲームに勝利することが可能である白石の配置の個数を 998244353 で割った余りを出力せよ。
入力例 1
6 4 2 3
出力例 1
4
例えば白石を以下の図のように配置したとします。
...... ..BW.. .....W ...... ..W... ....W.
このときあなたは次の手順で黒石を動かすことでゲームに勝利することが出来ます。
- (5, 3) にある白石を取り除いて (6, 3) に黒石を動かす。
- (6, 5) にある白石を取り除いて (6, 6) に黒石を動かす。
- (3, 6) にある白石を取り除いて (2, 6) に黒石を動かす。
- (2, 4) にある白石を取り除いて (2, 3) に黒石を動かす。
- グリッドから全ての白石を取り除き、かつ黒石が (A, B) = (2, 3) に置かれた状態になったので、あなたはゲームに勝利する。
ゲームに勝利することが可能である白石の配置は全部で 4 通りあります。
入力例 2
5 3 1 3
出力例 2
0
入力例 3
200000 47718 21994 98917
出力例 3
146958602
Score: 800 points
Problem Statement
There is a grid with N rows and N columns. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left. Additionally, there is one black stone and M white stones.
You will play a single-player game using these items.
Here are the rules. Initially, you place the black stone at (A, B). Then, you place each of the M white stones on some cell of the grid. Here:
- You cannot place a white stone at (A, B).
- You can place at most one white stone per row.
- You can place at most one white stone per column.
Then, you will perform the following operation until you cannot do so:
- Assume the black stone is at (i, j). Perform one of the four operations below:
- If there is a white stone at (i, k) where (j < k), remove that white stone and move the black stone to (i, k + 1).
- If there is a white stone at (i, k) where (j > k), remove that white stone and move the black stone to (i, k - 1).
- If there is a white stone at (k, j) where (i < k), remove that white stone and move the black stone to (k + 1, j).
- If there is a white stone at (k, j) where (i > k), remove that white stone and move the black stone to (k - 1, j).
- Here, if the cell to which the black stone is to be moved does not exist, such a move cannot be made.
The following figure illustrates an example. Here, B represents the black stone, W represents a white stone, . represents an empty cell, and O represents a cell to which the black stone can be moved.
..O... ..W... ...... ...... ..B.WO ......
You win the game if all of the following conditions are satisfied when you finish performing the operation. Otherwise, you lose.
- All white stones have been removed from the grid.
- The black stone is placed at (A, B).
In how many initial configurations of the M white stones can you win the game by optimally performing the operation? Find the count modulo 998244353.
Constraints
- 2 \leq M \leq N \leq 2 \times 10^5
- 1 \leq A \leq N
- 1 \leq B \leq N
- N, M, A, and B are integers.
Input
The input is given from Standard Input in the following format:
N M A B
Output
Print the number, modulo 998244353, of possible configurations of the white stones that can lead to your victory.
Sample Input 1
6 4 2 3
Sample Output 1
4
For example, consider the white stones placed as shown in the following figure:
...... ..BW.. .....W ...... ..W... ....W.
Here, you can win the game by moving the black stone in the following steps:
- Remove the white stone at (5, 3) and move the black stone to (6, 3).
- Remove the white stone at (6, 5) and move the black stone to (6, 6).
- Remove the white stone at (3, 6) and move the black stone to (2, 6).
- Remove the white stone at (2, 4) and move the black stone to (2, 3).
- Since all white stones have been removed from the grid and the black stone is placed at (A, B) = (2, 3), you win the game.
There are four configurations of white stones that can lead to your victory.
Sample Input 2
5 3 1 3
Sample Output 2
0
Sample Input 3
200000 47718 21994 98917
Sample Output 3
146958602
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 1100 点
問題文
文字列 T が次の条件を満たす時、T を 良い文字列 と呼びます。
- 次の条件を全て満たす文字列の組 (A, B) が存在する。
- A, B はともに空でない。
- A + B = T
- A + \mathrm{rev}(B) と \mathrm{rev}(A) + B はともに回文となる。
ここで A + B は文字列 A と文字列 B をこの順に結合してできる文字列を意味します。
また、\mathrm{rev}(A) は文字列 A の文字を逆順に並べ替えてできる文字列を意味します。
英小文字と ? からなる長さ N の文字列 S があります。
S に含まれる ? を英小文字に置き換える方法は 26^{(? の個数)} 通りありますが、そのうち置き換えた後の文字列が良い文字列になる方法は何通りありますか?答えを 998244353 で割った余りを求めてください。
制約
- 2 \leq N \leq 5 \times 10^4
- S は英小文字と
?からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
問題文の条件を満たす置き換え方の個数を 998244353 で割った余りを出力せよ。
入力例 1
4 ?ba?
出力例 1
1
文字列 abab は良い文字列です。なぜならば、A = ab, B = ab としたとき、A + B = abab であり A + \mathrm{rev}(B) = abba と \mathrm{rev}(A) + B = baab はともに回文となるからです。
S の ? を英小文字に置き換えてできる文字列のうち、良い文字列は abab の 1 通りのみです。
入力例 2
10 ?y?x?x????
出力例 2
676
入力例 3
30 ???a?????aab?a???c????c?aab???
出力例 3
193994800
入力例 4
36 ????????????????????????????????????
出力例 4
363594614
Score: 1100 points
Problem Statement
A string T is called a good string when it satisfies the following condition:
- There is a pair of strings (A, B) that satisfies all of the following:
- Both A and B are non-empty.
- A + B = T.
- Both A + \mathrm{rev}(B) and \mathrm{rev}(A) + B are palindromes.
Here, A + B denotes the string formed by concatenating strings A and B in this order.
Also, \mathrm{rev}(A) denotes the string formed by reversing the order of the characters in string A.
There is a string S of length N consisting of lowercase English letters and the character ?.
Among the 26^{(\text{number of ?s})} ways to replace the ?s in S with lowercase English letters, how many result in a good string? Find the count modulo 998244353.
Constraints
- 2 \leq N \leq 5 \times 10^4
- S is a string of length N consisting of lowercase English letters and
?.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the number, modulo 998244353, 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 A = ab and B = ab, then A + B = abab, and both A + \mathrm{rev}(B) = abba and \mathrm{rev}(A) + B = baab are palindromes.
Among the strings that can be formed by replacing the ?s in S 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