#include <cmath> 
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<class T> void rd(T &x) {
	x=0; int f=1,ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=getchar();}
	x*=f;
}
typedef long long ll;
const int mod=998244353;
const int maxn=1500+5;
int n; char A[maxn][maxn];
int head[maxn];
int adj[maxn][maxn],deg[maxn];
int vis[maxn],E,P,C;
struct edge {
	int to,nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
inline int add(int x) {return x>=mod?x-mod:x;}
ll power(ll x,ll y) {
	ll re=1;
	while(y) {
		if(y&1) re=re*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return re;
}
inline void addedge(int u,int v) {
	G.push_back(edge(v,head[u])),head[u]=G.size()-1;
	G.push_back(edge(u,head[v])),head[v]=G.size()-1;
}
inline int idx0(int x,int y) {return x+y;}
inline int idx1(int x,int y) {return x<y?idx0(0,y-x):idx0(x-y,0);}
inline bool upd(int x,int y,char c) {
	if(c=='?') return 1;
	int a=x+y,b=x-y;
	if(a>n) a=2*n-a;
	if(b<0) b=-b;
	x=(a+b)/2,y=a-x;
	a=idx0(x,y),b=idx1(x,y);
	if(a>b) swap(a,b);
	if(adj[a][b]==-1) {
		adj[a][b]=c=='x'; 
		deg[a]^=adj[a][b];
		deg[b]^=adj[a][b];
	}
	else return adj[a][b]==(c=='x');
	return 1;
}
void travel(int u) {
	if(vis[u]) return; vis[u]=1;
	++P; if(deg[u]) ++C;
	for(int i=head[u];~i;i=G[i].nex) {
		int v=G[i].to;
		++E;
		travel(v);
	}
}
int sol(int k) {
	for(int i=1;i<n;++i) for(int j=1;j<n;++j) if(((i+j)&1)==k) {
		if(!upd(i,j,A[i][j])) return 0;
	}
	int cnt=0;
	for(int i=k;i<=n;i+=2) ++cnt;
	if(~cnt&1) {
		int an=1;
		for(int i=k;i<=n;i+=2) for(int j=i+2;j<=n;j+=2) {
			if(adj[i][j]==-1) an=add(an<<1);
		}
		return an;
	}
	for(int i=k;i<=n;i+=2) for(int j=i+2;j<=n;j+=2) {
		if(adj[i][j]==-1) addedge(i,j);
	}
	int an=1;
	for(int i=k;i<=n;i+=2) if(!vis[i]) {
		E=0,P=0,C=0,travel(i),E>>=1;
		if(C&1) return 0;
		an=an*power(2,E-(P-1))%mod;
	}
	return an;
}
int main() {
	rd(n);
	for(int i=1;i<n;++i) scanf("%s",A[i]+1);
	memset(adj,-1,sizeof(adj));
	memset(head,-1,sizeof(head));
	printf("%lld\n",(ll)sol(0)*sol(1)%mod);
	return 0;
}
### Prompt

Generate a CPP solution to 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 <cmath> 
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<class T> void rd(T &x) {
	x=0; int f=1,ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=getchar();}
	x*=f;
}
typedef long long ll;
const int mod=998244353;
const int maxn=1500+5;
int n; char A[maxn][maxn];
int head[maxn];
int adj[maxn][maxn],deg[maxn];
int vis[maxn],E,P,C;
struct edge {
	int to,nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
inline int add(int x) {return x>=mod?x-mod:x;}
ll power(ll x,ll y) {
	ll re=1;
	while(y) {
		if(y&1) re=re*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return re;
}
inline void addedge(int u,int v) {
	G.push_back(edge(v,head[u])),head[u]=G.size()-1;
	G.push_back(edge(u,head[v])),head[v]=G.size()-1;
}
inline int idx0(int x,int y) {return x+y;}
inline int idx1(int x,int y) {return x<y?idx0(0,y-x):idx0(x-y,0);}
inline bool upd(int x,int y,char c) {
	if(c=='?') return 1;
	int a=x+y,b=x-y;
	if(a>n) a=2*n-a;
	if(b<0) b=-b;
	x=(a+b)/2,y=a-x;
	a=idx0(x,y),b=idx1(x,y);
	if(a>b) swap(a,b);
	if(adj[a][b]==-1) {
		adj[a][b]=c=='x'; 
		deg[a]^=adj[a][b];
		deg[b]^=adj[a][b];
	}
	else return adj[a][b]==(c=='x');
	return 1;
}
void travel(int u) {
	if(vis[u]) return; vis[u]=1;
	++P; if(deg[u]) ++C;
	for(int i=head[u];~i;i=G[i].nex) {
		int v=G[i].to;
		++E;
		travel(v);
	}
}
int sol(int k) {
	for(int i=1;i<n;++i) for(int j=1;j<n;++j) if(((i+j)&1)==k) {
		if(!upd(i,j,A[i][j])) return 0;
	}
	int cnt=0;
	for(int i=k;i<=n;i+=2) ++cnt;
	if(~cnt&1) {
		int an=1;
		for(int i=k;i<=n;i+=2) for(int j=i+2;j<=n;j+=2) {
			if(adj[i][j]==-1) an=add(an<<1);
		}
		return an;
	}
	for(int i=k;i<=n;i+=2) for(int j=i+2;j<=n;j+=2) {
		if(adj[i][j]==-1) addedge(i,j);
	}
	int an=1;
	for(int i=k;i<=n;i+=2) if(!vis[i]) {
		E=0,P=0,C=0,travel(i),E>>=1;
		if(C&1) return 0;
		an=an*power(2,E-(P-1))%mod;
	}
	return an;
}
int main() {
	rd(n);
	for(int i=1;i<n;++i) scanf("%s",A[i]+1);
	memset(adj,-1,sizeof(adj));
	memset(head,-1,sizeof(head));
	printf("%lld\n",(ll)sol(0)*sol(1)%mod);
	return 0;
}
```