#include #include #include #include #include using namespace std; using ll = long long; int main() { int N; cin >> N; vector> c(N, vector(N)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> c[i][j]; vector> S(N); auto DFS1 = [&](auto dfs, int x, int y, string s) -> void{ if (x + y == N - 1) { S[x][s]++; return; } if (x + 1 != N) dfs(dfs, x + 1, y, s + c[x][y]); if (y + 1 != N) dfs(dfs, x, y + 1, s + c[x][y]); }; DFS1(DFS1, 0, 0, ""); ll ans = 0; const ll MOD = 998244353; auto DFS2 = [&](auto dfs, int x, int y, string s) { if (x + y == N - 1) { ans += S[x][s]; ans %= MOD; return; } if (x != 0) dfs(dfs, x - 1, y, s + c[x][y]); if (y != 0) dfs(dfs, x, y - 1, s + c[x][y]); }; DFS2(DFS2, N - 1, N - 1, ""); cout << ans << endl; return 0; }