#include using namespace std; #define rep(i,n) for(int i=0;i=0;i--) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3k5NXAD ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair; using vi=vector; void print(){cout<<'\n';} template void print(const h&v,const t&...u){cout< struct modint{ ll x; // typedef long long ll; modint(ll x=0):x((x%mod+mod)%mod){} modint operator-()const{return modint(-x);} modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;} modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;} modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;} modint operator+(const modint a)const{modint res(*this); return res+=a;} modint operator-(const modint a)const{modint res(*this); return res-=a;} modint operator*(const modint a)const{modint res(*this); return res*=a;} modint pow(ll n)const{ modint res=1,x(*this); while(n){ if(n&1)res*=x; x*=x; n>>=1; } return res; } modint inv()const{return pow(mod-2);} }; using mint=modint<1000'000'007>; signed main(){ _3k5NXAD; int h,w; std::cin>>h>>w; vec(string) a; rep(i,h){ string s; std::cin>>s; a.emplace_back(s); } vec(vec(vec(mint))) dp(w+1,vec(vec(mint))(w+1,vec(mint)((h+w)/2+1))); if(a[0][0]!=a[h-1][w-1]){ print(0); return 0; } dp[0][0][0]=1; rep(k,(h+w)/2+1){ rep(i,w+1){ if(i>k) break; rep(j,w+1){ if(j>k) break; int sh=k-i,sw=i; int th=h-1-(k-j),tw=w-1-j; //rl if(sw+1=0 and a[sh][sw+1]==a[th][tw-1]){ dp[i+1][j+1][k+1]+=dp[i][j][k]; } //dl if(sh+1=0 and a[sh+1][sw]==a[th][tw-1]){ dp[i][j+1][k+1]+=dp[i][j][k]; } //ru if(sw+1=0 and a[sh][sw+1]==a[th-1][tw]){ dp[i+1][j][k+1]+=dp[i][j][k]; } // du if(sh+1=0 and a[sh+1][sw]==a[th-1][tw]){ dp[i][j][k+1]+=dp[i][j][k]; } } } } // print(dp[1][0][1].x); const int di[]={1,-1,0,0}; const int dj[]={0,0,1,-1}; auto adj=[&](int sx,int sy,int tx,int ty)->bool{ rep(dir,4){ int nx=sx+di[dir],ny=sy+dj[dir]; if(nx==tx and ny==ty){ return 1; } } return 0; }; mint ans=0; int k=(h+w-1)/2-1; rep(i,w+1){ rep(j,w+1){ int sh=k-i,sw=i; int th=h-1-(k-j),tw=w-1-j; if((h+w-1)%2==0){ if(adj(sh,sw,th,tw)){ ans+=dp[i][j][k]; } }else{ rep(dir,4){ int nx=sh+di[dir],ny=sw+dj[dir]; if(adj(nx,ny,th,tw)){ ans+=dp[i][j][k]; } } } } } print(ans.x); // return 0; }