#include #include using namespace std; using i32 = int; using i64 = long long; using i128 = __int128_t; using f64 = double; using p2 = pair; using el = tuple; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } void _main() { i64 n; cin >> n; vector s(n); for (i64 i = 0; i < n; i++) cin >> s[i]; map, mint> mp; for (i64 i = 0; i < n; i++) mp[{{i, n - i - 1}, {i, n - i - 1}}] = 1; i64 nxt[5] = {0, -1, 0, 1, 0}; for (i64 k = n - 1; k >= 1; k--) { map, mint> nmp; for (auto [pp, c] : mp) { auto [a, b] = pp; auto [i1, j1] = a; auto [i2, j2] = b; for (i64 x = 0; x < 2; x++) for (i64 y = 2; y < 4; y++) { i64 ni1 = i1 + nxt[x], nj1 = j1 + nxt[x + 1]; i64 ni2 = i2 + nxt[y], nj2 = j2 + nxt[y + 1]; if (ni1 < 0 || nj1 < 0 || ni2 >= n || nj2 >= n) continue; if (s[ni1][nj1] != s[ni2][nj2]) continue; nmp[{{ni1, nj1}, {ni2, nj2}}] += c; } } swap(mp, nmp); } mint ans = 0; for (auto [pp, c] : mp) { ans += c; } cout << ans.val() << "\n"; }