atcoder#ARC136F. [ARC136F] Flip Cells

[ARC136F] Flip Cells

Score : 10001000 points

Problem Statement

We have a checkerboard with HH rows and WW columns, where each square has a 0 or 1 written on it. The current state of checkerboard is represented by HH strings S1,S2,,SHS_1,S_2,\cdots,S_H: the jj-th character of SiS_i represents the digit in the square at the ii-th row from the top and jj-th column from the left.

Snuke will repeat the following operation.

  • Choose one square uniformly at random. Then, flip the value written in that square. (In other words, change 0 to 1 and vice versa.)

By the way, he loves an integer sequence A=(A1,A2,,AH)A=(A_1,A_2,\cdots,A_H), so he will terminate the process at the moment when the following condition is satisfied.

  • For every ii (1iH1 \leq i \leq H), the ii-th row from the top contains exactly AiA_i 1s.

Particularly, he may do zero operations.

Find the expected value of the number of operations Snuke does, modulo 998244353998244353.

Definition of the expected value modulo $998244353$

It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is represented as an irreducible fraction PQ\frac{P}{Q}, it can also be proved that Q≢0(mod998244353)Q \not \equiv 0 \pmod{998244353}. Thus, there uniquely exists an integer RR such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Find this RR.

Constraints

  • 1H,W501 \leq H,W \leq 50
  • SiS_i is a string of length WW consisting of 0, 1.
  • 0AiW0 \leq A_i \leq W

Input

Input is given from Standard Input in the following format:

HH WW

S1S_1

S2S_2

\vdots

SHS_H

A1A_1 A2A_2 \cdots AHA_H

Output

Print the answer.

1 2
01
0
3

The process goes as follows.

  • With probability 1/21/2, a square with 1 is flipped. The 11-st row now contains zero 1s, terminating the process.
  • With probability 1/21/2, a square with 0 is flipped. The 11-st row now contains two 1s, continuing the process.- One of the squares is flipped. Regardless of which square is flipped, the 11-st row now contains one 1, continuing the process.- With probability 1/21/2, a square with 1 is flipped. The 11-st row now contains zero 1s, terminating the process.
    • With probability 1/21/2, a square with 0 is flipped. The 11-st row now contains two 1s, continuing the process.
    • \vdots
  • One of the squares is flipped. Regardless of which square is flipped, the 11-st row now contains one 1, continuing the process.
  • With probability 1/21/2, a square with 1 is flipped. The 11-st row now contains zero 1s, terminating the process.
  • With probability 1/21/2, a square with 0 is flipped. The 11-st row now contains two 1s, continuing the process.
  • \vdots

The expected value of the number of operations is 33.

3 3
000
100
110
0 1 2
0
2 2
00
01
1 0
332748127
5 4
1101
0000
0010
0100
1111
1 3 3 2 1
647836743