func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / _gcd(a, b)) * b;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   inline long long power(long long a, long long b) {     long long multiply = 1;     for (int i = (0); i < (b); i++) {       multiply *= a;     }     return multiply;   }   char given[505][505];   long long dp[505][505];   int n, m, modby;   long long calc(int x, int y) {     long long &ret = dp[x][y];     if (x == 2 && y == 0) return 1;     if (x == 0 && y == 1) return 0;     if (ret != -1) return ret;     ret = 0;     long long a;     if (x > 1) {       a = calc(x - 2, y) % modby;       a = (a * ((x * (x - 1)) / 2) % modby) % modby;       ret += a % modby;     }     if (y > 1) {       a = calc(x + 2, y - 2) % modby;       a = (a * ((y * (y - 1)) / 2) % modby) % modby;       ret += a % modby;     }     if (x != 0 && y != 0) {       a = calc(x, y - 1) % modby;       a = (a * (x * y) % modby) % modby;       ret += a % modby;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> modby;     memset(dp, -1, sizeof(dp));     for (int i = (0); i < (m); i++) {       for (int j = (0); j < (n); j++) cin >> given[i][j];     }     int zeros = 0, ones = 0;     for (int i = (0); i < (n); i++) {       int x = 0;       for (int j = (0); j < (m); j++) {         if (given[j][i] ==  1 ) x++;       }       if (x == 0)         zeros++;       else if (x == 1)         ones++;     }     if (n == m)       cout << 1 << endl;     else       cout << calc(ones, zeros) % modby << endl;     return 0;   }   