malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char types[11];   bool possible[1005][12][11];   int m;   int pre[1005][12][11][3];   int main() {     scanf( %s , types);     scanf( %d , &m);     for (int i = 0; i < 11; ++i)       for (int d = 0; d <= 10; ++d) possible[0][i][d] = 0;     possible[0][0][0] = 1;     int best = 0;     int bestVal[3];     for (int j = 1; j <= m; ++j) {       for (int d = 0; d <= 10; ++d) possible[j][0][d] = 0;       for (int i = 1; i < 11; ++i)         for (int d = 0; d <= 10; ++d) {           possible[j][i][d] = 0;           if (types[i - 1] ==  0  || !d || d > i) {             continue;           }           for (int k = 0; k < 11; ++k) {             if (!possible[j - 1][k][i - d] || k == i) continue;             possible[j][i][d] = 1;             pre[j][i][d][0] = j - 1;             pre[j][i][d][1] = k;             pre[j][i][d][2] = i - d;             best = j;             bestVal[0] = j;             bestVal[1] = i;             bestVal[2] = d;           }         }     }     if (best == m) {       printf( YES n );       int j = bestVal[0], i = bestVal[1], d = bestVal[2];       int ansList[1005];       ansList[j - 1] = i;       while (j > 1) {         int jp = pre[j][i][d][0], ip = pre[j][i][d][1], kp = pre[j][i][d][2];         j = jp;         i = ip;         d = kp;         ansList[j - 1] = i;       }       for (int a = 0; a < m; ++a) printf( %d  , ansList[a]);     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, cnt[1010], ans;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;     }     for (int i = 1; i <= (n + 1) / 2; i++) {       int idx = -1, mx = -1;       for (int j = 1; j <= k; j++) {         if (cnt[j] > mx) {           mx = cnt[j];           idx = j;         }       }       if (cnt[idx] >= 2) {         ans += 2;         cnt[idx] -= 2;       } else {         ans += cnt[idx];         cnt[idx] = 0;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   short c1[25001], c2[25001];   int a[12][12];   int main() {     int n, m, res = 0;     cin >> n >> m;     char c;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> c;         if (c ==  W )           a[i][j] = 2;         else if (c ==  P )           a[i][j] = 1;         else           a[i][j] = 0;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] == 2) {           if (a[max(i - 1, 0)][j] == 1) {             res++;             a[max(i - 1, 0)][j] = 0;             continue;           }           if (a[i][max(j - 1, 0)] == 1) {             a[i][max(j - 1, 0)] = 0;             res++;             continue;           }           if (a[i + 1][j] == 1) {             res++;             a[i + 1][j] = 0;             continue;           }           if (a[i][j + 1] == 1) {             a[i][j + 1] = 0;             res++;           }         }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[5000], rev[5000];   bool used[5000];   vector<int> ord;   bool curcm[5000];   vector<int> cm;   void dfs1(int v) {     used[v] = true;     for (int to : g[v])       if (!used[to]) {         dfs1(to);       }     ord.push_back(v);   }   void dfs2(int v) {     used[v] = true;     cm.push_back(v);     curcm[v] = true;     for (int to : rev[v])       if (!used[to]) {         dfs2(to);       }   }   int dist[5000][5000];   int q[5000];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(m); ++i) {       int from, to;       scanf( %d%d , &from, &to), --from, --to;       g[from].push_back(to);       rev[to].push_back(from);     }     memset(dist, -1, sizeof dist);     for (int i = 0; i < (int)(n); ++i) {       int(&d)[5000] = dist[i];       d[i] = 0;       q[0] = i;       for (int qh = 0, qt = 1; qh < qt; ++qh) {         int v = q[qh];         for (int to : g[v])           if (d[to] == -1) {             d[to] = d[v] + 1;             q[qt++] = to;           }       }     }     for (int i = 0; i < (int)(n); ++i) used[i] = false;     for (int i = 0; i < (int)(n); ++i)       if (!used[i]) {         dfs1(i);       }     reverse(ord.begin(), ord.end());     for (int i = 0; i < (int)(n); ++i) used[i] = false;     int ans = n;     for (int v : ord)       if (!used[v]) {         cm.clear();         for (int i = 0; i < (int)(n); ++i) curcm[i] = false;         dfs2(v);         bool ok = false;         for (int x : cm) {           for (int y : g[x])             if (!curcm[y]) {               ok = true;               break;             }           if (ok) break;         }         if (!ok && (int)cm.size() > 1) {           ++ans;           int z = 12341234;           for (int x : cm)             for (int y : cm) {               if (y == x) break;               z = min(z, dist[x][y] + dist[y][x]);             }           ans += z * 998;         }       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const long double pi = acos(-1);   int N, M;   string s[100];   long long d[1 << 20];   long double f[1 << 20];   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cout << fixed;     cout.tie(0);     cin >> N;     for (int(i) = 0, j123 = N; (i) < j123; (i)++) cin >> s[i];     M = s[0].size();     for (int(i) = 0, j123 = N; (i) < j123; (i)++)       for (int(j) = 0, j123 = N; (j) < j123; (j)++)         if (i != j) {           int same = 0;           for (int(k) = 0, j123 = M; (k) < j123; (k)++)             if (s[i][k] == s[j][k]) same |= (1 << k);           d[same] |= (1LL << i);         }     for (int mask = (1 << M) - 1; mask >= 0; mask--)       for (int(i) = 0, j123 = M; (i) < j123; (i)++)         if (!((mask >> i) & 1)) d[mask] |= d[mask | (1 << i)];     for (int mask = (1 << M) - 1; mask >= 0; mask--) {       if (d[mask] == 0) continue;       long double tot = 0;       int cnt = 0;       for (int(i) = 0, j123 = M; (i) < j123; (i)++)         if (!((mask >> i) & 1)) {           cnt++;           tot += f[mask | (1 << i)] * __builtin_popcountll(d[mask | (1 << i)]) /                  __builtin_popcountll(d[mask]);         }       tot /= cnt;       tot += 1;       f[mask] = tot;     }     cout << f[0] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(0) * 2;   const double EPS = 1e-8;   const long long MOD = 1e9 + 7;   const int MAXN = 1e4 + 5;   const int oo = 1e9;   const double foo = 1e30;   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcounll(s);   }   template <class T>   T sqr(T x) {     return x * x;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   int n;   long double val[MAXN], f[MAXN];   vector<int> has[MAXN], ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int s, r;       scanf( %d%d , &s, &r);       if (r > val[s]) {         val[s] = r;         has[s].clear();       }       if (r == val[s]) has[s].push_back(i);     }     for (int i = 1; i <= 10000; i++) {       if (!has[i].empty()) f[i] = val[i] / i;     }     for (int i = 1; i <= 10000; i++) {       if (has[i].empty()) continue;       long double r = 10000000000000.0;       long double l = 0;       int cant = 0;       for (int j = 1; j < i; j++) {         if (!has[j].empty() && val[j] > val[i]) {           long double tmp =               ((long double)i - (long double)j) / (val[j] - val[i]) * f[i] * f[j];           r = min(r, tmp);         }       }       for (int j = i + 1; j <= 10000; j++) {         if (cant) break;         if (!has[j].empty()) {           if (val[i] > val[j]) {             long double tmp = ((long double)j - (long double)i) /                               (val[i] - val[j]) * f[i] * f[j];             l = max(l, tmp);           } else             cant = 1;         }       }       if ((l == 10000000000000.0 || r == 0 || l <= r) && !cant) {         for (int j = 0; j < ((int)(has[i]).size()); j++) {           ans.push_back(has[i][j]);         }       }     }     sort(ans.begin(), ans.end());     for (int i = 0; i < ((int)(ans).size()); i++) {       printf( %d  , ans[i] + 1);     }   }
#include <bits/stdc++.h>   using namespace std;   using LLI = long long;   long long NWD(long long blep, long long b) {     return (b == 0) ? blep : NWD(b, blep % b);   }   long long NWW(long long blep, long long b) { return blep / NWD(blep, b) * b; }   const int MX = 3e5 + 400;   int n, T[MX];   long long ans[MX];   void out() {     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> T[i];     T[n + 1] = T[1];     T[0] = T[n];     for (int i = 1; i <= n; i++) {       if (T[i] > T[i - 1]) {         ans[i] = T[i];         if (i == 1)           ans[n + 1] = ans[1];         else if (i == n)           ans[0] = ans[n];         for (int j = i - 1; j > i - n; j--) {           int blep = (j + n) % n;           if (blep == 0) blep = n;           ans[blep] = ans[blep + 1] + T[blep];           while (ans[blep] <= (long long)T[blep - 1]) ans[blep] += ans[blep + 1];           if (j == 1)             ans[n + 1] = ans[1];           else if (j == n)             ans[0] = ans[n];         }         return out(), 0;       }     }     for (int i = 1; i <= n; i++) ans[i] = 1;     if (T[1] == 0)       out();     else       cout <<  NO  << endl;     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 1;   int n;   int main() {     scanf( %d , &n);     n = abs(n);     int i = 0;     while (1) {       int s = i * (i + 1);       s /= 2;       if (s >= n) {         if (s % 2 && n % 2) {           printf( %d , i);           exit(0);         }         if (s % 2 == 0 && n % 2 == 0) {           printf( %d , i);           exit(0);         }       }       i++;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     string s;     cin >> s;     int n = s.size();     if (n % 2 == 1) {       for (int i = 0; i < n + 1; ++i) {         cout << (i < (n + 1) / 2 ? 4 : 7);       }       cout << endl;       return 0;     }     int seven = 0, four = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  4 ) {         four++;       }       if (s[i] ==  7 ) {         seven++;       }     }     if (seven == four && seven + four == n) {       cout << s << endl;       return 0;     }     for (int i = n - 1; i >= 0; --i) {       if (s[i] ==  4 ) {         four--;       }       if (s[i] ==  7 ) {         seven--;       }       if (seven + four != i) {         continue;       }       if (seven > n / 2 || four > n / 2) {         continue;       }       if (s[i] <  4  && n / 2 - four > 0) {         s[i] =  4 ;         four++;         int x = i + 1;         while (four < n / 2) {           s[x++] =  4 ;           four++;         }         while (seven < n / 2) {           s[x++] =  7 ;           seven++;         }         cout << s << endl;         return 0;       }       if (s[i] <  7  && n / 2 - seven > 0) {         s[i] =  7 ;         seven++;         int x = i + 1;         while (four < n / 2) {           s[x++] =  4 ;           four++;         }         while (seven < n / 2) {           s[x++] =  7 ;           seven++;         }         cout << s << endl;         return 0;       }     }     for (int i = 0; i < n + 2; ++i) {       cout << (i < (n + 2) / 2 ? 4 : 7);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005];   long long d[800][800], g[800][800];   int w[100];   vector<long long> v;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       long long x = a[i];       int cnt = 0;       while (x) {         if (x % 2) w[cnt]++;         cnt++;         x /= 2;       }     }     for (int i = 0; i < 70; i++) {       if (w[i] >= 3) {         printf( 3 n );         return 0;       }     }     v.push_back(0);     for (int i = 1; i <= n; i++) {       if (a[i]) v.push_back(a[i]);     }     n = v.size() - 1;     if (n > 300) {       printf( 3 n );       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) d[i][j] = g[i][j] = 0x3f3f3f3f;     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (v[i] & v[j]) d[i][j] = 1, d[j][i] = 1, g[i][j] = 1, g[j][i] = 1;       }     }     long long ans = 0x3f3f3f3f;     for (int k = 1; k <= n; k++) {       for (int i = 1; i < k; i++) {         for (int j = i + 1; j < k; j++)           ans = min(ans, d[i][j] + g[i][k] + g[k][j]);       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);       }     }     if (ans == 0x3f3f3f3f) ans = -1;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   signed main() {     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     multiset<long long> kek;     long long ans = 0;     for (int i = n - 1; i >= 0; i--) {       if (a[i] == -1) {         break;       }       kek.insert(a[i]);       if ((i & (i + 1)) == 0) {         ans += *(kek.begin());         kek.erase(kek.begin());       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long dp[4];   int a[100005];   string s;   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (s[i] ==  h )         dp[0] += a[i];       else if (s[i] ==  a )         dp[1] = min(dp[0], dp[1] + a[i]);       else if (s[i] ==  r )         dp[2] = min(dp[1], dp[2] + a[i]);       else if (s[i] ==  d )         dp[3] = min(dp[2], dp[3] + a[i]);     }     cout << dp[3];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace Work {   int c[100010], f[100010], l[100010];   int n, d, s;   void solve(FILE* fin, FILE* fout) {     fscanf(fin,  %d%d%d , &n, &d, &s);     for (int i = 0; i < n; i++) fscanf(fin,  %d%d%d , c + i, f + i, l + i);     vector<int> a, b;     a.clear();     b.clear();     for (int i = 0; i < n; i++)       if (c[i] == 0 && l[i] >= d) a.push_back(f[i]);     sort(a.begin(), a.end());     int acnt = 0, acost = 0;     int sum = 0;     for (int i = 0; i < (int)a.size(); i++)       if (sum + a[i] <= s) {         sum += a[i];         if (i + 1 > acnt || (i + 1 == acnt && sum < acost)) {           acnt = i + 1;           acost = sum;         }       }     bool flag = false;     for (int i = 0; i < n; i++)       if (c[i] > 0 && f[i] <= s && l[i] >= d) flag = true;     if (flag) {       int carry = 0;       for (int i = 0; i < n; i++) {         carry += c[i];         carry = min(carry, n);       }       a.clear();       for (int i = 0; i < n; i++)         if (l[i] >= d) {           if (c[i] > 0)             a.push_back(f[i]);           else             b.push_back(f[i]);         }       sort(a.begin(), a.end());       sort(b.begin(), b.end());       int i = 1, j = 0;       sum = a[0];       while (true) {         int cnt = min(n, carry + i + j);         if (cnt > acnt || (cnt == acnt && sum < acost)) {           acnt = cnt;           acost = sum;         }         if (i == a.size() && j == b.size()) break;         if (i < a.size() && (j == b.size() || a[i] < b[j])) {           sum += a[i];           i++;         } else {           sum += b[j];           j++;         }         if (sum > s) break;       }     }     fprintf(fout,  %d %d , acnt, acost);   }   }  // namespace Work   int main() {     Work::solve(stdin, stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, n, ret;   long long retr(long long x) {     long long t = 0;     while (x > 0) {       t = 10 * t + (x % 10);       x /= 10;     }     return t;   }   int main() {     int i;     cin >> a >> b;     ret = retr(b);     ret += a;     cout << ret;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char s[200100];   int x[200100];   int main() {     scanf( %d , &n);     scanf( %s , s);     int mint = 0x3f3f3f3f;     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       if (i && s[i] ==  L  && s[i - 1] ==  R )         mint = min((x[i] - x[i - 1]) / 2, mint);     }     if (mint == 0x3f3f3f3f) mint = -1;     printf( %d , mint);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int N = 100100;   struct point {     int id, val, sum;   } a[N], b[N];   bool cmp(point x, point y) { return x.val > y.val; }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int na = 0;     int nb = 1;     b[0].val = 0;     for (int i = 1; i <= n; ++i) {       int op;       scanf( %d , &op);       if (op == 1) {         scanf( %d , &a[na].val);         a[na++].id = i;       } else {         scanf( %d , &b[nb].val);         b[nb++].id = i;       }     }     sort(a, a + na, cmp);     sort(b + 1, b + nb, cmp);     for (int i = 0; i < na; ++i) {       if (i == 0)         a[i].sum = a[i].val;       else         a[i].sum = a[i - 1].sum + a[i].val;     }     int sum = 0;     int ia = 0;     int ib = 1;     int ans = 0;     for (int i = 0; i < nb && 2 * i <= m; ++i) {       sum += b[i].val;       int id = min(m - 2 * i - 1, na - 1);       int tmp = sum;       if (id >= 0) tmp += a[id].sum;       if (tmp > ans) {         ans = tmp;         ia = id + 1;         ib = i + 1;       }     }     printf( %d n , ans);     for (int i = 0; i < ia; ++i) printf( %d  , a[i].id);     for (int i = 1; i < ib; ++i) printf( %d  , b[i].id);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> dg, og;   vector<bool> vist;   vector<int> dist;   void bfs(int begin) {     vist[begin] = true;     dist[begin] = 0;     queue<int> pq;     pq.push(begin);     while (!pq.empty()) {       int a = pq.front();       pq.pop();       for (int i = 0; i < dg[a].size(); i++) {         if (!vist[dg[a][i]]) {           vist[dg[a][i]] = true;           dist[dg[a][i]] = dist[a] + 1;           pq.push(dg[a][i]);         }       }     }   }   int distcounter(int a) {     int count = 0;     for (int i = 0; i < og[a].size(); i++) {       if (dist[og[a][i]] == dist[a] - 1) count++;     }     return count;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     dg.resize(n + 1);     dist.resize(n + 1);     og.resize(n + 1);     vist.assign(n + 1, false);     int u, v;     for (int i = 1; i <= m; i++) {       cin >> u >> v;       og[u].push_back(v);       dg[v].push_back(u);     }     int k;     cin >> k;     vector<int> p;     p.resize(k + 1);     for (int i = 1; i <= k; i++) cin >> p[i];     bfs(p[k]);     int small = 0, large = 0;     for (int i = 1; i < k; i++) {       int count = distcounter(p[i]);       if (dist[p[i + 1]] != dist[p[i]] - 1) {         small++;         large++;       } else {         if (count > 1) {           large++;         }       }     }     cout << small <<     << large << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:128777216 )   using namespace std;   const long long LINF = 1000000000000000000LL;   const int INF = 1000000000;   const long double eps = 1e-9;   const long double PI = 3.1415926535897932384626433832795l;   void prepare(string s) {     if (s.length() != 0) {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   const int NMAX = 1000100;   const int MOD = INF + 7;   char s[NMAX];   int n;   int c[4];   char sym[] = { A ,  C ,  G ,  T };   int get(char c) {     for (int i = 0; i < (int)(4); i++)       if (sym[i] == c) return i;     assert(false);     return -1;   }   void read() {     scanf( %d n , &n);     scanf( %s , s);   }   int bpow(int a, int n) {     int r = 1;     for (; n > 0; n >>= 1) {       if (n & 1) r = ((long long)r * (long long)a) % MOD;       a = ((long long)a * (long long)a) % MOD;     }     return r;   }   void solve() {     memset(c, 0, sizeof(c));     for (int i = 0; i < (int)(n); i++) c[get(s[i])]++;     int mx = *max_element(c, c + 4);     int cnt = 0;     for (int i = 0; i < (int)(4); i++)       if (c[i] == mx) cnt++;     printf( %d n , bpow(cnt, n));   }   int main() {     prepare(  );     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[300000];   int main() {     int i, j, n, k, m, l = 0, h, b = 0, c;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 1; i < n - 1; i++) {       if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) {         l++;         a[i + 1] = 0;       }     }     cout << l << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt, h;   bool f = true;   int main() {     long long s, x;     cin >> s >> x;     h = sizeof(long long) * 8 - __builtin_clzll(max(s, x)) - 1;     for (; h >= 0; h--) {       if (x & (1LL << h))         cnt++, s -= (1LL << h);       else if (s >= (1LL << h + 1))         s -= (1LL << h + 1), f = false;     }     if (s || (cnt < 2 && f))       cout << 0 << endl;     else       cout << (1LL << (cnt)) - f * 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char mtx[555][555];   long long comb[555][555];   int n, m, MOD;   map<pair<int, int>, long long> dp[555];   long long solve(int col, int empty, int halfempt) {     if (empty < 0 || halfempt < 0) return 0;     if (col == n) {       return empty == 0 && halfempt == 0;     }     if (dp[col].find(make_pair(empty, halfempt)) == dp[col].end()) {       long long ans = 0;       int cnt = 0;       for (int(i) = 0; (i) < (m); (i)++)         if (mtx[i][col] ==  1 ) cnt++;       if (cnt == 0) {         if (halfempt == 0) {           ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2);         } else {           ans += comb[halfempt][2] * solve(col + 1, empty, halfempt - 2);           if (empty != 0) {             ans += comb[halfempt][1] * comb[empty][1] *                    solve(col + 1, empty - 1, halfempt);             ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2);           }         }       } else if (cnt == 1) {         ans = comb[empty][1] * solve(col + 1, empty - 1, halfempt + 1);         ans += comb[halfempt][1] * solve(col + 1, empty, halfempt - 1);       } else         ans = solve(col + 1, empty, halfempt);       ans %= MOD;       dp[col][make_pair(empty, halfempt)] = ans;     }     return dp[col][make_pair(empty, halfempt)];   }   int main() {     scanf( %d%d%d , &n, &m, &MOD);     for (int i = 1; i < 505; i++) {       comb[i][0] = comb[i][i] = 1;       for (int j = 0; j < i; j++) {         comb[i + 1][j + 1] = (comb[i][j] + comb[i][j + 1]) % MOD;       }     }     if (n == m) {       printf( 1 n );       return 0;     }     for (int(i) = 0; (i) < (m); (i)++) scanf( %s , mtx[i]);     long long ans = solve(0, n - m, 0);     printf( %I64d n , ans);     return 0;   }