Codeforces Round 848 (Div. 2)
D
Flexible String Revisit
Codeforces
2100
原题
← CE →
翻译中…

You are given two binary strings $a$ and $b$ of length $n$. In each move, the string $a$ is modified in the following way.

翻译中…
  • An index $i$ ($1 \leq i \leq n$) is chosen uniformly at random. The character $a_i$ will be flipped. That is, if $a_i$ is $0$, it becomes $1$, and if $a_i$ is $1$, it becomes $0$.
翻译中…

What is the expected number of moves required to make both strings equal for the first time?

翻译中…

A binary string is a string, in which the character is either $\tt{0}$ or $\tt{1}$.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^6$) — the length of the strings.

翻译中…

The second line of each test case contains the binary string $a$ of length $n$.

翻译中…

The third line of each test case contains the binary string $b$ of length $n$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, output a single line containing the expected number of moves modulo $998\,244\,353$.

翻译中…

Formally, let $M = 998\,244\,353$. It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$, where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$. Output the integer equal to $p \cdot q^{-1} \bmod M$. In other words, output such an integer $x$ that $0 \le x \lt M$ and $x \cdot q \equiv p \pmod{M}$.

翻译中…

Note

翻译中…

In the first test case, index $1$ is chosen randomly and $a_1$ is flipped. After the move, the strings $a$ and $b$ are equal. The expected number of moves is $1$.

翻译中…

The strings $a$ and $b$ are already equal in the second test case. So, the expected number of moves is $0$.

翻译中…

The expected number of moves for the third and fourth test cases are $\frac{56}{3}$ and $\frac{125}{3}$ respectively.

翻译中…

样例

Input #1
4
1
0
1
2
00
00
4
1000
1110
5
01001
10111
Output #1
1
0
665496254
665496277
InputCopy OutputCopy
题目信息
题号
1778D
时间限制
2 s
内存限制
256 MB
标签
组合数学
动态规划
数学
概率论

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