Big Picture

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Grammy has a big picture with n+1n+1 rows and m+1m+1 columns. Rows are numbered from 11 to n+1n+1 and columns are numbered from 11 to m+1m+1.

Grammy decides to color this picture in a special way. For the ii-th row, Grammy will color the leftmost jj (1jm1\leq j\leq m) cells black with probability p_i,jp\_{i,j}. For the jj-th column, Grammy will color the topmost ii (1in1\leq i\leq n) cells black with probability q_i,jq\_{i,j}. Operations are independent, and a cell could be colored more than once.

Let us define the beauty value as the number of maximal orthogonally connected regions of the same color. Before Grammy finishes her coloring, she wants to know the expected number of regions on the picture. Please calculate the expected beauty value of the picture for her.

Two cells xx and yy are in the same orthogonally connected region if and only if they satisfy the following constraints:

  • They have the same color.
  • xx shares an edge with yy or xx shares an edge with some cell zz while yy and zz are in the same orthogonally connected region.

입력

The first line contains two integers nn and mm (1n,m10001 \leq n,m \leq 1000), denoting the size of the picture.

Each of the next nn lines contains mm integers p_i,jp\_{i,j}, denoting the probability of painting the leftmost jj cells of the ii-th row black, modulo 998,244,353998\\,244\\,353. It is guaranteed that the sum of the probabilities in each row is 11.

Each of the next nn lines contains mm integers q_i,jq\_{i,j}, denoting the probability of painting the topmost ii cells of the jj-th column black, modulo 998,244,353998\\,244\\,353. It is guaranteed that the sum of the probabilities in each column is 11.

출력

Output a single integer, denoting the expected beauty value of the picture, modulo 998,244,353998\\,244\\,353.

It can be shown that the answer can be expressed as an irreducible fraction xy\frac{x}{y}, where xx and yy are integers and y≢0(mod998,244,353)y \not \equiv 0 \pmod {998\\,244\\,353}. Output the integer equal to xy1(mod998,244,353)x\cdot y^{-1}\pmod {998\\,244\\,353}. In other words, output such an integer aa that 0a<998,244,3530\leq a < 998\\,244\\,353 and ayx(mod998,244,353)a\cdot y\equiv x\pmod {998\\,244\\,353}.

힌트

There is only one possible picture in the first example, which is shown as follows. There are 33 maximal orthogonally connected regions in the picture, so the beauty value of the picture is 33.