QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#10285. Good String

統計

For three binary strings $s_1, s_2, s_3$ of length $n$, a binary string $t$ of length $n$ is called "good" if and only if $\forall 1 \le i, j \le n, \exists k \in \{1, 2, 3\}$ such that $s_{k,i} = t_i$ and $s_{k,j} = t_j$. Let $f(s_1, s_2, s_3)$ be the number of such good strings.

We are given three random binary strings $s_1, s_2, s_3$ of length $n$, where the $j$-th character ($1 \le j \le n$) of $s_i$ ($1 \le i \le 3$) is $1$ with probability $\frac{p_{i,j}}{9}$ and $0$ with probability $(1 - \frac{p_{i,j}}{9})$, where $p_{i,j}$ is an integer from $0$ to $9$. All random events are independent. You need to find the expected value of $f(s_1, s_2, s_3)$, modulo $998244353$.

Input

The first line contains an integer $n$ ($3 \le n \le 3 \times 10^5$) representing the length of the strings. The next 3 lines each contain $n$ digits, where the digit at the $i$-th row and $j$-th column represents $p_{i,j}$.

Output

Output a single integer representing the expected value modulo $998244353$.

Examples

Input 1

3
900
090
009

Output 1

4

Note 1

In this example, $s_1, s_2, s_3$ are $100, 010, 001$ respectively. The four valid strings are $100, 010, 001, 000$.

Input 2

3
999
999
999

Output 2

1

Input 3

10
0123456789
1234567890
2345678901

Output 3

612360617

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.