#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1505,mod=998244353;
int n,tot,a[N][N],head[N],nex[N*N<<1],to[N*N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
char s[N][N];
vector<int>v[N][N];
bool vis[N];
int num,c[N][N],vt[N],e[N];
void solve(int x,int y,int dx,int dy,int tot)
{
    while(x>=0&&x<=n&&y>=0&&y<=n)
    {
        v[x][y].push_back(tot);
        x+=dx;y+=dy;
    }
}
void dfs(int u)
{
    if(vis[u]) return;
    vis[u]=true;num^=vt[u];
    for(int i=head[u];i;i=nex[i])
        dfs(to[i]);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
        scanf("%s",s[i]+1);
    for(int i=0;i<=n;i++)
    {
        int x=0,y=i,dx=1,dy=1;
        for(int j=1;j<=(i>0&&i<n?2*n:n);j++)
        {
            v[x][y].push_back(i);
            if(x+dx<0||x+dx>n) dx*=-1;
            if(y+dy<0||y+dy>n) dy*=-1;
            x+=dx;y+=dy;
        }
    }
    for(int i=1;i<n;i++)
        for(int j=1;j<n;j++)
        if(s[i][j]=='o') a[i][j]=1;
    else if(s[i][j]=='x') a[i][j]=2;
    for(int i=1;i<n;i++)
        for(int j=1;j<n;j++)
    {
        int x=v[i][j][0],y=v[i][j][1];
        c[x][y]|=a[i][j];
        if(c[x][y]==3){cout<<0<<endl;return 0;}
    }
    for(int i=0;i<=n;i++)
        for(int j=i+2;j<=n;j+=2)
        if(c[i][j]==0) add(i,j),add(j,i),e[i&1]++;
    else vt[i]^=c[i][j]-1,vt[j]^=c[i][j]-1;
    int ans=1;
    for(int d=0;d<2;d++)
    {
        int nt=(n-d)/2+1;
        if(nt&1)
        {
            int cnt=0;
            for(int i=d;i<=n;i+=2)
                if(!vis[i])
            {
                cnt++;num=0;
                dfs(i);
                if(num&1){cout<<0<<endl;return 0;}
            }
            for(int i=1;i<=e[d]-nt+cnt;i++)
                ans=(ans<<1)%mod;
        }
        else for(int i=1;i<=e[d];i++) ans=(ans<<1)%mod;
    }
    printf("%d\n",ans);
    return 0;
}

### Prompt

Create a solution in Cpp for the following problem:

In a two-dimensional plane, there is a square frame whose vertices are at coordinates (0,0), (N,0), (0,N), and (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) (0<i,j<N) strictly within the frame, as follows:

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



<image>

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 998244353. The state of the bulb at the grid point (i,j) is set to be ON if A_{i,j}=`o`, OFF if A_{i,j}=`x`, and unset if A_{i,j}=`?`.

Constraints

* 2 \leq N \leq 1500
* A_{ij} is `o`, `x`, or `?`.

Input

Input is given from Standard Input in the following format:


N
A_{1,1}...A_{1,N-1}
:
A_{N-1,1}...A_{N-1,N-1}


Output

Print the answer.

Examples

Input

4
o?o
???
?x?


Output

1


Input

5
o?o?
????
o?x?
????


Output

0


Input

6
?o???
????o
??x??
o????
???o?


Output

32


Input

9
????o??x
?????x??
??o?o???
?o?x????
???????x
x?o?o???
????????
x?????x?


Output

4

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1505,mod=998244353;
int n,tot,a[N][N],head[N],nex[N*N<<1],to[N*N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
char s[N][N];
vector<int>v[N][N];
bool vis[N];
int num,c[N][N],vt[N],e[N];
void solve(int x,int y,int dx,int dy,int tot)
{
    while(x>=0&&x<=n&&y>=0&&y<=n)
    {
        v[x][y].push_back(tot);
        x+=dx;y+=dy;
    }
}
void dfs(int u)
{
    if(vis[u]) return;
    vis[u]=true;num^=vt[u];
    for(int i=head[u];i;i=nex[i])
        dfs(to[i]);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
        scanf("%s",s[i]+1);
    for(int i=0;i<=n;i++)
    {
        int x=0,y=i,dx=1,dy=1;
        for(int j=1;j<=(i>0&&i<n?2*n:n);j++)
        {
            v[x][y].push_back(i);
            if(x+dx<0||x+dx>n) dx*=-1;
            if(y+dy<0||y+dy>n) dy*=-1;
            x+=dx;y+=dy;
        }
    }
    for(int i=1;i<n;i++)
        for(int j=1;j<n;j++)
        if(s[i][j]=='o') a[i][j]=1;
    else if(s[i][j]=='x') a[i][j]=2;
    for(int i=1;i<n;i++)
        for(int j=1;j<n;j++)
    {
        int x=v[i][j][0],y=v[i][j][1];
        c[x][y]|=a[i][j];
        if(c[x][y]==3){cout<<0<<endl;return 0;}
    }
    for(int i=0;i<=n;i++)
        for(int j=i+2;j<=n;j+=2)
        if(c[i][j]==0) add(i,j),add(j,i),e[i&1]++;
    else vt[i]^=c[i][j]-1,vt[j]^=c[i][j]-1;
    int ans=1;
    for(int d=0;d<2;d++)
    {
        int nt=(n-d)/2+1;
        if(nt&1)
        {
            int cnt=0;
            for(int i=d;i<=n;i+=2)
                if(!vis[i])
            {
                cnt++;num=0;
                dfs(i);
                if(num&1){cout<<0<<endl;return 0;}
            }
            for(int i=1;i<=e[d]-nt+cnt;i++)
                ans=(ans<<1)%mod;
        }
        else for(int i=1;i<=e[d];i++) ans=(ans<<1)%mod;
    }
    printf("%d\n",ans);
    return 0;
}

```