Codeforces Round 758 (Div.1 + Div. 2)
D
Dominoes
Codeforces
2400
原题
← CE →
翻译中…

You are given $n$ dominoes. Each domino has a left and a right cell. Each cell can be colored either black or white. Some cells are already colored, while some aren't yet.

翻译中…

The coloring is said to be valid if and only if it is possible to rearrange the dominoes in some order such that for each $1 \le i \le n$ the color of the right cell of the $i$-th domino is different from the color of the left cell of the $((i \bmod n)+1)$-st domino.

翻译中…

Note that you can't rotate the dominoes, so the left cell always remains the left cell, and the right cell always remains the right cell.

翻译中…

Count the number of valid ways to color the yet uncolored cells of dominoes. Two ways are considered different if there is a cell that is colored white in one way and black in the other. In particular, colorings BW WB and WB BW different (and both invalid).

翻译中…

As this number can be very big, output it modulo $998\,244\,353$.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $n$ ($1 \le n \le 10^5$) — the number of dominoes.

翻译中…

The next $n$ lines describe dominoes. Each line contains two characters which represent the left and the right cell. Character B means that the corresponding cell is black, character W means that the corresponding cell is white, and ? means that the cell is yet to be colored.

翻译中…

Output

翻译中…

Print a single integer — the answer to the problem.

翻译中…

Note

翻译中…

In the first test case, there is only one domino, and we need the color of its right cell to be different from the color of its left cell. There is only one way to achieve this.

翻译中…

In the second test case, there are only $2$ such colorings:

翻译中…

BB WW and WB WB.

翻译中…

样例

Input #1
1
?W
Output #1
1
InputCopy OutputCopy
Input #2
2
??
W?
Output #2
2
InputCopy OutputCopy
Input #3
4
BB
??
W?
??
Output #3
10
InputCopy OutputCopy
题目信息
题号
1608D
时间限制
1 s
内存限制
256 MB
标签
组合数学
FFT
图论
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。