#include #include using namespace std; using mint = atcoder::modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector A(n); for(auto &&str : A) cin >> str; if(A[0][0] != A[n - 1][n - 1]){ cout << "0\n"; return 0; } auto B = A; reverse(B.begin(), B.end()); for(auto &&str : B) reverse(str.begin(), str.end()); vector dp(1, vector(1)); dp[0][0] = 1; for(int a = 0; a + 1 < n; a++){ vector ndp(a + 2, vector(a + 2)); for(int y1 = 0; y1 <= a; y1++){ int x1 = a - y1; for(int y2 = 0; y2 <= a; y2++){ int x2 = a - y2; if(A[y1][x1] != B[y2][x2]) continue; if(A[y1 + 1][x1] == B[y2][x2 + 1]) ndp[y1 + 1][y2] += dp[y1][y2]; if(A[y1 + 1][x1] == B[y2 + 1][x2]) ndp[y1 + 1][y2 + 1] += dp[y1][y2]; if(A[y1][x1 + 1] == B[y2 + 1][x2]) ndp[y1][y2 + 1] += dp[y1][y2]; if(A[y1][x1 + 1] == B[y2][x2 + 1]) ndp[y1][y2] += dp[y1][y2]; } } swap(dp, ndp); } mint ans; for(int y1 = 0; y1 < n; y1++){ int x1 = n - 1 - y1; int y2 = n - 1 - y1; int x2 = n - 1 - x1; ans += dp[y1][y2]; } cout << ans.val() << '\n'; }