malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   T mulmod(T a, T b) {     if (b == 0) return 0;     if (b == 1) return a;     T x = mulmod(a, b >> 1);     x = (x + x) % 1000000007;     if (b & 1) x = (x + a) % 1000000007;     return x;   }   template <class T>   T larger(T a, T b) {     return (a > b ? a : b);   }   template <class T>   T smaller(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   template <class T>   string converter(T n) {     stringstream x;     x << n;     return x.str();   }   template <class T>   T pw(T a, T b) {     if (b == 0) return 1;     T x = pw(a, b >> 1);     x = mulmod(x, x);     if (b & 1) x = mulmod(x, a);     return x;   }   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   void letsgo() {     long long int a, b, x, n;     cin >> a >> b >> n >> x;     if (a == 1) {       cout << (x + (n % 1000000007 * b) % 1000000007) % 1000000007;       return;     }     long long int aN = pw(a, n);     long long int ans = (aN * x) % 1000000007;     long long int z = ((aN - 1 + 1000000007) % 1000000007 * b) % 1000000007;     z = (z * pw(a - 1, 1000000007 - 2ll)) % 1000000007;     cout << (ans + z) % 1000000007;   }   int main() {     letsgo();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-8;   const double PI = acos(-1.0);   const int maxn = 200 + 10;   char str[maxn];   struct TwoSat {     int n;     vector<int> G[maxn * 2];     bool mark[maxn * 2];     int S[maxn * 2], c;     bool isv[maxn];     int sz;     bool dfs(int x) {       if (mark[x ^ 1]) return false;       if (mark[x]) return true;       if (x / 2 < xi) {         int id = str[x / 2] -  a ;         if (isv[id] != (x & 1)) return false;         tmp[x / 2] = str[x / 2];       } else if (x / 2 == xi) {         int t = get_min(str[xi] -  a , (x & 1) ? true : false);         if (t == -1) return false;         tmp[x / 2] = t +  a ;       } else {         int t = get_min(-1, (x & 1) ? true : false);         if (t == -1) return false;         tmp[x / 2] = t +  a ;       }       mark[x] = true;       S[c++] = x;       for (int i = 0; i < G[x].size(); i++)         if (!dfs(G[x][i])) return false;       return true;     }     void init(int n, char *s) {       this->n = n;       for (int i = 0; i < n * 2; i++) G[i].clear();       memset(mark, false, sizeof(mark));       sz = strlen(s);       for (int i = 0; i < sz; i++) isv[i] = s[i] ==  V  ? true : false;     }     void add_clause(int x, int xval, int y, int yval) {       x = x * 2 + xval;       y = y * 2 + yval;       G[x ^ 1].push_back(y);       G[y ^ 1].push_back(x);     }     int get_min(int pos, bool c) {       for (int i = pos + 1; i < sz; i++) {         if (c == isv[i]) return i;       }       return -1;     }     char ans[maxn], tmp[maxn];     int xi;     void solve() {       bool OK = false;       for (int pos = 0; pos <= n; pos++) {         for (int x = 0; x <= 1; x++) {           xi = pos;           bool ok = false;           memset(mark, false, sizeof(mark));           strcpy(tmp, str);           if (pos < n) {             int t = get_min(str[pos] -  a , (x & 1) ? true : false);             if (t == -1) continue;             tmp[pos] = t +  a ;           }           for (int i = pos + 1; i < n; i++) tmp[i] =  a ;           c = 0;           for (int i = 0; i < n; i++) {             int x1 = (i << 1) | (isv[tmp[i] -  a ]);             if (!dfs(x1)) {               ok = true;               break;             }           }           if (n == 200) {           }           if (ok) continue;           OK = true;           tmp[n] = 0;           if (ans[0] == 0)             strcpy(ans, tmp);           else if (strcmp(tmp, ans) < 0)             strcpy(ans, tmp);         }       }       if (OK)         printf( %s n , ans);       else         printf( -1 n );     }   } sat;   int main() {     int n, m;     while (~scanf( %s , str)) {       scanf( %d%d , &n, &m);       sat.init(n, str);       for (int i = 0, x, y, xval, yval; i < m; i++) {         char t1[5], t2[5];         scanf( %d%s%d%s , &x, t1, &y, t2);         xval = t1[0] ==  V  ? 1 : 0;         yval = t2[0] ==  V  ? 1 : 0;         --x;         --y;         sat.add_clause(x, xval ^ 1, y, yval);       }       scanf( %s , str);       sat.solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int thien, n, tt, h;   string s;   int main() {     cin >> tt;     for (int ii = 1; ii <= tt; ii++) {       cin >> n;       thien = 0;       h = 0;       for (int i = 1; i <= n; i++) {         cin >> s;         if (s.length() % 2 != 0) thien++;         for (int j = 0; j < s.length(); j++)           if (s[j] ==  1 ) h++;       }       if (h % 2 != 0 && thien == 0)         cout << n - 1 << endl;       else         cout << n << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   int p1[maxn], p2[maxn], q[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &p1[i]);       p1[i]--;       p2[p1[i]] = i;       q[i] = n;     }     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       x = p2[x];       y = p2[y];       if (x > y) swap(x, y);       q[x] = min(q[x], y);     }     int r = n - 1;     long long ans = 0;     for (int i = n - 1; i >= 0; i--) {       r = min(q[i] - 1, r);       ans += r - i + 1;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200001];   const double esl = 1e-11;   double cal(double x) {     double t = 0;     double ans = 0;     for (int i = 1; i <= n; i++) {       if (t + a[i] - x < 0) {         ans = max(ans, t);         t = 0;       } else {         t += ((double)a[i] - x);         ans = max(ans, t);       }     }     ans = max(ans, t);     double t1 = 0;     for (int i = 1; i <= n; i++) {       if (t1 + a[i] - x > 0) {         ans = max(ans, -t1);         t1 = 0;       } else {         t1 += ((double)a[i] - x);         ans = max(ans, -t1);       }     }     ans = max(ans, -t1);     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     double l = -(1e5);     double r = 1e5;     for (int i = 1; i <= 500; i++) {       double d = (2.0 * l + r) / 3;       double c = (2.0 * r + l) / 3;       if (cal(d) > cal(c)) {         l = d;       } else         r = c;     }     printf( %.10f , cal(l));     return 0;   }
#include <bits/stdc++.h>   const int N = 5e4 + 10;   int n, m;   std::vector<char> a[N];   int sx[N], sy[N];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; ++i) {         a[i].resize(m + 2);         getchar();         for (int j = 1; j <= m; ++j) scanf( %c , &a[i][j]);       }       int cnt_x = 0, cnt_y = 0, p_x = 1, p_y = 1;       for (int i = 1; i <= n; ++i) {         int sum = 0;         for (int j = 1; j <= m; ++j) sum += (a[i][j] ==  * );         sx[i] = sum;       }       for (int i = 1; i <= m; ++i) {         int sum = 0;         for (int j = 1; j <= n; ++j) sum += (a[j][i] ==  * );         sy[i] = sum;       }       int ans = 0x3f3f3f3f;       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j) {           int now = n + m - sx[i] - sy[j];           if (a[i][j] ==  . ) --now;           ans = std::min(ans, now);         }       printf( %d n , ans);       for (int i = 1; i <= n; ++i) a[i].clear(), sx[i] = 0;       for (int i = 1; i <= m; ++i) sy[i] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   auto clk = clock();   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   void test_case() {     long long int n;     cin >> n;     long long int a[n + 1];     long long int t = -1, b = -1, c = -1;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     for (long long int i = 2; i <= n - 1; i++) {       for (long long int j = i - 1; j >= 1; j--) {         if (a[j] < a[i]) {           t = j;           break;         }       }       for (long long int j = i + 1; j <= n; j++) {         if (a[j] < a[i]) {           c = j;           break;         }       }       if (t != -1 && c != -1) {         b = i;         break;       }       t = -1, c = -1;     }     if (b != -1) {       cout <<  YES  << endl;       cout << t <<     << b <<     << c << endl;     } else       cout <<  NO  << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     cout << fixed << setprecision(10);     long long int t = 1;     cin >> t;     while (t--) {       test_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long nthRoot(long long A, long long N) {     float xPre = rand() % 10;     float eps = 1e-3;     float delX = LLONG_MAX;     float xK;     while (delX > eps) {       xK = ((N - 1.0) * xPre + (float)A / pow(xPre, N - 1)) / (float)N;       delX = abs(xK - xPre);       xPre = xK;     }     return ceil(xK);   }   int main() {     long long n;     cin >> n;     char a[] = { c ,  o ,  d ,  e ,  f ,  o ,  r ,  c ,  e ,  s };     long long in = 0, num;     num = nthRoot(n, 10);     if (pow(num, 10) < n) num++;     for (int i = 0; i <= 10; i++) {       if (pow(num - 1, i) * pow(num, 10 - i) >= n) {         in = i;       } else         break;     }     if (in * (num - 1) + (10 - in) * num - 10 < n - 1) {       for (int i = 0; i < in; i++) {         long long t = num - 1;         while (t--) cout << a[i];       }       for (int i = in; i < 10; i++) {         long long t = num;         while (t--) cout << a[i];       }     } else {       for (int i = 0; i < 10; i++) cout << a[i];       long long t = n - 1;       while (t--) cout << a[9];     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void amin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   inline void amax(T& a, const T& b) {     if (a < b) a = b;   }   template <class T>   inline void rv(vector<T>& v, int n) {     vector<T>(n).swap(v);     for (int i = 0; i < (n); i++) cin >> v[i];   }   inline void rv(int* v, int n) {     for (int i = 0; i < (n); i++) scanf( %d , &v[i]);   }   inline void rv(long long* v, int n) {     for (int i = 0; i < (n); i++) scanf( %lld , &v[i]);   }   inline vector<int> rvi(int n) {     vector<int> v(n);     for (int i = 0; i < (n); i++) scanf( %d , &v[i]);     return v;   }   inline vector<long long> rvl(int n) {     vector<long long> v(n);     for (int i = 0; i < (n); i++) scanf( %lld , &v[i]);     return v;   }   inline vector<string> rvs(int n) {     vector<string> v(n);     for (int i = 0; i < (n); i++) scanf( %s , &v[i]);     return v;   }   template <class T>   inline void readvv(vector<vector<T>>& v, int m, int n) {     vector<vector<T>>(m).swap(v);     for (int i = 0; i < (m); i++) readv(v[i], n);   }   inline void pvi(vector<int>& v) {     for (int i = 0; i < (v.size()); i++) printf( %d  , v[i]);     printf(  n );   }   inline void pvl(vector<long long>& v) {     for (int i = 0; i < (v.size()); i++) {       printf( %lld  , v[i]);     }     printf(  n );   }   inline void pvs(vector<string>& v) {     for (int i = 0; i < (v.size()); i++) {       printf( %s n , v[i].c_str());     }   }   int main() {     long long n;     long double s;     cin >> n >> s;     vector<vector<long long>> g(n);     for (int i = 0; i < (n - 1); i++) {       long long u, v;       cin >> u >> v;       g[u - 1].push_back(v - 1);       g[v - 1].push_back(u - 1);     }     long double leaves = 0, two = 2;     for (int i = 0; i < (n); i++) {       if (g[i].size() == 1) leaves++;     }     cout << setprecision(20) << endl;     cout << ((two * s) / leaves) << endl;     return 0;   }
#include  bits/stdc++.h    using namespace std;   #define all(x) x.begin(),x.end()   #define pb push_back   #define ff first   #define ss second   #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)   #define ar array   #define int long long    #define F(i,a,b) for(i=a;i<b;++i)   #define RF(i,b,a) for(i=b;i>=a;--i)    #define NL cout<<  n ;   #define INF LONG_LONG_MAX   #define pii pair<int,int>   #define vi vector<int>      typedef long long ll;   typedef long double ld;   const ll mod=1e9+7;   bool comp(ll a,ll b)   {    return a<b;   }   ll fpow(ll a, ll b) {       ll res=1;    while(b) {     if(b&1)      res=(res*a);     a=(a*a);     b>>=1;    }    return res;   }      ll minm(ll a,ll b){    if(a<b) return a;    return b;   }      ll maxm(ll a,ll b){    if(a>b){ return a;}    else return b;   }      int PHI(int k){    // This is Euler s Totient Function.    //This function returns no. of coprime numbers to N in range [1,2,....,N]         int ans=k;      for(int i=2;i*i<=k;++i){       if(k%i==0){        ans-=ans/i;        while(k%i==0){         k/=i;        }       }      }        if(k>1) ans-=ans/k;        return ans;          }      void solve(){           int n,i;      cin >> n;            vector<pii>ecells;      vector<pii>ocells;            for(i=1;i<=n;i++){       for(int j=1;j<=n;j++){        if((i+j)%2){         ocells.pb({i,j});        }        else ecells.pb({i,j});       }      }            // 1 even      // 2,3 odd      // if not possible ie all odd are filled, fill 2,3 in even            int cnt=0;            while(cnt<n*n){       int a; cin >> a;              if(a==1){         // try to fill 2 in odd cell          // if not possible , fill 3 in even         if(ocells.empty()){          cout<< 3  <<ecells.back().ff<<   <<ecells.back().ss<<endl;          ecells.pop_back();         }                  else{          cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl;          ocells.pop_back();         }         ++cnt;       }              else if(a==2){        // fill 1 in even , if possible        if(!ecells.empty()){         cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl;         ecells.pop_back();        }                else{         // fill 3 in ocells         cout<< 3  <<ocells.back().ff<<   <<ocells.back().ss<<endl;         ocells.pop_back();        }        cnt++;       }       else{        // fill 1 in even if possible        if(!ecells.empty()){         cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl;         ecells.pop_back();        }        else{         // fill 2 in odd         cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl;         ocells.pop_back();        }        cnt++;       }      }                  }         signed main(void)        {       fast;            int _=1;    //cin>>_;             for(int test_case=1;test_case<=_;++test_case){            solve();         }             }
#include <bits/stdc++.h>   int main() {     char str[3][100];     int i;     for (i = 0; i < 3; i++) {       scanf( %s  , &str[i][0]);     }     int r = 0, p = 0, s = 0;     for (i = 0; i < 3; i++) {       if (str[i][0] ==  r )         r++;       else if (str[i][0] ==  p )         p++;       else if (str[i][0] ==  s )         s++;     }     char m =  a ;     if (r == 1 && s == 2)       m =  r ;     else if (s == 1 && p == 2)       m =  s ;     else if (p == 1 && r == 2)       m =  p ;     if (m !=  a ) {       for (i = 0; i < 3; i++) {         if (str[i][0] == m) break;       }       if (i == 0)         printf( F );       else if (i == 1)         printf( M );       else if (i == 2)         printf( S );     } else       printf( ? );   }
#include <bits/stdc++.h>   using namespace std;   long long int powe(long long int d, long long int s) {     if (s == 1)       return d;     else if (s == 0)       return 1;     else {       long long int u, v = d;       for (u = 1; u < s; u++) {         d = d * v;       }       return d;     }   }   bool isprime(long long int n) {     long long int i;     for (i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long int a[2000005], c[10000005];   int main() {     map<int, int> b;     long long int i, p, y, mx = -1, j, q;     cin >> p >> y;     for (i = y; i > p; i--) {       q = 1;       for (j = 2; j * j <= i && j <= p; j++) {         if (i % j == 0) {           q = 0;           break;         }       }       if (q == 1) {         cout << i;         return 0;       }     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   using llint = long long;   using par = pair<int, int>;   const int MAXN = 200100;   llint w[MAXN];   vector<par> edges[MAXN];   int p[MAXN], in[MAXN], out[MAXN], idx[MAXN], id;   void dfs(int u) {     in[u] = ++id;     for (const auto& edge : edges[u]) {       if (edge.first == p[u]) continue;       p[edge.first] = u;       idx[edge.first] = edge.second;       dfs(edge.first);     }     out[u] = id;   }   int next(int u) { return w[idx[u]] == 1 ? p[u] = next(p[u]) : u; }   void toLCA(int u, int v, llint& c) {     if (!u || !c) return;     if (in[u] <= in[v] && out[u] >= out[v]) return;     c /= w[idx[u]];     toLCA(p[u] = next(p[u]), v, c);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     llint c;     int n, m, u, v;     cin >> n >> m;     for (int i = 1; i < n; ++i) {       cin >> u >> v >> w[i];       edges[u].emplace_back(v, i);       edges[v].emplace_back(u, i);     }     dfs(1);     while (m--) {       cin >> u;       if (u == 1) {         cin >> u >> v >> c;         toLCA(u, v, c);         toLCA(v, u, c);         cout << c <<   n ;       } else {         cin >> u >> c;         w[u] = c;       }     }   }
#include <bits/stdc++.h>   using namespace std;   bool found = false;   long long b, A[10000], n, orig_a;   void bfs(long long a, long long k) {     if (found) return;     if (a > b) return;     if (a == b) {       found = true;       n = k;       a = orig_a;       cout <<  YES  << endl;       cout << n + 1 << endl;       cout << a;       for (int i = 0; i < n; i++) {         if (A[i] == 1) {           a = a * 10 + 1;           cout <<     << a;         } else if (A[i] == 2) {           a = a * 2;           cout <<     << a;         }       }       cout << endl;       return;     }     A[k] = 2;     bfs(a * 2, k + 1);     A[k] = 1;     bfs((a * 10) + 1, k + 1);   }   int main() {     long long a, c, d, i, j, m;     string s;     cin >> a >> b;     orig_a = a;     bfs(a, 0);     if (!found) cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Compare {    public:     bool operator()(pair<long long, long long> a, pair<long long, long long> b) {       return (a.first + a.second) > (b.first + b.second);     }   };   int main() {     long long test, x, n, m, k, w, d, f, y;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >, Compare>         pqw;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >, Compare>         pqd;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >, Compare>         pqf;     scanf( %lld%lld%lld%lld%lld%lld%lld , &x, &n, &m, &k, &w, &d, &f);     for (long long i = 0; i < n; i++) {       pqw.push(make_pair(0, w));     }     for (long long i = 0; i < m; i++) {       pqd.push(make_pair(0, d));     }     for (long long i = 0; i < k; i++) {       pqf.push(make_pair(0, f));     }     long long ans = 0;     for (long long i = 0; i < x; i++) {       pair<long long, long long> cur = pqw.top();       pqw.pop();       pqw.push(make_pair(cur.first + cur.second, cur.second));       pair<long long, long long> curd = pqd.top();       pqd.pop();       curd.first = max(cur.first + cur.second, curd.first) + d;       pqd.push(curd);       pair<long long, long long> curf = pqf.top();       pqf.pop();       curf.first = max(curd.first, curf.first) + f;       pqf.push(curf);       ans = curf.first;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7;   vector<int> b[200005];   int L[200005], R[200005], u[200005], v[200005], opt[200005], size[200005];   int m, n, ql, qr, upd, tot, now, ans, i, x;   struct data {     int cnt, sum;     data() { cnt = 1; }     void multi(int x) {       cnt = 1ll * cnt * x % P;       sum = 1ll * sum * x % P;     }     int renew(int x) {       cnt = 1;       sum = x;       return 0;     }   } a[200005 << 2];   void DFS(int x, int Fa) {     L[x] = ++tot;     for (int i = 0, y; i < b[x].size(); i++)       if ((y = b[x][i]) != Fa) DFS(y, x);     R[x] = tot;   }   int INV(int a) {     int ret = 1, b = P - 2;     for (; b; b >>= 1, a = 1ll * a * a % P)       if (b & 1) ret = 1ll * ret * a % P;     return ret;   }   inline void down(int x) {     if (a[x].cnt == 1) return;     a[x << 1].multi(a[x].cnt);     a[x << 1 | 1].multi(a[x].cnt);     a[x].cnt = 1;   }   inline void up(int x) { a[x].sum = (a[x << 1].sum + a[x << 1 | 1].sum) % P; }   void Multi(int x, int l, int r) {     if (ql <= l && r <= qr) {       a[x].multi(now);       return;     }     int mid = (l + r) >> 1;     down(x);     if (ql <= mid) Multi(x << 1, l, mid);     if (qr > mid) Multi(x << 1 | 1, mid + 1, r);     up(x);   }   int Update(int x, int l, int r, int pos) {     if (l == r) return (!upd) ? a[x].sum : a[x].renew(now);     int mid = (l + r) >> 1;     down(x);     int ret = (pos <= mid) ? Update(x << 1, l, mid, pos)                            : Update(x << 1 | 1, mid + 1, r, pos);     return up(x), ret;   }   void Query(int x, int l, int r) {     if (ql <= l && r <= qr) {       ans = (ans + a[x].sum) % P;       return;     }     int mid = (l + r) >> 1;     down(x);     if (ql <= mid) Query(x << 1, l, mid);     if (qr > mid) Query(x << 1 | 1, mid + 1, r);   }   int main() {     scanf( %d%d , &v[1], &m);     n = 1;     for (i = 1; i <= m; i++) {       scanf( %d%d , &opt[i], &u[i]);       if (opt[i] == 1) scanf( %d , &v[++n]), b[u[i]].push_back(n);     }     DFS(1, 0);     size[n = 1] = 1;     upd = 1;     now = v[1];     Update(1, 1, tot, L[1]);     for (i = 1; i <= m; i++)       if (opt[i] == 1) {         x = u[i];         size[++n] = 1;         ql = L[x];         qr = R[x];         now = 1ll * (size[x] + 1) * INV(size[x]) % P;         ++size[x];         Multi(1, 1, tot);         upd = 0;         now = Update(1, 1, tot, L[x]);         now = 1ll * now * INV(v[x]) % P;         now = 1ll * now * v[n] % P;         upd = 1;         Update(1, 1, tot, L[n]);       } else {         x = u[i];         ans = 0;         ql = L[x];         qr = R[x];         Query(1, 1, tot);         upd = 0;         now = Update(1, 1, tot, L[x]);         now = 1ll * now * INV(1ll * v[x] * size[x] % P) % P;         ans = 1ll * ans * INV(now) % P;         printf( %d n , ans);       }   }