#include #include using namespace std; using namespace atcoder; using mint = modint1000000007; const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } const int dx0[] = { -1,0 }; const int dy0[] = { 0,-1 }; const int dx1[] = { 1,0 }; const int dy1[] = { 0,1 }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h, w; cin >> h >> w; map, mint>dp; vectors(h); rep(i, h)cin >> s[i]; rrep(i, h) { rrep(j, w) { rep(k, h) { int l = h - 1 + w - 1 - i - j - k; if (k < i)continue; if (l < j)continue; if ((k < 0) || (h <= k))continue; if ((l < 0) || (w <= l))continue; if ((1 >= k - i) && (1 >= l - j) && (1 >= (k + l - i - j))) { if (s[i][j] == s[k][l]) { dp[{ {i, j}, { k,l }}] = 1; } } mint val = dp[{ {i, j}, { k,l }}]; rep(m, 2)rep(n, 2) { int ni = i + dx0[m]; int nj = j + dy0[m]; int nk = k + dx1[n]; int nl = l + dy1[n]; if ((ni < 0) || (h <= ni))continue; if ((nj < 0) || (w <= nj))continue; if ((nk < 0) || (h <= nk))continue; if ((nl < 0) || (w <= nl))continue; if (s[ni][nj] != s[nk][nl])continue; dp[{ {ni, nj}, { nk,nl }}] += val; //cout << i << j << k << l << endl; //cout << ni << nj << nk << nl << endl; } } } } /*for (auto[k, v] : dp) { cout << k.first.first << " " << k.first.second << endl; cout << k.second.first << " " << k.second.second << endl; cout << v.val() << endl; }*/ mint ans = dp[{ {0, 0}, { h - 1,w - 1 }}]; cout << ans.val() << endl; return 0; }