#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 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[4] = { 1,0 }; const int dy0[4] = { 0,1 }; const int dx1[4] = { -1,0 }; const int dy1[4] = { 0,-1 }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; vectors(n); rep(i, n) cin >> s[i]; if (s[0][0] != s[n - 1][n - 1]) { cout << 0 << endl; return 0; } map, mint>dp; dp[{ {0, 0}, { n - 1,n - 1 }}] = 1; rep(i, n - 1) { map, mint>ndp; for (auto[k, v] : dp) { auto p0 = k.first; auto p1 = k.second; //cout << p0.first << " " << p0.second << ":" << p1.first << " " << p1.second << endl; //cout << v.val() << endl; rep(i, 2)rep(j, 2) { auto cp0 = p0; auto cp1 = p1; cp0.first += dx0[i]; cp0.second += dy0[i]; if (cp0.first < 0 || cp0.first >= n)continue; if (cp0.second < 0 || cp0.second >= n)continue; cp1.first += dx1[j]; cp1.second += dy1[j]; if (cp1.first < 0 || cp1.first >= n)continue; if (cp1.second < 0 || cp1.second >= n)continue; if (s[cp0.first][cp0.second] != s[cp1.first][cp1.second])continue; ndp[{cp0, cp1}] += v; } } swap(dp, ndp); } mint ans = 0; for (auto[k, v] : dp)if (k.first == k.second)ans += v; cout << ans.val() << endl; return 0; }