// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int UF[510];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
char in[210][210];
char t[210];
char s[5];
int main(){
	for(int i=0;i<510;i++)UF[i]=-1;
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	long long ret=1;
	for(int i=0;i<a/2;i++){
		for(int j=0;j<b/2;j++){
			s[0]=in[i][j];
			s[1]=in[i][b-1-j];
			s[2]=in[a-1-i][j];
			s[3]=in[a-1-i][b-1-j];
			std::sort(s,s+4);
			int cnt=0;
			do{
				cnt++;
			}while(next_permutation(s,s+4));
			if(cnt==24){
				ret=ret*12%mod;
				UNION(i,j+a/2);
			}else{
				ret=ret*cnt%mod;
			}
		}
	}
	for(int i=0;i<a/2+b/2;i++){
		if(FIND(i)!=i){
			ret=ret*2%mod;
		}
	}
	if(a%2){
		for(int i=0;i<b;i++)t[i]=in[a/2][i];
		reverse(t,t+b);
		bool ok=false;
		for(int i=0;i<b;i++)if(t[i]!=in[a/2][i])ok=true;
		if(ok)ret=ret*2%mod;
	}
	if(b%2){
		for(int i=0;i<a;i++)t[i]=in[i][b/2];
		reverse(t,t+a);
		bool ok=false;
		for(int i=0;i<a;i++)if(t[i]!=in[i][b/2])ok=true;
		if(ok)ret=ret*2%mod;
	}
	printf("%lld\n",ret);
}
### Prompt

Generate a CPP solution to the following problem:

Snuke has a grid with H rows and W columns. The square at the i-th row and j-th column contains a character S_{i,j}.

He can perform the following two kinds of operation on the grid:

* Row-reverse: Reverse the order of the squares in a selected row.
* Column-reverse: Reverse the order of the squares in a selected column.



For example, reversing the 2-nd row followed by reversing the 4-th column will result as follows:

<image>

By performing these operations any number of times in any order, how many placements of characters on the grid can be obtained?

Constraints

* 1≦H,W≦200
* S_{i,j} is a lowercase English letter (`a`-`z`).

Input

The input is given from Standard Input in the following format:


H W
S_{1,1}S_{1,2}...S_{1,W}
S_{2,1}S_{2,2}...S_{2,W}
:
S_{H,1}S_{H,2}...S_{H,W}


Output

Print the number of placements of characters on the grid that can be obtained, modulo 1000000007 (=10^9+7).

Examples

Input

2 2
cf
cf


Output

6


Input

1 12
codefestival


Output

2

### Response

```cpp
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int UF[510];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
char in[210][210];
char t[210];
char s[5];
int main(){
	for(int i=0;i<510;i++)UF[i]=-1;
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	long long ret=1;
	for(int i=0;i<a/2;i++){
		for(int j=0;j<b/2;j++){
			s[0]=in[i][j];
			s[1]=in[i][b-1-j];
			s[2]=in[a-1-i][j];
			s[3]=in[a-1-i][b-1-j];
			std::sort(s,s+4);
			int cnt=0;
			do{
				cnt++;
			}while(next_permutation(s,s+4));
			if(cnt==24){
				ret=ret*12%mod;
				UNION(i,j+a/2);
			}else{
				ret=ret*cnt%mod;
			}
		}
	}
	for(int i=0;i<a/2+b/2;i++){
		if(FIND(i)!=i){
			ret=ret*2%mod;
		}
	}
	if(a%2){
		for(int i=0;i<b;i++)t[i]=in[a/2][i];
		reverse(t,t+b);
		bool ok=false;
		for(int i=0;i<b;i++)if(t[i]!=in[a/2][i])ok=true;
		if(ok)ret=ret*2%mod;
	}
	if(b%2){
		for(int i=0;i<a;i++)t[i]=in[i][b/2];
		reverse(t,t+a);
		bool ok=false;
		for(int i=0;i<a;i++)if(t[i]!=in[i][b/2])ok=true;
		if(ok)ret=ret*2%mod;
	}
	printf("%lld\n",ret);
}
```