#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int MN = 222;

int N, M;
char G[MN][MN];
int chk[MN][MN];
vector<int> R, C;

int main() {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < N; i++) {
        scanf("\n");
        for(int j = 0; j < M; j++) {
            scanf("%c", &G[i][j]);
        }
    }

    int ans = 1;
    if(N % 2) {
        int found = 0;
        for(int i = 0; i < M / 2; i++) if(G[N / 2][i] != G[N / 2][M - 1 - i]) {
            found = 1;
            break;
        }
        if(found) ans = 1LL * ans * 2 % mod;
    }
    if(M % 2) {
        int found = 0;
        for(int i = 0; i < N / 2; i++) if(G[i][M / 2] != G[N - 1 - i][M / 2]) {
            found = 1;
            break;
        }
        if(found) ans = 1LL * ans * 2 % mod;
    }

    for(int i = 0; i < N / 2; i++) {
        for(int j = 0; j < M / 2; j++) {
            vector<char> X;
            unordered_map<char, int> dx;
            X.push_back(G[i][j]);
            X.push_back(G[N - 1 - i][j]);
            X.push_back(G[i][M - 1 - j]);
            X.push_back(G[N - 1 - i][M - 1 - j]);
            sort(X.begin(), X.end());
            X.resize(unique(X.begin(), X.end()) - X.begin());
            for(int i = 0; i < X.size(); i++) dx[X[i]] = i;

            vector<int> cnt(4, 0);
            for(int a = 0; a < 2; a++) for(int b = 0; b < 2; b++) cnt[ dx[ G[ a? i : N - 1 - i ][ b? j : M - 1 - j ] ] ]++;

            if(X.size() == 4) {
                R.push_back(i);
                C.push_back(j);
                ans = 1LL * ans * 12 % mod;
            }
            else {
                int tmp = 24;
                for(int a = 0; a < 4; a++) for(int b = 1; b <= cnt[a]; b++) tmp /= b;
                ans = 1LL * ans * tmp % mod;
            }
        }
    }

    sort(R.begin(), R.end());
    sort(C.begin(), C.end());
    R.resize(unique(R.begin(), R.end()) - R.begin());
    C.resize(unique(C.begin(), C.end()) - C.begin());

    for(int i = 0; i < (int)R.size() + (int)C.size() - 1; i++) ans = 1LL * ans * 2 % mod;
    cout << ans;
}

### 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<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int MN = 222;

int N, M;
char G[MN][MN];
int chk[MN][MN];
vector<int> R, C;

int main() {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < N; i++) {
        scanf("\n");
        for(int j = 0; j < M; j++) {
            scanf("%c", &G[i][j]);
        }
    }

    int ans = 1;
    if(N % 2) {
        int found = 0;
        for(int i = 0; i < M / 2; i++) if(G[N / 2][i] != G[N / 2][M - 1 - i]) {
            found = 1;
            break;
        }
        if(found) ans = 1LL * ans * 2 % mod;
    }
    if(M % 2) {
        int found = 0;
        for(int i = 0; i < N / 2; i++) if(G[i][M / 2] != G[N - 1 - i][M / 2]) {
            found = 1;
            break;
        }
        if(found) ans = 1LL * ans * 2 % mod;
    }

    for(int i = 0; i < N / 2; i++) {
        for(int j = 0; j < M / 2; j++) {
            vector<char> X;
            unordered_map<char, int> dx;
            X.push_back(G[i][j]);
            X.push_back(G[N - 1 - i][j]);
            X.push_back(G[i][M - 1 - j]);
            X.push_back(G[N - 1 - i][M - 1 - j]);
            sort(X.begin(), X.end());
            X.resize(unique(X.begin(), X.end()) - X.begin());
            for(int i = 0; i < X.size(); i++) dx[X[i]] = i;

            vector<int> cnt(4, 0);
            for(int a = 0; a < 2; a++) for(int b = 0; b < 2; b++) cnt[ dx[ G[ a? i : N - 1 - i ][ b? j : M - 1 - j ] ] ]++;

            if(X.size() == 4) {
                R.push_back(i);
                C.push_back(j);
                ans = 1LL * ans * 12 % mod;
            }
            else {
                int tmp = 24;
                for(int a = 0; a < 4; a++) for(int b = 1; b <= cnt[a]; b++) tmp /= b;
                ans = 1LL * ans * tmp % mod;
            }
        }
    }

    sort(R.begin(), R.end());
    sort(C.begin(), C.end());
    R.resize(unique(R.begin(), R.end()) - R.begin());
    C.resize(unique(C.begin(), C.end()) - C.begin());

    for(int i = 0; i < (int)R.size() + (int)C.size() - 1; i++) ans = 1LL * ans * 2 % mod;
    cout << ans;
}

```