#include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; using mint = atcoder::modint; using M = vector>; __int128 det(M a, int n, bool flg) { if (n == 1) { return a[0][0]; } i64 ret = 0; for (auto i : views::iota(0, n)) { M sa; for (auto j : views::iota(0, n-1)) { sa.push_back(vector<__int128>()); int p = 0; for (auto k : views::iota(0, n)) { if (k == i) continue; sa[j].push_back(a[j + 1][k]); } } i64 f = flg && i % 2 ? -1 : 1; ret += f * a[0][i] * det(sa, n - 1, flg); } return ret; } int main() { FAST_IO int n, b; cin >> n >> b; M a; for (auto i : views::iota(0, n)) { a.push_back(vector<__int128>()); for (auto j : views::iota(0, n)) { long v; cin >> v; a[i].push_back(v); } } auto x = det(a, n, true); auto y = det(a, n, false); auto ret = (long)((y-x)/2%b); cout << ret << endl; }