#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
struct unionfind{
    vector<int> par, sz; int cnt;
    unionfind() {}
    unionfind(int n):cnt(n), par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x]; cnt--;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
	int h, w;
	cin>>h>>w;
	string s[202];
	for(int i=0; i<h; i++) cin>>s[i];
	ll ans=1;
	if(h&1){
		string t=s[h/2];
		reverse(t.begin(), t.end());
		if(s[h/2]!=t) ans*=2;
	}
	if(w&1){
		string t, u;
		for(int i=0; i<h; i++) t+=s[i][w/2];
		u=t;
		reverse(u.begin(), u.end());
		if(t!=u) ans*=2;
	}
  unionfind uf(h/2+w/2);
	for(int i=0; i<h/2; i++){
		for(int j=0; j<w/2; j++){
			string t; int cnt[3]={};
			t+=s[i][j];
			t+=s[h-1-i][j];
			t+=s[i][w-1-j];
			t+=s[h-1-i][w-1-j];
			int ind[4]={0, 1, 2, 3};
			set<string> st[2];
			do{
				int c=0;
				for(int k=0; k<4; k++) for(int l=k+1; l<4; l++) if(ind[k]>ind[l]) c^=1;
				string u;
				for(int k=0; k<4; k++) u+=t[ind[k]];
				st[c].insert(u);
			}while(next_permutation(ind, ind+4));
          for(auto u:st[0]) if(st[1].find(u)!=st[1].end()) cnt[2]++;
          for(int k=0; k<2; k++) cnt[k]=st[k].size()-cnt[2];
          if(cnt[0]==0) (ans*=cnt[2])%=MOD;
          else (ans*=cnt[0])%=MOD, uf.unite(i, j+h/2);
		}
	}
  for(int i=0; i<h/2+w/2-uf.cnt; i++) (ans*=2)%=MOD;
  cout<<ans<<endl;
	return 0;
}
### Prompt

Your challenge is to write 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
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
struct unionfind{
    vector<int> par, sz; int cnt;
    unionfind() {}
    unionfind(int n):cnt(n), par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x]; cnt--;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
	int h, w;
	cin>>h>>w;
	string s[202];
	for(int i=0; i<h; i++) cin>>s[i];
	ll ans=1;
	if(h&1){
		string t=s[h/2];
		reverse(t.begin(), t.end());
		if(s[h/2]!=t) ans*=2;
	}
	if(w&1){
		string t, u;
		for(int i=0; i<h; i++) t+=s[i][w/2];
		u=t;
		reverse(u.begin(), u.end());
		if(t!=u) ans*=2;
	}
  unionfind uf(h/2+w/2);
	for(int i=0; i<h/2; i++){
		for(int j=0; j<w/2; j++){
			string t; int cnt[3]={};
			t+=s[i][j];
			t+=s[h-1-i][j];
			t+=s[i][w-1-j];
			t+=s[h-1-i][w-1-j];
			int ind[4]={0, 1, 2, 3};
			set<string> st[2];
			do{
				int c=0;
				for(int k=0; k<4; k++) for(int l=k+1; l<4; l++) if(ind[k]>ind[l]) c^=1;
				string u;
				for(int k=0; k<4; k++) u+=t[ind[k]];
				st[c].insert(u);
			}while(next_permutation(ind, ind+4));
          for(auto u:st[0]) if(st[1].find(u)!=st[1].end()) cnt[2]++;
          for(int k=0; k<2; k++) cnt[k]=st[k].size()-cnt[2];
          if(cnt[0]==0) (ans*=cnt[2])%=MOD;
          else (ans*=cnt[0])%=MOD, uf.unite(i, j+h/2);
		}
	}
  for(int i=0; i<h/2+w/2-uf.cnt; i++) (ans*=2)%=MOD;
  cout<<ans<<endl;
	return 0;
}
```