#pragma GCC optimize("Ofast") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } inline double time() { return static_cast(chrono::duration_cast(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9; } constexpr int mod = 1e9+7; void add(int &x,int y){ x += y; if(x >= mod) x -= mod; } int dx[]={0,1}; int dy[]={1,0}; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int h,w; cin >> h >> w; vector s(h); for(int i=0;i> s[i]; } using P = pair; map,int> mp; if(s[0][0] == s[h-1][w-1]) mp[{{0,0},{h-1,w-1}}] = 1; int loop = (h+w)/2-1; int res = 0; for(int _=0;_,int> nmp; for(auto &p:mp){ int _x1 = p.first.first.first, _y1 = p.first.first.second; int _x2 = p.first.second.first, _y2 = p.first.second.second; for(int i=0;i<2;i++){ int nx1 = _x1 + dx[i]; int ny1 = _y1 + dy[i]; for(int j=0;j<2;j++){ int nx2 = _x2 - dx[j]; int ny2 = _y2 - dy[j]; if(nx1 <= nx2 and ny1 <= ny2 and s[nx1][ny1] == s[nx2][ny2]){ add(nmp[{{nx1,ny1},{nx2,ny2}}], p.second); } } } } swap(nmp,mp); } for(auto p:mp){ auto v1 = p.first.first, v2 = p.first.second; if(abs(v1.first-v2.first)+abs(v1.second-v2.second) <= 1){ add(res, p.second); } } cout << res << endl; }