#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector Grid(n, vector(n)); rep(i, n) rep(j, n) cin >> Grid[i][j]; int ans = 0; rep(bit, 1 << (2 * n - 2)) { if (popcount(ull(bit)) != n - 1) continue; string s = { Grid[0][0] }; pair pos = { 0, 0 }; rep(i, 2 * n - 2) { if (bit & (1 << i)) pos.first++; else pos.second++; s += Grid[pos.first][pos.second]; } assert(pos == make_pair(n - 1, n - 1)); string t = s; reverse(t.begin(), t.end()); // cerr << s << ' ' << t << '\n'; if (s == t) ++ans; } cout << ans << '\n'; return 0; }