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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < (int)v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  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)]; }
};


ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll h,w;
vector<string> s;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>h>>w;
  s.resize(h);
  rep(i,h)cin>>s[i];

  ll res=1;
  if(h%2==1){
    ll mid=h/2;
    bool isp=true;
    rep(j,w)if(s[mid][j]!=s[mid][w-1-j])isp=false;
    if(!isp){
      res*=2;
    }

    vector<string> ns;
    rep(i,h){
      if(i==mid)continue;
      ns.push_back(s[i]);
    }
    s=ns;
    h--;
  }

  if(w%2==1){
    ll mid=w/2;
    bool isp=true;
    rep(i,h)if(s[i][mid]!=s[h-1-i][mid])isp=false;
    if(!isp){
      res*=2;
    }

    vector<string> ns;
    rep(i,h){
      string tmp;
      rep(j,w){
        if(j==mid)continue;
        tmp+=s[i][j];
      }
      ns.push_back(tmp);
    }
    s=ns;
    w--;
  }

  UnionFind uf((h/2)+(w/2));
  rep(i,h/2)rep(j,w/2){
    map<char,ll> cnt;
    cnt[s[i][j]]++;
    cnt[s[i][w-1-j]]++;
    cnt[s[h-1-i][j]]++; 
    cnt[s[h-1-i][w-1-j]]++;

    if(cnt.size()==4){
      uf.unite(i,(h/2)+j);
      res*=mod_pow(2,mod-2);
      res%=mod;
    }

    ll cnta=24;
    for(auto it : cnt){
      rep(k,it.se)(cnta*=mod_pow(k+1,mod-2))%=mod;
    }
    (res*=cnta)%=mod;
  }

  set<ll> comp;
  rep(i,h/2)comp.insert(uf.find(i));
  rep(j,w/2)comp.insert(uf.find((h/2)+j));

  res*=mod_pow(2,(h/2)+(w/2)-comp.size());
  res%=mod;
  cout<<res<<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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < (int)v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  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)]; }
};


ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll h,w;
vector<string> s;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>h>>w;
  s.resize(h);
  rep(i,h)cin>>s[i];

  ll res=1;
  if(h%2==1){
    ll mid=h/2;
    bool isp=true;
    rep(j,w)if(s[mid][j]!=s[mid][w-1-j])isp=false;
    if(!isp){
      res*=2;
    }

    vector<string> ns;
    rep(i,h){
      if(i==mid)continue;
      ns.push_back(s[i]);
    }
    s=ns;
    h--;
  }

  if(w%2==1){
    ll mid=w/2;
    bool isp=true;
    rep(i,h)if(s[i][mid]!=s[h-1-i][mid])isp=false;
    if(!isp){
      res*=2;
    }

    vector<string> ns;
    rep(i,h){
      string tmp;
      rep(j,w){
        if(j==mid)continue;
        tmp+=s[i][j];
      }
      ns.push_back(tmp);
    }
    s=ns;
    w--;
  }

  UnionFind uf((h/2)+(w/2));
  rep(i,h/2)rep(j,w/2){
    map<char,ll> cnt;
    cnt[s[i][j]]++;
    cnt[s[i][w-1-j]]++;
    cnt[s[h-1-i][j]]++; 
    cnt[s[h-1-i][w-1-j]]++;

    if(cnt.size()==4){
      uf.unite(i,(h/2)+j);
      res*=mod_pow(2,mod-2);
      res%=mod;
    }

    ll cnta=24;
    for(auto it : cnt){
      rep(k,it.se)(cnta*=mod_pow(k+1,mod-2))%=mod;
    }
    (res*=cnta)%=mod;
  }

  set<ll> comp;
  rep(i,h/2)comp.insert(uf.find(i));
  rep(j,w/2)comp.insert(uf.find((h/2)+j));

  res*=mod_pow(2,(h/2)+(w/2)-comp.size());
  res%=mod;
  cout<<res<<endl;

  return 0;
}

```