malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> a >> b;       if (abs(a - b) > 1 || a + b > n - 2)         cout << -1;       else {         int l, r, x;         x = a + b;         if (a == b) {           l = n, r = n - x;           while (r < l) {             cout << l <<     << r <<    ;             l--, r++;           }           if (r == l) cout << r <<    ;           for (int i = n - x - 1; i >= 1; i--) cout << i <<    ;         } else if (a > b) {           l = n, r = n - x;           while (r < l) {             cout << r <<     << l <<    ;             r++, l--;           }           if (r == l) cout << r <<    ;           for (int i = n - x - 1; i >= 1; i--) cout << i <<    ;         } else {           r = 1, l = x + 1;           while (r < l) {             cout << l <<     << r <<    ;             l--, r++;           }           if (r == l) cout << r <<    ;           for (int i = x + 2; i <= n; i++) cout << i <<    ;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1234567;   int query(vector<long long> a) {     int n = a.size();     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         if (n % (i * i) != 0) {           for (int j = 0; j < n; j += i) {             long long d = a[j];             int k = j;             do {               a[k] -= d;               k = (k + n / i) % n;             } while (k != j);           }         }         vector<vector<long long> > w(i);         for (int j = 0; j < n; j++) w[j % i].push_back(a[j]);         bool f = 1;         for (int j = 0; j < i; j++)           if (!query(w[j])) {             f = 0;             break;           }         return f;       }     }     for (int i = 1; i < a.size(); i++)       if (a[i] != a[0]) return 0;     return 1;   }   int main() {     int n;     string s;     cin >> n >> s;     vector<long long> a(n);     for (int i = 0; i < n; i++) a[i] = s[i] -  0 ;     cout << (query(a) ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int k, n, maxb, t, b[N], tot = 1, dp[N << 2], rec[N << 2];   void update(int i, int x) {     while (i <= tot) {       dp[i] = max(dp[i], x);       i += i & -i;     }   }   int sum(int i) {     int ret = 0;     while (i) {       ret = max(ret, dp[i]);       i -= i & -i;     }     return ret;   }   int main() {     scanf( %d%d%d%d , &k, &n, &maxb, &t);     t = min(t, maxb);     while (tot <= maxb) tot <<= 1;     while (k--) {       memset(dp, 0, sizeof(dp));       memset(rec, 0, sizeof(rec));       memset(b, 0, sizeof(b));       for (int i = 0; i < n; i++) scanf( %d , &b[i]);       for (int i = 1; i <= t; i++)         for (int j = 0; j < n; j++) {           int tmp = sum(b[j] - 1);           if (tmp >= rec[j]) {             update(b[j], tmp + 1);             rec[j] = tmp + 1;           }         }       printf( %d n , sum(tot));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long MAX_N = 1e3 + 1;   long n, m, h;   long aw[MAX_N];   long bw[MAX_N];   vector<long> g[MAX_N];   bool v[MAX_N];   vector<long> st;   vector<pair<pair<long, long>, long> > ans;   void add_edge(long a, long b) {     g[a].push_back(b);     g[b].push_back(a);   }   void try_flow(long i, long need) {     if (i + 1 >= st.size()) return;     long a = st[i], b = st[i + 1];     long can = min(need, h - aw[b]);     if (can > 0) {       ans.push_back(make_pair(make_pair(a, b), can));     }     try_flow(i + 1, need);     if (need - can > 0) {       ans.push_back(make_pair(make_pair(a, b), need - can));     }   }   void flow() {     long a = st[0];     long b = st[st.size() - 1];     long need = min(aw[a] - bw[a], bw[b] - aw[b]);     if (need > 0) {       try_flow(0, need);       aw[a] -= need;       aw[b] += need;     }   }   void dfs(long a) {     v[a] = true;     st.push_back(a);     if (aw[a] < bw[a]) flow();     for (size_t i = 0; i < g[a].size(); i++) {       long b = g[a][i];       if (!v[b]) dfs(b);     }     st.pop_back();   }   int main() {     cin >> n >> h >> m;     for (long i = 1; i <= n; i++) {       cin >> aw[i];     }     for (long i = 1; i <= n; i++) {       cin >> bw[i];     }     for (long i = 1; i <= m; i++) {       long x, y;       cin >> x >> y;       add_edge(x, y);     }     for (long i = 1; i <= n; i++) {       if (aw[i] > bw[i]) {         for (long j = 1; j <= n; j++) v[j] = false;         dfs(i);       }     }     for (long i = 1; i <= n; i++) {       if (aw[i] != bw[i]) {         cout <<  NO ;         return 0;       }     }     cout << ans.size() << endl;     for (size_t i = 0; i < ans.size(); i++) {       cout << ans[i].first.first <<     << ans[i].first.second <<                << ans[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     getline(cin, str);     str.erase(remove(str.begin(), str.end(),    ), str.end());     int n = str.size();     if (str[n - 2] ==  a  || str[n - 2] ==  e  || str[n - 2] ==  i  ||         str[n - 2] ==  o  || str[n - 2] ==  u  || str[n - 2] ==  y  ||         str[n - 2] ==  A  || str[n - 2] ==  E  || str[n - 2] ==  I  ||         str[n - 2] ==  O  || str[n - 2] ==  U  || str[n - 2] ==  Y ) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     long long mid;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  ^ ) {         mid = i;         break;       }     }     long long sum = 0;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  =  || s[i] ==  ^ ) continue;       long long x = s[i] - 48;       sum += x * (i - mid);     }     if (sum == 0)       cout <<  balance ;     else if (sum < 0)       cout <<  left ;     else       cout <<  right ;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = int(1e9) + 1;   const long double eps = 1e-9;   map<string, int> jogos;   map<string, int> pontos;   map<string, int> gol;   map<string, int> leva;   set<string> times;   vector<string> falta;   int x1, x2;   bool menor(string x, string y) {     int g1 = 0, g2 = 0;     int l1 = 0, l2 = 0;     if (falta[0] == x) {       g1 += x1;       l1 += x2;     } else if (falta[0] == y) {       g2 += x1;       l2 += x2;     }     if (falta[1] == x) {       g1 += x2;       l1 += x1;     } else if (falta[1] == y) {       g2 += x2;       l2 += x1;     }     g1 += gol[x];     l1 += leva[x];     g2 += gol[y];     l2 += leva[y];     if (pontos[x] > pontos[y])       return true;     else if (pontos[x] < pontos[y])       return false;     else {       if (g1 - l1 > g2 - l2)         return true;       else if (g1 - l1 < g2 - l2)         return false;       else {         if (g1 > g2)           return true;         else if (g1 < g2)           return false;         return y > x;       }     }   }   bool ord(int p1, int p2) {     x1 = p1;     x2 = p2;     vector<string> pi;     for (set<string>::iterator it = times.begin(); it != times.end(); ++it) {       string aux = *it;       pi.push_back((aux));     }     for (int i = 3; i >= 1; --i) {       for (int j = 0; j < i; j++) {         if (!menor(pi[j], pi[j + 1])) {           swap(pi[j], pi[j + 1]);         }       }     }     if (pi[0] ==  BERLAND  || pi[1] ==  BERLAND ) return true;     return false;   }   int main() {     for (int i = 0; i < 5; ++i) {       string x, y;       int g1, g2;       cin >> x >> y;       times.insert(x);       times.insert(y);       scanf( %d:%d , &g1, &g2);       jogos[x]++;       jogos[y]++;       if (g1 == g2) {         pontos[x]++;         pontos[y]++;       } else if (g1 > g2) {         pontos[x] += 3;       } else {         pontos[y] += 3;       }       gol[x] += g1;       leva[x] += g2;       gol[y] += g2;       leva[y] += g1;     }     for (set<string>::iterator it = times.begin(); it != times.end(); ++it) {       if (jogos[*it] < 3) falta.push_back(*it);     }     if (falta[1] ==  BERLAND ) swap(falta[0], falta[1]);     pontos[falta[0]] += 3;     int ans1 = 1e8, ans2 = 1e7;     for (int g1 = 0; g1 < 201; ++g1) {       for (int g2 = 0; g2 < g1; ++g2) {         bool can = ord(g1, g2);         if (can) {           if (ans1 - ans2 > g1 - g2) {             ans1 = g1;             ans2 = g2;           }         }       }     }     if (ans1 >= 1e8)       puts( IMPOSSIBLE );     else       printf( %d:%d n , ans1, ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, a, b, c;     cin >> t;     while (t--) {       cin >> a >> b >> c;       cout << ((a + b * 2 + c * 3) & 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void swap(long long int arr[], long long int x, long long int y) {     long long int temp = arr[x];     arr[x] = arr[y];     arr[y] = temp;   }   void print_arr(long long int arr[], long long int n) {     cout <<   n ;     for (long long int i = 0; i < n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }   void input_arr(long long int arr[], long long int n) {     for (long long int i = 0; i < n; i++) {       cin >> arr[i];     }   }   bool primes[1000001];   int checkstring(string s) {     int l = s.length();     string p =   ;     for (int i = 0; i < l; i++) {       if (s[i] !=  - ) {         p += s[i];       }     }     int same = 0;     int dec = 0;     for (int i = 1; i < p.length(); i++) {       if (p[i] == p[i - 1]) {         same++;       } else if (p[i] <= p[i - 1]) {         dec++;       }     }     if (same == p.length() - 1) {       return 2;     } else if (dec == p.length() - 1) {       return 1;     }     return 3;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     while (t--) {       long long int n;       cin >> n;       map<string, long long int> tx;       map<string, long long int> cg;       map<string, long long int> pz;       string abc[n];       for (int i = 0; i < n; i++) {         int N;         string fname;         cin >> N >> fname;         abc[i] = fname;         for (int j = 0; j < N; j++) {           string s;           cin >> s;           int x = checkstring(s);           if (x == 2) {             tx[fname]++;           } else if (x == 3) {             cg[fname]++;           } else {             pz[fname]++;           }         }       }       int maxp = 0, maxt = 0, maxc = 0;       vector<string> v[3];       for (int i = 0; i < n; i++) {         if (tx[abc[i]] > maxt) {           maxt = tx[abc[i]];         }         if (pz[abc[i]] > maxp) {           maxp = pz[abc[i]];         }         if (cg[abc[i]] > maxc) {           maxc = cg[abc[i]];         }       }       for (int i = 0; i < n; i++) {         if (pz[abc[i]] == maxp) {           v[0].push_back(abc[i]);         }         if (cg[abc[i]] == maxc) {           v[1].push_back(abc[i]);         }         if (tx[abc[i]] == maxt) {           v[2].push_back(abc[i]);         }       }       cout <<  If you want to call a taxi, you should call: ;       for (int i = 0; i < v[2].size(); i++) {         if (i != v[2].size() - 1)           cout <<     << v[2][i] <<  , ;         else           cout <<     << v[2][i] <<  . ;       }       cout <<   n ;       cout <<  If you want to order a pizza, you should call: ;       for (int i = 0; i < v[0].size(); i++) {         if (i != v[0].size() - 1)           cout <<     << v[0][i] <<  , ;         else           cout <<     << v[0][i] <<  . ;       }       cout <<   n ;       cout <<  If you want to go to a cafe with a wonderful girl, you should                  call: ;       for (int i = 0; i < v[1].size(); i++) {         if (i != v[1].size() - 1)           cout <<     << v[1][i] <<  , ;         else           cout <<     << v[1][i] <<  . ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int digitMask = 0;   int c[20];   int factorize(int n, int pos) {     int curPos = pos;     c[curPos] = 0;     while (n > 0) c[curPos++] = n % 10, n /= 10;     curPos--;     curPos = max(curPos, pos);     for (int i = pos, j = curPos; i < j; i++, j--) swap(c[i], c[j]);     return curPos;   }   int parsenum(int n) {     if (c[n - 1] == 0 && n != 1) return -1;     int ans = 0;     for (int i = n - 1; i >= 0; i--) ans *= 10, ans += c[i];     return ans;   }   bool good(int i, int j) {     int ii = i, jj = j;     while (i < j)       if (c[i] != c[j])         return false;       else         i++, j--;     int mask = 0;     for (int we = ii; we <= jj; we++) mask |= (1 << c[we]);     return mask == digitMask;   }   bool nogood(int i, int j) {     for (int we = i; we <= j; we++)       if ((digitMask & (1 << c[we])) == 0) return true;     return false;   }   const int maxn = 1000000;   int ans1[maxn], ans2[maxn], ans3[maxn], ans4[maxn];   int ansCount;   int main() {     int n;     cin >> n;     if (n >= 7) {       cout << 0;       return 0;     }     for (int i = 0; i < n; i++) {       int c;       cin >> c;       digitMask |= (1 << c);     }     for (int a = 0; a < 256; a++) {       int pos1 = factorize(a, 0);       for (int b = 0; b < 256; b++) {         int pos2 = factorize(b, pos1 + 1);         if (nogood(0, pos2)) continue;         for (int c = 0; c < 256; c++) {           int pos3 = factorize(c, pos2 + 1);           if (nogood(0, pos3)) continue;           for (int count = 1; count <= 3; count++) {             int last = parsenum(count);             if (last == -1) continue;             if (last >= 256) continue;             int pos = factorize(last, pos3 + 1);             if (good(0, pos)) {               ans1[ansCount] = a;               ans2[ansCount] = b;               ans3[ansCount] = c;               ans4[ansCount] = last;               ansCount++;             }           }         }       }     }     cout << ansCount << endl;     for (int i = 0; i < ansCount; i++) {       cout << ans1[i] <<  .  << ans2[i] <<  .  << ans3[i] <<  .  << ans4[i]            << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   int n;   vector<int> v[30];   int qt[30];   int main() {     int i, j;     string s;     cin >> s;     n = s.size();     for (i = 0; i < n; i++) v[s[i] -  a ].push_back(i);     double ans = 0;     for (i = 0; i < 26; i++) {       if (v[i].empty()) continue;       if (v[i].size() == 1) {         ans += 1;         continue;       }       if (v[i].size() == 2) {         string t1 = s, t2 = s;         rotate(t1.begin(), t1.begin() + v[i][0], t1.end());         rotate(t2.begin(), t2.begin() + v[i][1], t2.end());         if (t1 != t2) ans += 2;         continue;       }       int mx = 0;       for (j = 0; j < n; j++) {         for (int k : v[i]) qt[s[(k + j) % n] -  a ]++;         int cur = 0;         int k;         for (k = 0; k < 26; k++)           if (qt[k] == 1) cur++;         mx = max(mx, cur);         for (int k : v[i]) qt[s[(k + j) % n] -  a ]--;       }       ans += mx;     }     printf( %.15f n , ans / n);   }
#include <bits/stdc++.h>   using namespace std;   template <class temp>   inline void Rd(temp &p) {     p = 0;     char c;     while (c = getchar(), c < 48)       ;     do p = p * 10 + (c & 15);     while (c = getchar(), c > 47);   }   int n, k, len, m, q[200005];   int l[200005], r[200005];   int lfind(int x) {     if (l[x] == x)       return x;     else       return l[x] = lfind(l[x]);   }   int rfind(int x) {     if (r[x] == x)       return x;     else       return r[x] = rfind(r[x]);   }   int main() {     Rd(n), Rd(k), Rd(len), Rd(m);     for (int i = 1; i <= n; i++) l[i] = i - 1, r[i] = i + 1;     l[0] = r[0] = 0;     l[n + 1] = r[n + 1] = n + 1;     for (int i = 1; i <= m; i++) {       Rd(q[i]);       l[q[i]] = r[q[i]] = q[i];     }     int pre = 0, ans = 0;     for (int i = 1; i <= n + 1; i++)       if (lfind(i) == rfind(i)) {         ans += (i - pre) / (len + 1);         pre = i;       }     if (ans >= k) puts( -1 ), exit(0);     for (int i = m; i >= 1; i--) {       int pos = q[i];       ans -= (rfind(r[pos - 1]) - lfind(l[pos - 1])) / (len + 1);       ans -= (rfind(r[pos + 1]) - lfind(l[pos + 1])) / (len + 1);       l[pos] = pos - 1, r[pos] = pos + 1;       ans += (rfind(r[pos]) - lfind(l[pos])) / (len + 1);       if (ans >= k) printf( %d n , i), exit(0);     }   }
#include <bits/stdc++.h>   double vp, vd, t, f, c;   int main() {     scanf( %lf%lf%lf%lf%lf , &vp, &vd, &t, &f, &c);     double x = vp * t;     int ans = 0;     if (vp > vd) {       puts( 0 );       return 0;     }     while (x + 1e-6 < c) {       double needtime = x / (vd - vp);       double willx = x + needtime * vp;       if (willx + 1e-6 >= c) break;       ans++;       t += needtime * 2 + f;       x = vp * t;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   long long n, m;   map<long long, long long> mp;   long long ans[N], top;   signed main() {     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       mp[x] = 1;     }     for (long long i = 1; 26 > 30 / 39 / 57; ++i) {       if (mp[i] == 0) {         m -= i;         if (m < 0) {           break;         }         ans[++top] = i;       }     }     cout << top << endl;     for (long long i = 1; i <= top; ++i) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   int main() {     long long t, i, r, c, k, j, n, cnt, x, y, p, q, l, flag;     vector<string> a;     vector<char> b;     for (i = 48; i < 58; i++) {       b.push_back(char(i));     }     for (i = 65; i < 91; i++) {       b.push_back(char(i));     }     for (i = 97; i < 124; i++) {       b.push_back(char(i));     }     string s;     cin >> t;     for (i = 0; i < t; i++) {       cin >> r >> c >> n;       cnt = 0;       p = 0, q = 0, l = 0, flag = 1;       for (j = 0; j < r; j++) {         cin >> s;         for (k = 0; k < c; k++) {           if (s[k] ==  R ) {             cnt++;           }         }         a.push_back(s);       }       if (cnt % n == 0) {         x = cnt / n;         y = n;       } else {         x = cnt / n + 1;         y = cnt % n;       }       for (j = 0; j < r; j++) {         if (j % 2 == 0) {           for (k = 0; k < c; k++) {             if (a[j][k] ==  R ) {               if (q == x) {                 p++;                 if (p == y && flag == 1) {                   x = x - 1;                   flag = 2;                 }                 q = 1;                 l++;                 a[j][k] = b[l];               } else {                 q++;                 a[j][k] = b[l];               }             } else {               a[j][k] = b[l];             }           }         } else {           for (k = c - 1; k >= 0; k--) {             if (a[j][k] ==  R ) {               if (q == x) {                 p++;                 if (p == y && flag == 1) {                   x = x - 1;                   flag = 2;                 }                 q = 1;                 l++;                 a[j][k] = b[l];               } else {                 q++;                 a[j][k] = b[l];               }             } else {               a[j][k] = b[l];             }           }         }       }       for (j = 0; j < r; j++) {         cout << a[j] << endl;       }       a.clear();     }   }
#include <bits/stdc++.h>   int in[101], od[101], fa[101], n;   int f[101], f2[102];   inline int find(int a) {     if (fa[a] != a) fa[a] = find(fa[a]);     return fa[a];   }   inline void u(int x, int y) {     x = find(x);     y = find(y);     fa[y] = x;   }   signed main() {     scanf( %d , &n);     for (register int i = 1; i <= n; i++) fa[i] = i;     for (register int i = 1; i <= n; i++) scanf( %d , &in[i]);     for (register int i = 1; i <= n; i++) {       scanf( %d , &od[i]);       if (i - od[i] > 0) u(in[i], in[i - od[i]]);       if (i + od[i] <= n) u(in[i], in[i + od[i]]);     }     for (register int i = 1; i <= n; i++) {       f[find(i)] += i;       f2[find(i)] += in[i];     }     for (register int i = 1; i <= n; i++) {       if (f[i] ^ f2[i]) {         printf( NO n );         return 0;       }     }     printf( YES n );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5, M = (1 << 20) + 5;   template <typename T>   void read(T &x) {     bool neg = false;     unsigned char c = getchar();     for (; (c ^ 48) > 9; c = getchar())       if (c ==  - ) neg = true;     for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);     if (neg) x = -x;   }   struct line {     int next, to;   } e[N];   int n, m, hd[N], cnt, k, s[25], t[25], f[N], a[M], pop[M];   bool iss[N], ist[N];   void adline(int u, int v) {     e[cnt].to = v;     e[cnt].next = hd[u];     hd[u] = cnt++;   }   void dfs(int u) {     if (f[u]) return;     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       dfs(v);       f[u] |= f[v];     }   }   int main() {     read(n);     read(m);     for (int i = 0, i_end = n; i < i_end; ++i) hd[i] = -1, iss[i] = ist[i] = true;     for (int i = 0, i_end = m; i < i_end; ++i) {       int u, v;       read(u);       read(v);       adline(--u, --v);       ist[u] = false;       iss[v] = false;     }     for (int i = 0, i_end = n; i < i_end; ++i)       if (iss[i]) s[k++] = i;     k = 0;     for (int i = 0, i_end = n; i < i_end; ++i)       if (ist[i]) t[k++] = i;     for (int i = 0, i_end = k; i < i_end; ++i) f[t[i]] = 1 << i;     for (int i = 0, i_end = k; i < i_end; ++i) dfs(s[i]), a[1 << i] = f[s[i]];     for (int i = 1, i_end = 1 << k; i < i_end; ++i)       pop[i] = pop[i ^ (i & -i)] + 1;     for (int i = 1, i_end = (1 << k) - 1; i < i_end; ++i) {       a[i] = a[i & -i] | a[i ^ (i & -i)];       if (pop[a[i]] <= pop[i]) return puts( NO ), 0;     }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, int> A;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       A[x]++;     }     int mx = 0;     for (auto x : A) {       if (x.second > mx) mx = x.second;     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     const string t =  RGB ;     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int n, k;       string s;       cin >> n >> k >> s;       int ans = 1e9;       for (int j = 0; j < n - k + 1; ++j) {         for (int offset = 0; offset < 3; ++offset) {           int cur = 0;           for (int pos = 0; pos < k; ++pos) {             if (s[j + pos] != t[(pos + offset) % 3]) {               ++cur;             }           }           ans = min(ans, cur);         }       }       cout << ans << endl;     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;      const int N=500;   int n,mod,xn[N];   long long dp[N*N];      #define id(x,y) *(xn+x)+y      int main(){    cin>>n>>mod;    dp[id(1,1)]=1;    for(int i=2;i<=n;++i)     xn[i]=xn[i-1]+n;    xn[n+2]=(xn[n+1]=xn[n]+n)+n;    for(int i=1;i<n;i++){      long long a=(dp[id(i,1)]<<1)%mod;      dp[id(i+1,2)]+=a;      dp[id(i+1,1)]+=a;      dp[id(i+2,1)]+=a;         for(int j=2;j<=n;j++){     long long a=dp[id(i,j)]*(j-1)%mod,b=(dp[id(i,j)]*j<<1)%mod;     dp[id(i+1,j+1)]+=dp[id(i,j)]*(j+1)%mod;     dp[id(i+3,j-1)]+=a;     dp[id(i+2,j-1)]+=a<<1;     dp[id(i+1,j)]+=b;     dp[id(i+2,j)]+=b;      }    }          cout<<dp[id(n,1)]%mod<<endl;   }