#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

int main() {
  int H, W; scanf("%d%d", &H, &W);
  static char S[200][201];
  for(int i = 0; i < H; ++i) {
    scanf(" %200s", S[i]);
  }
  static bool has_parity[100][100];
  int count = 1;
  int H2 = H/2;
  int W2 = W/2;
  for(int i = 0; i < H2; ++i) {
    for(int j = 0; j < W2; ++j) {
      char chs[4] = {S[i][j], S[i][W-1-j], S[H-1-i][j], S[H-1-i][W-1-j]};
      sort(chs, chs+4);
      int arbity;
      bool hp = false;
      if(chs[0] == chs[1] && chs[1] == chs[2] && chs[2] == chs[3]) {
        arbity = 1;
      } else if(chs[0] == chs[1] && chs[2] == chs[3]) {
        arbity = 6;
      } else if(chs[1] == chs[2] && chs[2] == chs[3]) {
        arbity = 4;
      } else if(chs[0] == chs[1] && chs[1] == chs[2]) {
        arbity = 4;
      } else if(chs[0] == chs[1] || chs[1] == chs[2] || chs[2] == chs[3]) {
        arbity = 12;
      } else {
        arbity = 12;
        hp = true;
      }
      count = (int64_t)count * arbity % MOD;
      has_parity[i][j] = hp;
    }
  }
  if(H % 2 == 1) {
    bool hp = false;
    for(int j = 0; j < W2; ++j) {
      if(S[H/2][j] != S[H/2][W-1-j]) hp = true;
    }
    if(hp) count = (int64_t)count * 2 % MOD;
  }
  if(W % 2 == 1) {
    bool hp = false;
    for(int i = 0; i < H2; ++i) {
      if(S[i][W/2] != S[H-1-i][W/2]) hp = true;
    }
    if(hp) count = (int64_t)count * 2 % MOD;
  }
  vector<char> vis(H2+W2);
  function<void(int)> dfs = [&](int v) {
    if(vis[v]) return;
    vis[v] = true;
    if(v < H2) {
      int i = v;
      for(int j = 0; j < W2; ++j) {
        if(has_parity[i][j]) {
          dfs(H2+j);
        }
      }
    } else {
      int j = v-H2;
      for(int i = 0; i < H2; ++i) {
        if(has_parity[i][j]) {
          dfs(i);
        }
      }
    }
  };
  int resolvable_parities = H2+W2;
  for(int i = 0; i < H2; ++i) {
    if(!vis[i]) {
      --resolvable_parities;
      dfs(i);
    }
  }
  for(int j = 0; j < W2; ++j) {
    if(!vis[H2+j]) {
      --resolvable_parities;
      dfs(H2+j);
    }
  }
  for(int i = 0; i < resolvable_parities; ++i) {
    count = (int64_t)count * 2 % MOD;
  }
  printf("%d\n", count);
  return 0;
}

### 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
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

int main() {
  int H, W; scanf("%d%d", &H, &W);
  static char S[200][201];
  for(int i = 0; i < H; ++i) {
    scanf(" %200s", S[i]);
  }
  static bool has_parity[100][100];
  int count = 1;
  int H2 = H/2;
  int W2 = W/2;
  for(int i = 0; i < H2; ++i) {
    for(int j = 0; j < W2; ++j) {
      char chs[4] = {S[i][j], S[i][W-1-j], S[H-1-i][j], S[H-1-i][W-1-j]};
      sort(chs, chs+4);
      int arbity;
      bool hp = false;
      if(chs[0] == chs[1] && chs[1] == chs[2] && chs[2] == chs[3]) {
        arbity = 1;
      } else if(chs[0] == chs[1] && chs[2] == chs[3]) {
        arbity = 6;
      } else if(chs[1] == chs[2] && chs[2] == chs[3]) {
        arbity = 4;
      } else if(chs[0] == chs[1] && chs[1] == chs[2]) {
        arbity = 4;
      } else if(chs[0] == chs[1] || chs[1] == chs[2] || chs[2] == chs[3]) {
        arbity = 12;
      } else {
        arbity = 12;
        hp = true;
      }
      count = (int64_t)count * arbity % MOD;
      has_parity[i][j] = hp;
    }
  }
  if(H % 2 == 1) {
    bool hp = false;
    for(int j = 0; j < W2; ++j) {
      if(S[H/2][j] != S[H/2][W-1-j]) hp = true;
    }
    if(hp) count = (int64_t)count * 2 % MOD;
  }
  if(W % 2 == 1) {
    bool hp = false;
    for(int i = 0; i < H2; ++i) {
      if(S[i][W/2] != S[H-1-i][W/2]) hp = true;
    }
    if(hp) count = (int64_t)count * 2 % MOD;
  }
  vector<char> vis(H2+W2);
  function<void(int)> dfs = [&](int v) {
    if(vis[v]) return;
    vis[v] = true;
    if(v < H2) {
      int i = v;
      for(int j = 0; j < W2; ++j) {
        if(has_parity[i][j]) {
          dfs(H2+j);
        }
      }
    } else {
      int j = v-H2;
      for(int i = 0; i < H2; ++i) {
        if(has_parity[i][j]) {
          dfs(i);
        }
      }
    }
  };
  int resolvable_parities = H2+W2;
  for(int i = 0; i < H2; ++i) {
    if(!vis[i]) {
      --resolvable_parities;
      dfs(i);
    }
  }
  for(int j = 0; j < W2; ++j) {
    if(!vis[H2+j]) {
      --resolvable_parities;
      dfs(H2+j);
    }
  }
  for(int i = 0; i < resolvable_parities; ++i) {
    count = (int64_t)count * 2 % MOD;
  }
  printf("%d\n", count);
  return 0;
}

```