malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   long long dp[40][40][2], n, ans;   int lim[45], len;   int calc(int x, int sgn) {     if (x == 0) return sgn ^ 1;     return 1 << x >> 1;   }   int main() {     cin >> n;     if (n == 0) return puts( 1 ), 0;     while (n) {       lim[++len] = n & 1;       n >>= 1;     }     reverse(lim + 1, lim + len + 1);     dp[0][0][1] = 1;     for (int i = 0; i < len; ++i)       for (int j = 0; j <= i; ++j)         for (int k = 0; k < 2; ++k) {           (dp[i + 1][j][k & (lim[i + 1] ^ 1)] +=            1ll * dp[i][j][k] * calc(j, 0) % p) %= p;           if ((!k) || lim[i + 1]) {             (dp[i + 1][j][k] += 1ll * dp[i][j][k] * calc(j, 1) % p) %= p;             (dp[i + 1][j + 1][k] += dp[i][j][k]) %= p;           }         }     for (int i = 0; i <= len; ++i)       (ans += (dp[len][i][0] + dp[len][i][1]) % p) %= p;     printf( %lld n , ans);     return 0;   }
#include<iostream>   #include<cstring>   #include<cmath>   #include<string>   #include<algorithm>   #include<cstdio>   #include<set>   #include<vector>   #include<map>   #include<stack>   using namespace std;   const int N = 110;   const int inf = 0x3f3f3f3f;   typedef long long ll;   #define reg register   const int mod = 1e9 + 7;   inline ll gcd(reg ll a, reg ll b) {    return b == 0 ? a : gcd(b, a % b);   }   inline ll lcm(reg ll a, reg ll b) {    return a / gcd(a, b) * b;   }   signed main()   {    ios::sync_with_stdio(false);    //freopen( 文本.txt ,  r , stdin);    ll T, n;    cin >> T;    while (T--) {     cin >> n;     reg ll res = 0, k = 1;     for (reg ll i = 1; k <= n; i++) {      k = lcm(k, i);      if (n < k) break;      res += n / k;     }     cout << (res + n) % mod << endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     vector<long long int> a(n);     for (long long int i = 0; i < a.size(); i++) cin >> a[i];     long long int ans(0);     for (long long int i = 0; i < n; i++) {       long long int t;       cin >> t;       if (t) ans += a[i], a[i] = 0;     }     long long int s(0);     long long int tot(0);     for (long long int i = 0; i < k; i++) {       s = s + a[i];     }     tot = s;     for (long long int i = k; i < n; i++) {       s += (a[i] - a[i - k]);       tot = max(tot, s);     }     cout << ans + tot << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     set<char> st;     for (int i = 0; i < s.size(); i++) {       if (s[i] == s[i + 1]) {         i++;       } else {         st.insert(s[i]);       }     }     for (auto it : st) {       cout << it;     }     cout <<   n ;   }   void withtest() {     int t;     cin >> t;     while (t--) {       solve();     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     withtest();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[3][111111];   vector<int> graph[111111];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       graph[a].push_back(b);       graph[b].push_back(a);     }     for (int i = 0; i < n; i++) dp[0][i] = 1;     for (int len = 1; len <= 2; len++)       for (int v = 0; v < n; v++) {         for (int u : graph[v]) dp[len][v] += dp[len - 1][u];       }     int sum = 0;     for (int i = 0; i < n; i++) sum += dp[2][i];     sum /= 2;     sum -= n - 1;     cout << sum <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int MAXN = 1e3 + 10;   inline long long in() {     long long x = 0, flag = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();     return x * flag;   }   int T;   int n, m;   long long ans;   long long fac[MAXN];   long long c[MAXN << 1][MAXN << 1];   long long dp[52][MAXN];   void prework() {     fac[0] = 1;     for (int i = 1; i <= 1000; i++) fac[i] = fac[i - 1] * 1LL * i % MOD;     c[0][0] = 1;     for (int i = 1; i <= 2000; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++)         (c[i][j] = c[i - 1][j - 1] + c[i - 1][j]) %= MOD;     }     dp[0][0] = 1;     for (int i = 0; i <= 50; i++) {       for (int j = i * (i + 1) / 2; j <= 1000; j++) {         if (j + i <= 1000 && i != 0) (dp[i][j + i] += dp[i][j]) %= MOD;         if (j + i + 1 <= 1000) (dp[i + 1][j + i + 1] += dp[i][j]) %= MOD;       }     }   }   int main() {     T = in();     prework();     while (T--) {       ans = 0;       n = in(), m = in();       for (int i = m * (m + 1) / 2; i <= n; i++) {         if (dp[m][i] == 0) continue;         int res = n - i;         (ans += c[res + m][m] * fac[m] % MOD * dp[m][i] % MOD) %= MOD;       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(NULL);     int a[100][100];     int b[100][100];     int m, n;     cin >> m >> n;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         b[i][j] = 1;       }     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> a[i][j];         if (!a[i][j]) {           for (int k = 0; k < m; k++) b[k][j] = 0;           for (int k = 0; k < n; k++) b[i][k] = 0;         }       }     }     bool flag = true;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         if (a[i][j] == 1) {           int g = 0;           int r = i;           int c = j;           for (int h = 0; h < n; h++)             if (b[r][h]) g = 1;           for (int h = 0; h < m; h++)             if (b[h][c]) g = 1;           if (!g) flag = false;         }       }     }     if (!flag)       cout <<  NO ;     else {       cout <<  YES n ;       for (int i = 0; i < m; i++) {         for (int j = 0; j < n; j++) {           cout << b[i][j] <<    ;         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     bool f1 = true, f2 = false;     int arrS[26] = {0};     int arrT[26] = {0};     string s, t;     getline(cin, s);     getline(cin, t);     for (int i = 0; i < s.size(); i++) arrS[s[i] -  a ]++;     for (int i = 0; i < t.size(); i++) arrT[t[i] -  a ]++;     for (int i = 0; i < 26; i++)       if (arrS[i] < arrT[i]) {         cout <<  need tree  << endl;         return 0;       }     if (s.size() == t.size()) {       cout <<  array  << endl;       return 0;     }     int j = 0;     for (int i = 0; i < s.size(); i++)       if (s[i] == t[j]) j++;     if (j == t.size())       cout <<  automaton  << endl;     else       cout <<  both  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e6;   const int inf = (int)2e9;   const double eps = 1e-9;   const int mod = (int)1e9 + 7;   int n, l, x, y, a[maxn], ok1, ok2;   map<int, int> was;   bool check(int v) {     if (v >= 0 && v <= l && (was.count(v - x) || was.count(v + x) || ok1) &&         (ok2 || was.count(v - y) || was.count(v + y)))       return true;     return false;   }   int main() {     scanf( %d%d%d%d , &n, &l, &x, &y);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (was.count(a[i] - x)) ok1 = true;       if (was.count(a[i] - y)) ok2 = true;       was[a[i]] = true;     }     if (ok1 && ok2) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; ++i) {       if (check(a[i] - x)) {         puts( 1 );         cout << a[i] - x <<   n ;         return 0;       }       if (check(a[i] - y)) {         puts( 1 );         cout << a[i] - y <<   n ;         return 0;       }       if (check(a[i] + x)) {         puts( 1 );         cout << a[i] + x <<   n ;         return 0;       }       if (check(a[i] + y)) {         puts( 1 );         cout << a[i] + y <<   n ;         return 0;       }     }     puts( 2 );     cout << x <<     << y <<   n ;     return 0;   }
#include <bits/stdc++.h>   const long long SZ = 401010;   const long long INF = 1e18;   const long long MOD = 1000000007;   const long long mod = 998244353;   long long opnmbr = 1;   using namespace std;   void solve() {}   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 / gcd(a, b)) * b; }   bool isPrime(long long n) {     long long sq = sqrt(n);     for (long long i = 2; i <= sq; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   void krdiyasuru() {     long long n, k;     cin >> n >> k;     string a;     cin >> a;     string chk;     chk = a;     for (long long i = k; i < (n); i++) {       a[i] = a[i - k];     }     if (a >= chk) {       cout << n <<   n ;       cout << a <<   n ;       return;     }     for (long long i = k - 1; i >= (0); i--) {       if (a[i] ==  9  && i != 0) {         a[i] =  0 ;       } else if (a[i] !=  9 ) {         a[i]++;         break;       }     }     cout << n <<   n ;     for (long long i = k; i < (n); i++) {       a[i] = a[i - k];     }     cout << a <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     { krdiyasuru(); }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct mydata {     int id;     int x;     int num;     bool operator<(const mydata &r) const {       if (x == r.x)         return id < r.id;       else         return x < r.x;     }   } data[50];   int ret[2000];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int i;     for (i = 0; i < m; i++) {       data[i].id = i + 1;       data[i].num = 0;       scanf( %d , &data[i].x);     }     sort(data, data + m);     int total = n;     int maxnum = 0;     for (i = 0; i < m; i++) {       data[i].num = min(data[i].x, total / (m - i));       maxnum = max(maxnum, data[i].num);       total -= data[i].num;     }     if (total > 0)       printf( -1 n );     else if (maxnum * 2 > n)       printf( -1 n );     else {       int idx = 0;       int j;       for (i = 0; i < m; i++) {         for (j = 0; j < data[i].num; j++) {           ret[idx] = data[i].id;           idx += 2;           if (idx >= n) idx = 1;         }       }       for (i = 0; i < n; i++) printf( %d  , ret[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin.tie(0);   }   int main() {     c_p_c();     int Q;     cin >> Q;     while (Q--) {       int n, h = 0, j = 0, b[2];       cin >> n;       for (int i = 1; i <= n; i++) {         int a;         cin >> a;         if (a % 2 == 0)           h = i;         else {           if (j == 2) continue;           b[j++] = i;         }       }       if (h > 0)         cout <<  1 n  << h <<   n ;       else if (j == 2) {         cout <<  2 n  << b[0] <<     << b[1] <<   n ;       } else         cout <<  -1 n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int fact(long long int n) {     long long int ans = 1;     for (long long int i = 2; i <= n; i++)       ans = (ans % 1000000007 * i % 1000000007) % 1000000007;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       cout << (n % 1000000007 * fact(2 * n - 1) % 1000000007) % 1000000007            << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T, cas = 0;     scanf( %d , &T);     while (cas++ < T) {       int sum = 0, s[251], maxi = 0;       for (int i = 1; i <= 250; i++) {         scanf( %d , s + i);         sum += s[i];         maxi = max(s[i], maxi);       }       double aver = sum / 250.0, fang = 0;       for (int i = 1; i <= 250; i++) {         fang += (s[i] - aver) * (s[i] - aver);       }       fang /= 250;       if (fang / aver > 2) {         printf( %.0f n , maxi * 1.04 / 2);       } else         printf( %.0f n , aver);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string to_string(bool b) { return (b ?  true  :  false ); }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int mod = 1000000007;   void solve() {     int n;     cin >> n;     map<string, int> m;     vector<string> v(n);     for (int i = 0; i < (n); ++i) cin >> v[i];     for (int i = 0; i < (n); ++i) {       for (int j = 1; j <= 8; j++) {         for (int k = 0; k + j <= 9; k++) {           m[v[i].substr(k, j)]++;         }       }     }     vector<string> ans(n);     for (int i = 0; i < (n); ++i) {       map<string, int> mm;       for (int j = 1; j <= 8; j++) {         for (int k = 0; k + j <= 9; k++) {           mm[v[i].substr(k, j)]++;         }       }       string anss = v[i];       int len = 9;       for (auto it = mm.begin(); it != mm.end(); it++) {         if (m[it->first] == it->second) {           if ((int)(it->first).size() < len) {             len = (int)(it->first).size();             anss = it->first;           }         }       }       ans[i] = anss;     }     for (int i = 0; i < (n); ++i) cout << ans[i] <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     while (tt--) solve();   }
#include <bits/stdc++.h>   const int MAXN = 2000 + 10;   int n;   char s[MAXN];   struct Bitset {     static const int SIZE = 2048 / 64;     unsigned long long a[SIZE];     int cnt;     int high;     Bitset() {       memset(a, 0, sizeof a);       cnt = 0;       high = 0;     }     inline bool at(int x) { return (a[x >> 6] >> (x & 63)) & 1; }     inline void setone(int x) {       cnt += !at(x);       high = std::max(high, x >> 6);       a[x >> 6] |= (1ull << (x & 63));     }     inline int count() const { return cnt; }     void operator^=(const Bitset &rhs) {       cnt = 0;       high = std::max(high, rhs.high);       for (int i = 0; i <= high; i++) {         a[i] ^= rhs.a[i];         cnt += __builtin_popcountll(a[i]);       }     }   };   Bitset a[MAXN], b[MAXN];   Bitset x;   void insert(int cur) {     Bitset ans;     ans.setone(cur);     for (register int j = 2000; j >= 0; j--) {       if (!x.at(j)) continue;       if (b[j].count() == 0) {         puts( 0 );         std::swap(a[j], x);         std::swap(b[j], ans);         return;       }       ans ^= b[j];       x ^= a[j];       if (x.count() == 0) break;     }     printf( %d , ans.count() - 1);     for (int i = 1; i < cur; i++) {       if (ans.at(i)) {         printf(  %d , i - 1);       }     }     printf(  n );   }   Bitset to_binary() {     int n = strlen(s + 1);     static int num[MAXN];     std::reverse(s + 1, s + n + 1);     const int B = 8;     int cnt = 1, p = 1;     for (int i = 1; i <= n; i++) {       num[cnt] += (s[i] -  0 ) * p;       p *= 10;       if (i % B == 0) {         cnt++;         p = 1;       }     }     int cur = 0;     Bitset ans;     if (num[cnt] == 0) cnt--;     n = cnt;     while (n) {       if (num[1] & 1) ans.setone(cur);       cur++;       int res = 0;       for (int i = n; i >= 1; i--) {         num[i] += res * 100000000;         res = num[i] % 2;         num[i] /= 2;       }       while (n > 0 && num[n] == 0) n--;     }     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       x = to_binary();       insert(i);     }   }
#include <bits/stdc++.h>   using namespace std;   int N;   string get_block(const string &str) {     string res;     if (str.length() < 4) res.append(4 - str.length(),  0 );     res.append(str);     return res;   }   string process(const string &addr) {     string res;     int all = count(addr.begin(), addr.end(),  : );     int i = 0, j = 0;     int num = 0;     while (j = addr.find( : , i + 1), j != (int)string::npos) {       if (addr[i] ==  :  && addr[j] ==  : ) {         for (int k = 0; k < 8 - all + 1; k++) res.append( 0000: );         i++;       }       res.append(get_block(addr.substr(i, j - i)) +  : );       num++;       i = j + 1;     }     return string(res.begin(), res.end() - 1);   }   int main() {     cin >> N;     for (int t = 0; t < N; t++) {       string addr;       cin >> addr;       if (addr ==  :: ) addr =  0000::0000 ;       addr.push_back( : );       cout << process(addr) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ret = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       ret = (ret << 1) + (ret << 3) + ch -  0 ;       ch = getchar();     }     return ret * f;   }   int n, m, x, y, deg[25];   bool edge[25][25], vis[25];   int main() {     n = read();     m = read();     for (register int i = 1; i <= m; i++) {       x = read();       y = read();       if (x == y) continue;       if (edge[x][y]) continue;       deg[x]++;       deg[y]++;       edge[x][y] = 1;       edge[y][x] = 1;     }     for (register int i = 1; i <= n; i++) {       int st = i, j;       memset(vis, 0, sizeof(vis));       vis[st] = 1;       for (j = 1; j < n; j++) {         int minn = 0, de = 0;         for (register int k = 1; k <= n; k++) {           if (edge[st][k] && !vis[k]) {             if (de == 0 || minn > deg[k]) {               de = k;               minn = deg[k];             }           }         }         if (de == 0) break;         st = de;         vis[st] = 1;       }       if (j == n) {         printf( Yes n );         return 0;       }     }     printf( No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double jd[1100000], x[1100000], y[1100000];   long double pi =       3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647;   int n, m;   bool b;   long double qq;   void cty(int k, int l, int r, int o) {     if (l > o || r < o) return;     if (l == r) {       if (b)         jd[k] += qq;       else         x[k] += qq;       return;     }     int m = (l + r) >> 1, e = k << 1;     cty(e, l, m, o), cty(e ^ 1, m + 1, r, o);     jd[k] = jd[e] + jd[e ^ 1];     x[k] = x[e] + x[e ^ 1] * cos(jd[e]) - y[e ^ 1] * sin(jd[e]);     y[k] = y[e] + x[e ^ 1] * sin(jd[e]) + y[e ^ 1] * cos(jd[e]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) x[i + 524288] = 1.0;     for (int i = 524287; i; i--) {       int e = i << 1;       jd[i] = jd[e] + jd[e ^ 1];       x[i] = x[e] + x[e ^ 1] * cos(jd[e]) - y[e ^ 1] * sin(jd[e]);       y[i] = y[e] + x[e ^ 1] * sin(jd[e]) + y[e ^ 1] * cos(jd[e]);     }     while (m--) {       int q, w, Z;       long double z;       scanf( %d%d%d , &q, &w, &Z);       z = Z;       qq = (q == 1) ? z : -z / 180.0 * pi;       b = q - 1;       if (b) w--;       cty(1, 0, 524287, w);       printf( %.20lf %.20lf n , (double)x[1], (double)y[1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   int n, x[maxn], y[maxn], r;   void write(int x) {     if (x <= 50)       printf( %d , x);     else {       printf( (50+ );       write(x - 50);       printf( ) );     }   }   void work() {     for (int i = 1; i < n; i++) printf( ( );     for (int i = 1; i <= n; i++) {       if (i > 1) printf( + );       printf( ( );       write(x[i]);       printf( *((1-abs((t- );       write(i - 1);       printf( )))+abs((abs((t- );       write(i - 1);       printf( ))-1)))) );       if (i > 1) printf( ) );     }     printf(  n );   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , x + i, y + i, &r);       x[i] /= 2;       y[i] /= 2;     }     work();     memcpy(x, y, sizeof(y));     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long C[2333][2333];   int d, MOD, p = 0;   long long co[23333];   vector<int> operator-(vector<int> a, vector<int> b) {     vector<int> s;     int u = max(a.size(), b.size());     a.resize(u);     b.resize(u);     for (int i = 0; i < u; ++i) s.push_back((a[i] - b[i]) % MOD);     return s;   }   long long qp(long long a, long long b) {     long long x = 1;     a %= MOD;     while (b) {       if (b & 1) x = x * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return x;   }   int add(int a, int b) {     ++p;     cout <<  +   << a <<     << b <<     << p << endl;     co[p] = (co[a] + co[b]) % MOD;     return p;   }   int po(int a) {     ++p;     cout <<  ^   << a <<     << p << endl;     co[p] = qp(co[a], d);     return p;   }   int mul(int a, int k) {     k = (k % MOD + MOD) % MOD;     if (!k) k += MOD;     int s = a;     --k;     while (k) {       if (k & 1) s = add(s, a);       a = add(a, a);       k >>= 1;     }     return s;   }   int neg(int a) { return mul(a, MOD - 1); }   int minus_(int a, int b) { return add(a, neg(b)); }   void op(int a) {     cout <<  f   << a << endl;     cerr << co[a] << endl;   }   int l = 3, z;   long long show(vector<int>& v, long long t) {     long long x = 1, s = 0;     for (int i = 0; i < v.size(); ++i)       s += x * v[i] % MOD, s %= MOD, x = x * t % MOD;     return (s % MOD + MOD) % MOD;   }   int p2(int a) {     if (d == 2) return po(a);     int n = d + 1;     static vector<int> u[233], ss[233];     static int w[233], ww[233];     ww[0] = a;     for (int i = 1; i <= n; ++i) {       u[i].clear();       ss[i].clear();       for (int w = 0; w <= d; ++w) u[i].push_back(C[d][w] * qp(i, d - w) % MOD);       ww[i] = add(ww[i - 1], l);       w[i] = po(ww[i]);       ss[i].resize(n + 1);       ss[i][i] = 1;     }     for (int s = 0; s <= d; ++s) {       long long x = u[s + 1][s] % MOD;       if (!x) {         for (int q = s + 2; q <= n; ++q)           if (u[q][s] % MOD) {             x = u[q][s] % MOD;             for (int i = 1; i <= n; ++i) swap(ss[i][s + 1], ss[i][q]);             swap(u[s + 1], u[q]);             break;           }       }       if (!x) throw  GG ;       long long rv = qp(x, MOD - 2);       for (auto& w : u[s + 1]) w = w % MOD * rv % MOD;       for (auto& w : ss[s + 1]) w = w % MOD * rv % MOD;       for (int q = 1; q <= n; ++q)         if (q != s + 1 && u[q][s] % MOD) {           long long v = u[q][s] % MOD;           for (int e = 1; e <= n; ++e)             ss[q][e] = (ss[q][e] - ss[s + 1][e] * v) % MOD;           for (int e = 0; e <= d; ++e)             u[q][e] = (u[q][e] - u[s + 1][e] * v) % MOD;         }     }     int aa = z;     for (int i = 1; i <= n; ++i)       if (ss[3][i]) aa = add(aa, mul(w[i], ss[3][i]));     return aa;   }   int main() {     cin >> d >> MOD;     p = 4;     for (int i = 0; i < 23333; ++i) co[i] = 1;     for (int i = 0; i < 2333; ++i) {       C[i][0] = 1;       for (int j = 1; j <= i; ++j)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;     }     co[1] = 5;     co[2] = 3;     z = minus_(l, l);     op(mul(minus_(minus_(p2(add(1, 2)), p2(1)), p2(2)), (MOD + 1) / 2));   }