atcoder#NIKKEI20192QUALF. Mirror Frame

Mirror Frame

Score : 14001400 points

Problem Statement

In a two-dimensional plane, there is a square frame whose vertices are at coordinates (0,0)(0,0), (N,0)(N,0), (0,N)(0,N), and (N,N)(N,N). The frame is made of mirror glass. A ray of light striking an edge of the frame (but not a vertex) will be reflected so that the angle of incidence is equal to the angle of reflection. A ray of light striking a vertex of the frame will be reflected in the direction opposite to the direction it is coming from.

We will define the path for a grid point (a point with integer coordinates) (i,j)(i,j) ($0) strictly within the frame, as follows:

  • The path for (i,j)(i,j) is the union of the trajectories of four rays of light emitted from (i,j)(i,j) to (i1,j1)(i-1,j-1), (i1,j+1)(i-1,j+1), (i+1,j1)(i+1,j-1), and (i+1,j+1)(i+1,j+1).

Figure: an example of a path for a grid point

There is a light bulb at each grid point strictly within the frame. We will assign a state - ON or OFF - to each bulb. The state of the whole set of bulbs are called beautiful if it is possible to turn OFF all the bulbs by repeating the following operation:

  • Choose a grid point strictly within the frame, and switch the states of all the bulbs on its path.

Takahashi has set the states of some of the bulbs, but not for the remaining bulbs. Find the number of ways to set the states of the remaining bulbs so that the state of the whole set of bulbs is beautiful, modulo 998244353998244353. The state of the bulb at the grid point (i,j)(i,j) is set to be ON if Ai,j=A_{i,j}=o, OFF if Ai,j=A_{i,j}=x, and unset if Ai,j=A_{i,j}=?.

Constraints

  • 2N15002 \leq N \leq 1500
  • AijA_{ij} is o, x, or ?.

Input

Input is given from Standard Input in the following format:

NN

A1,1...A1,N1A_{1,1}...A_{1,N-1}

::

AN1,1...AN1,N1A_{N-1,1}...A_{N-1,N-1}

Output

Print the answer.

4
o?o
???
?x?
1

The state of the whole set of bulbs will be beautiful if we set the state of each bulb as follows:

oxo
xox
oxo

We can turn OFF all the bulbs by, for example, choosing the point (1,1)(1, 1) and switching the states of the bulbs at (1,1)(1,1), (1,3)(1,3), (2,2)(2,2), (3,1)(3,1), and (3,3)(3,3).

5
o?o?
????
o?x?
????
0
6
?o???
????o
??x??
o????
???o?
32
9
????o??x
?????x??
??o?o???
?o?x????
???????x
x?o?o???
????????
x?????x?
4