#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	int H, W; cin >> H >> W;
	vector<string> a(H);
	rep(y, H) cin >> a[y];
	ll ans = 1;
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++) {
			int _y = H - 1 - y, _x = W - 1 - x;
			if (y > _y || x > _x) continue;
			if (y < _y && x < _x) {
				map<char, int> mp;
				mp[a[y][x]]++;
				mp[a[y][_x]]++;
				mp[a[_y][x]]++;
				mp[a[_y][_x]]++;
				if (mp.size() == 2) {
					int ma = 0;
					for (auto z: mp) ma = max(ma, z.second);
					if (ma == 2) ans = ans * 6 % MOD;
					else ans = ans * 4 % MOD;
				}
				if (mp.size() == 3) ans = ans * 12 % MOD;
				if (mp.size() == 4) {
					ans = ans * 12 % MOD;
					a[y][x] = '*';
				}
			}
			if (y == _y && x < _x) if (a[y][x] != a[y][_x]) a[y][x] = '*';
			if (y < _y && x == _x) if (a[y][x] != a[_y][x]) a[y][x] = '*';
		}
	union_find uf((H / 2) * (W / 2));
	for (int y = 0; y < H; y++) {
		int _y = H - 1 - y;
		if (y < _y) {
			for (int x = 0; x < W / 2; x++)
				for (int _x = x + 1; _x < W / 2; _x++)
					if (a[y][x] == '*' && a[y][_x] == '*')
						uf.unite(y * (W / 2) + x, y * (W / 2) + _x);
		}
	}
	for (int x = 0; x < W; x++) {
		int _x = W - 1 - x;
		if (x < _x) {
			for (int y = 0; y < H / 2; y++)
				for (int _y = y + 1; _y < H / 2; _y++)
					if (a[y][x] == '*' && a[_y][x] == '*')
						uf.unite(y * (W / 2) + x, _y * (W / 2) + x);
		}
	}
	vector<set<int> > Y((H / 2) * (W / 2)), X((H / 2) * (W / 2));
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++) {
			int _y = H - 1 - y, _x = W - 1 - x;
			if (y < _y && x < _x) {
				if (a[y][x] == '*') {
					int k = uf.find(y * (W / 2) + x);
					Y[k].insert(y);
					X[k].insert(x);
				}
			}
		}
	for (int k = 0; k < (H / 2) * (W / 2); k++)
		if (!Y[k].empty()) {
			int t = Y[k].size() + X[k].size();
			t--;
			while (t--) ans = ans * 2 % MOD;
		}
	for (int y = 0; y < H; y++) {
		int _y = H - 1 - y;
		if (y == _y) {
			bool ok = false;
			for (int x = 0; x < W; x++)
				if (a[y][x] == '*')
					ok = true;
			if (ok) ans = ans * 2 % MOD;
		}
	}
	for (int x = 0; x < W; x++) {
		int _x = W - 1 - x;
		if (x == _x) {
			bool ok = false;
			for (int y = 0; y < H; y++)
				if (a[y][x] == '*')
					ok = true;
			if (ok) ans = ans * 2 % MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

### Prompt

Create a solution in CPP for 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 <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	int H, W; cin >> H >> W;
	vector<string> a(H);
	rep(y, H) cin >> a[y];
	ll ans = 1;
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++) {
			int _y = H - 1 - y, _x = W - 1 - x;
			if (y > _y || x > _x) continue;
			if (y < _y && x < _x) {
				map<char, int> mp;
				mp[a[y][x]]++;
				mp[a[y][_x]]++;
				mp[a[_y][x]]++;
				mp[a[_y][_x]]++;
				if (mp.size() == 2) {
					int ma = 0;
					for (auto z: mp) ma = max(ma, z.second);
					if (ma == 2) ans = ans * 6 % MOD;
					else ans = ans * 4 % MOD;
				}
				if (mp.size() == 3) ans = ans * 12 % MOD;
				if (mp.size() == 4) {
					ans = ans * 12 % MOD;
					a[y][x] = '*';
				}
			}
			if (y == _y && x < _x) if (a[y][x] != a[y][_x]) a[y][x] = '*';
			if (y < _y && x == _x) if (a[y][x] != a[_y][x]) a[y][x] = '*';
		}
	union_find uf((H / 2) * (W / 2));
	for (int y = 0; y < H; y++) {
		int _y = H - 1 - y;
		if (y < _y) {
			for (int x = 0; x < W / 2; x++)
				for (int _x = x + 1; _x < W / 2; _x++)
					if (a[y][x] == '*' && a[y][_x] == '*')
						uf.unite(y * (W / 2) + x, y * (W / 2) + _x);
		}
	}
	for (int x = 0; x < W; x++) {
		int _x = W - 1 - x;
		if (x < _x) {
			for (int y = 0; y < H / 2; y++)
				for (int _y = y + 1; _y < H / 2; _y++)
					if (a[y][x] == '*' && a[_y][x] == '*')
						uf.unite(y * (W / 2) + x, _y * (W / 2) + x);
		}
	}
	vector<set<int> > Y((H / 2) * (W / 2)), X((H / 2) * (W / 2));
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++) {
			int _y = H - 1 - y, _x = W - 1 - x;
			if (y < _y && x < _x) {
				if (a[y][x] == '*') {
					int k = uf.find(y * (W / 2) + x);
					Y[k].insert(y);
					X[k].insert(x);
				}
			}
		}
	for (int k = 0; k < (H / 2) * (W / 2); k++)
		if (!Y[k].empty()) {
			int t = Y[k].size() + X[k].size();
			t--;
			while (t--) ans = ans * 2 % MOD;
		}
	for (int y = 0; y < H; y++) {
		int _y = H - 1 - y;
		if (y == _y) {
			bool ok = false;
			for (int x = 0; x < W; x++)
				if (a[y][x] == '*')
					ok = true;
			if (ok) ans = ans * 2 % MOD;
		}
	}
	for (int x = 0; x < W; x++) {
		int _x = W - 1 - x;
		if (x == _x) {
			bool ok = false;
			for (int y = 0; y < H; y++)
				if (a[y][x] == '*')
					ok = true;
			if (ok) ans = ans * 2 % MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

```