malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int N = 2e5 + 10;   const int M = 300;   int a[N];   int b[N];   int typ[N];   int flag[N];   int root[N];   int tmp[N];   int q[N];   int qn;   int find_root(int u) {     if (u == root[u]) {       return u;     }     root[u] = find_root(root[u]);     return root[u];   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d , typ + i);       scanf( %d , a + i);       scanf( %d , b + i);     }     int t = 0;     set<pii> st;     set<pii> cr;     int last = 0;     while (t < m) {       for (int i = 1; i <= n; i++) {         flag[i] = 0;         root[i] = i;       }       for (int i = t; i < min(m, t + M); i++) {         if (a[i] > b[i]) {           swap(a[i], b[i]);         }         flag[a[i]] = 1;         flag[b[i]] = 1;         flag[a[i] + 1] = 1;         flag[b[i] < n ? b[i] + 1 : 1] = 1;       }       qn = 0;       for (int i = 1; i <= n; i++) {         if (flag[i] == 1) {           q[qn++] = i;         }       }       int u, v, uu, vv;       cr.clear();       for (auto r : st) {         u = r.first;         v = r.second;         if (flag[u] && flag[v]) {           cr.insert(pii(u, v));           continue;         }         u = find_root(u);         v = find_root(v);         root[u] = v;       }       for (int i = 0; i < qn; i++) {         root[q[i]] = find_root(q[i]);       }       sort(q, q + qn, [&](int i, int j) { return root[i] < root[j]; });       for (int i = 0, j; i < qn; i = j) {         j = i;         while (j < qn && root[q[j]] == root[q[i]]) {           tmp[q[j]] = q[i];           j++;         }       }       for (auto r : cr) {         uu = find_root(r.first);         vv = find_root(r.second);         root[uu] = vv;       }       for (int i = t; i < min(m, t + M); i++) {         u = a[i];         v = b[i];         if (last) {           u++;           v < n ? v++ : v = 1;         }         if (u > v) {           swap(u, v);         }         if (typ[i] == 1) {           if (cr.count(pii(u, v))) {             cr.erase(pii(u, v));             st.erase(pii(u, v));             for (int i = 0; i < qn; i++) {               root[q[i]] = tmp[q[i]];             }             for (auto r : cr) {               uu = find_root(r.first);               vv = find_root(r.second);               root[uu] = vv;             }           } else {             cr.insert(pii(u, v));             st.insert(pii(u, v));             u = find_root(u);             v = find_root(v);             root[u] = v;           }         } else {           u = find_root(u);           v = find_root(v);           if (u == v) {             putchar( 1 );             last = 1;           } else {             putchar( 0 );             last = 0;           }         }       }       t += M;     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, t;     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       int b, k;       cin >> n >> b >> k;       int arr[n];       for (i = 0; i < n; i++) cin >> arr[i];       int flag = 1;       for (i = 0; i < n - 1; i++) {         if (arr[i] >= arr[i + 1]) {           b += arr[i] - arr[i + 1] + min(k, arr[i + 1]);         } else if (arr[i + 1] > arr[i] + k) {           b -= arr[i + 1] - arr[i] - k;           if (b < 0) {             flag = 0;             break;           }         } else {           b += min(arr[i], arr[i] + k - arr[i + 1]);         }       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const double PI = acos(-1.);   const double eps = 1e-9;   char s[1000005];   char t[1000005];   int fs[11];   int ft[11];   int fx[11];   char y[1000005];   int main() {     int i, j, k, _T;     while (~scanf( %s%s , s, t)) {       if (strcmp(s,  01 ) == 0 || strcmp(s,  10 ) == 0) {         printf( 0 n );         continue;       }       memset(fs, 0, sizeof fs);       memset(ft, 0, sizeof ft);       for (i = 0; s[i]; i++) fs[s[i] -  0 ]++;       for (i = 0; t[i]; i++) ft[t[i] -  0 ]++;       int ls = strlen(s);       int lt = strlen(t);       for (int len = lt; len <= ls; len++) {         char x[15];         memset(fx, 0, sizeof fx);         memset(x, 0, sizeof x);         sprintf(x,  %d , len);         int lx = strlen(x);         for (i = 0; x[i]; i++) fx[x[i] -  0 ]++;         int fail = 0;         for (i = 0; i <= 9; i++)           if (fs[i] < ft[i] + fx[i]) {             fail = 1;           }         if (fail || ls - lx != len) continue;         int flag = 0;         for (i = 1; i <= 9; i++) flag |= fs[i] > fx[i] + ft[i];         if (t[0] ==  0  && !flag) continue;         if (!flag) {           printf( %s , t);           for (i = 0; i <= 9; i++)             for (j = 0; j < fs[i] - fx[i] - ft[i]; j++) putchar( 0  + i);           putchar(  n );           break;         }         int id = 0, fi = -1;         for (i = 1; i <= 9; i++)           if (fs[i] > fx[i] + ft[i]) {             fi = i;             break;           }         fs[fi]--;         y[id++] =  0  + fi;         for (i = 0; i <= 9; i++) {           if (t[0] ==  0  + i) {             int big = 0;             for (j = 1; j < lt; j++) {               if (t[j] != t[0]) {                 if (t[j] > t[0]) big = 1;                 break;               }             }             if (!big) {               for (j = 0; j < lt; j++) y[id++] = t[j];             }             for (j = 0; j < fs[i] - fx[i] - ft[i]; j++) y[id++] =  0  + i;             if (big) {               for (j = 0; j < lt; j++) y[id++] = t[j];             }           } else             for (j = 0; j < fs[i] - fx[i] - ft[i]; j++) y[id++] =  0  + i;         }         int ly = id;         fs[fi]++;         id = lt;         for (i = 0; i <= 9; i++)           for (j = 0; j < fs[i] - fx[i] - ft[i]; j++) t[id++] =  0  + i;         int uset = 0;         for (i = 0; i < ly; i++) {           if (y[i] != t[i]) {             if (y[i] > t[i]) uset = 1;             break;           }         }         if (uset && t[0] !=  0 ) {           for (i = 0; i < ly; i++) putchar(t[i]);           putchar(  n );         } else {           for (i = 0; i < ly; i++) putchar(y[i]);           putchar(  n );         }         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5, nax = 1e6 + 5;   char rodz[25];   int id[25];   int res[2 * nax];   int cob(int a) {     if (a) return (a % 2 ? 1 : 0) + cob(a / 2);     return 0;   }   int pro() {     int n;     cin >> n;     vector<int> w;     for (int _ = 1, _n = (n); _ <= _n; ++_) {       int a;       cin >> a;       w.push_back(a);     }     sort(w.begin(), w.end());     reverse(w.begin(), w.end());     cin >> n;     for (int i = 0, _n = (n); i < _n; ++i) cin >> rodz[i] >> id[i];     for (int m = 0, _n = (1 << n); m < _n; ++m)       if (m) {         int jed = cob(m), zer = n - jed;         if (id[zer] == 1) {           res[m] = -inf;           if (rodz[zer] ==  p ) {             for (int i = 0, _n = (n); i < _n; ++i)               if (m & (1 << i)) res[m] = max(res[m], (res[m ^ (1 << i)] + w[i]));           } else             for (int i = 0, _n = (n); i < _n; ++i)               if (m & (1 << i)) res[m] = max(res[m], (res[m ^ (1 << i)]));         } else {           res[m] = inf;           if (rodz[zer] ==  p ) {             for (int i = 0, _n = (n); i < _n; ++i)               if (m & (1 << i)) res[m] = min(res[m], (res[m ^ (1 << i)] - w[i]));           } else             for (int i = 0, _n = (n); i < _n; ++i)               if (m & (1 << i)) res[m] = min(res[m], (res[m ^ (1 << i)]));         }       }     cout << res[(1 << n) - 1];     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     int z = 1;     for (int _ = 1, _n = (z); _ <= _n; ++_) pro();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     long long x;     char c;     long long pr = -1, pb = -1;     long long lr = -1, lb = -1, lp = -1;     long long ans = 0;     long long mr = -1, mb = -1;     for (int i = 0; i < n; i++) {       scanf( %lld %c , &x, &c);       x += (long long)1e10;       if (c ==  P ) {         if (lp == -1) {           if (pr != -1) ans += x - pr;           if (pb != -1) ans += x - pb;         } else {           if (lb != -1) mb = max(mb, x - lb);           if (lr != -1) mr = max(mr, x - lr);           long long dif = x - lp;           if (lr == -1 && lb != -1) {             ans += 2 * dif - mb;           } else if (lr != -1 && lb == -1) {             ans += 2 * dif - mr;           } else if (lr != -1 && lb != -1) {             ans += min(3 * dif - mr - mb, 2 * dif);           } else {             ans += dif;           }         }         mb = mr = lb = lr = -1;         lp = x;       } else if (c ==  B ) {         if (pb == -1) pb = x;         if (mb == -1)           mb = x - lp;         else           mb = max(mb, x - lb);         lb = x;       } else {         if (pr == -1) pr = x;         if (mr == -1)           mr = x - lp;         else           mr = max(mr, x - lr);         lr = x;       }     }     if (lp == -1) {       ans = lr - pr + lb - pb;     } else {       if (lb != -1) ans += lb - lp;       if (lr != -1) ans += lr - lp;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int maxn = 500005;   const long long int mm = 1e+18;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[n], p[m];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < m; i++) cin >> p[i];       bool temp = true;       int count = 0;       while (temp) {         count = 0;         for (int i = 0; i < m; i++) {           int x = p[i], y;           y = x - 1;           if (a[y] > a[x]) {             int str = a[x];             a[x] = a[y];             a[y] = str;             count++;           }         }         if (count == 0) temp = false;       }       count = 0;       for (int i = 0; i < n - 1; i++) {         if (a[i] > a[i + 1]) {           count++;           break;         }       }       if (count > 0) {         cout <<  NO  << endl;       } else         cout <<  YES  << endl;     }     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() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n, m;     cin >> n >> m;     long long ip[n + 10][m + 10];     long long dp1[n + 10][m + 10];     long long dp2[n + 10][m + 10];     long long dp3[n + 10][m + 10];     long long dp4[n + 10][m + 10];     long long answer = 0;     for (long long i = 0; i < n + 10; i++) {       for (long long j = 0; j < m + 10; j++) {         dp1[i][j] = 0;         dp2[i][j] = 0;         dp3[i][j] = 0;         dp4[i][j] = 0;       }     }     for (long long i = 1; i < n + 1; i++) {       for (long long j = 1; j < m + 1; j++) {         cin >> ip[i][j];       }     }     for (long long i = 1; i < n + 1; i++) {       for (long long j = 1; j < m + 1; j++) {         dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + ip[i][j];       }     }     for (long long i = 1; i < n + 1; i++) {       for (long long j = m; j >= 1; j--) {         dp2[i][j] = max(dp2[i - 1][j], dp2[i][j + 1]) + ip[i][j];       }     }     for (long long i = n; i >= 1; i--) {       for (long long j = 1; j < m + 1; j++) {         dp3[i][j] = max(dp3[i + 1][j], dp3[i][j - 1]) + ip[i][j];       }     }     for (long long i = n; i >= 1; i--) {       for (long long j = m; j >= 1; j--) {         dp4[i][j] = max(dp4[i + 1][j], dp4[i][j + 1]) + ip[i][j];       }     }     for (long long i = 1; i < n + 1; i++) {       for (long long j = 1; j < m + 1; j++) {         if (i == 1 || i == n || j == 1 || j == m) {           continue;         }         answer = max(answer, dp1[i - 1][j] + dp4[i + 1][j] + dp3[i][j - 1] +                                  dp2[i][j + 1]);         answer = max(answer, dp1[i][j - 1] + dp4[i][j + 1] + dp3[i + 1][j] +                                  dp2[i - 1][j]);       }     }     cout << answer;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> pp[10];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int i, j, k, l, m, n, even1 = 0, odd1 = 0, count = 0, t, even2 = 0, odd2 = 0,                           even = 0, odd = 0;     cin >> t;     int a[t];     for (i = 0; i < t; i++) {       cin >> a[i];       if (i % 2 == 0) {         odd1 = odd1 + a[i];       } else {         even1 = even1 + a[i];       }     }     for (i = 0; i < t; i++) {       odd = even1 + odd2 - even2;       even = odd1 + even2 - odd2;       if (i % 2 == 0) {         odd2 = odd2 + a[i];         even = even - a[i];       } else {         even2 = even2 + a[i];         odd = odd - a[i];       }       if (even == odd) count++;     }     cout << count << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int arr[n], brr[m], check[n], indexer = 0;     for (int i = 0; i < n; i++) cin >> arr[i], check[i] = -2;     for (int i = 0; i < m; i++) {       cin >> brr[i];       for (int j = 0; j < n; j++)         if (brr[i] == arr[j]) {           check[indexer] = j;           indexer++;         }     }     sort(check, check + indexer);     for (int j = 0; j < indexer; j++) {       cout << arr[check[j]] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string name =          31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31            31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31            31 28 31 30 31 30 31 31 30 31 30 31  ;     string test;     int n;     cin >> n;     string t;     while (n--) {       cin >> t;       test += t;       test +=    ;     }     if (name.find(test) != std::string::npos)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct __TS {     ~__TS() {       cerr <<  Time elapsed:   << clock() * 1.0 / CLOCKS_PER_SEC << endl;     }   } __ts;   const int mod = 1e9 + 7;   const int maxn = 1239;   long long tp[maxn];   int main() {     tp[0] = 1;     for (int i = (int)(1); i < (int)(maxn); i++) {       tp[i] = (2 * tp[i - 1]) % mod;     }     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string x;     cin >> x;     int n = x.size();     long long ans = 0;     for (int i = 0; i < (int)(n); i++) {       if (x[i] ==  0 ) continue;       ans += tp[2 * (n - 1 - i) + i];       ans %= mod;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, maxn = 1000001;   long long t[maxn];   void init() {     for (int i = 0; i <= 1000000; i++) t[i] = (long long)i * i * i;   }   int main() {     init();     int n, a, b;     scanf( %d , &n);     while (n--) {       scanf( %d%d , &a, &b);       long long c = (long long)a * b;       int pos = lower_bound(t, t + maxn, c) - t;       if ((long long)pos * pos * pos == c && a % pos == 0 && b % pos == 0)         printf( Yes n );       else         printf( No n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int pre[N], n, m;   int f(int x) { return pre[x] == x ? x : pre[x] = f(pre[x]); }   set<int> s[N];   map<int, vector<int> > v[N];   void join(int x, int y) {     x = f(x);     y = f(y);     if (x == y) return;     if (s[x].size() < s[y].size()) swap(x, y);     set<int>::iterator it = s[y].begin();     for (; it != s[y].end(); ++it) s[x].insert(*it);     pre[y] = x;   }   void add() {     int x, y, z;     scanf( %d %d %d , &x, &y, &z);     s[f(x)].insert(y);     s[f(y)].insert(x);     v[x][z].push_back(y);     join(y, v[x][z][0]);     v[y][z].push_back(x);     join(x, v[y][z][0]);   }   void query() {     int x, y;     scanf( %d %d , &x, &y);     if (f(x) == f(y) || s[f(x)].count(y))       printf( Yes n );     else       printf( No n );   }   signed main() {     char opt[10];     int c, q;     scanf( %d %d %d %d , &n, &m, &c, &q);     for (register int i = (1); i <= (n); ++i) pre[i] = i;     for (register int i = (1); i <= (m); ++i) add();     for (register int i = (1); i <= (q); ++i) {       scanf( %s , opt);       if (opt[0] ==  + )         add();       else         query();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long n;     cin >> n;     long long i;     if (n == 1)       cout << 1;     else {       long long sum = 1;       for (i = 1;; i++) {         sum += (1ll << i);         if (sum >= n) break;       }       cout << i + 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long R = 1e3 + 69, INF = 2e9 + 6969, mod = 998244353;   long long n, a[R], dp[R], fact[R], rev[R];   long long choose(long long N, long long K) {     long long cur = (fact[N] * rev[K]) % mod;     cur = (cur * rev[N - K]) % mod;     return cur;   }   long long Pow(long long a, long long p) {     long long w = 1;     while (p) {       if (p & 1) w = (w * a) % mod;       a = (a * a) % mod;       p >>= 1;     }     return w;   }   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; ++i) scanf( %lld , &a[i]);     fact[0] = 1;     for (int i = 1; i <= n; ++i) fact[i] = (i * fact[i - 1]) % mod;     rev[n] = Pow(fact[n], mod - 2);     for (int i = n - 1; i >= 0; --i) rev[i] = (rev[i + 1] * (i + 1)) % mod;     dp[n] = 1;     for (int i = n - 1; i >= 0; --i) {       if (a[i] <= 0 || a[i] + i >= n) continue;       for (int j = i + a[i] + 1; j <= n; ++j) {         dp[i] += (dp[j] * choose(j - i - 1, a[i])) % mod;         dp[i] %= mod;       }     }     long long sum = 0;     for (int i = 0; i < n; ++i) sum = (sum + dp[i]) % mod;     printf( %lld n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, h, a, b, k;     cin >> n >> h >> a >> b >> k;     for (long long int i = 0; i < k; i++) {       long long int t1, f1, t2, f2;       cin >> t1 >> f1 >> t2 >> f2;       long long int ans;       if (t1 == t2) {         cout << abs(f1 - f2) << endl;         continue;       }       if (a <= f1 && f1 <= b) {         cout << abs(t1 - t2) + abs(f1 - f2) << endl;         continue;       }       long long int temp;       if (abs(f1 - a) <= abs(f1 - b)) {         temp = a;         ans = abs(f1 - a);       } else {         temp = b;         ans = abs(f1 - b);       }       ans = ans + abs(t1 - t2) + abs(temp - f2);       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using pii = pair<int, int>;   constexpr auto MOD = 1000000007LL;   constexpr auto LINF = (1LL << 60);   constexpr auto INF = 2147483647LL;   constexpr auto PI = 3.1415926535897932384626433;   constexpr auto EPS = 1E-9;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> p) {     out << p.first <<     << p.second;     return out;   }   template <typename T1, typename T2>   istream &operator>>(istream &in, pair<T1, T2> &p) {     in >> p.first >> p.second;     return in;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &x : v) in >> x;     return in;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> v) {     for (int i = 0; i < v.size(); i++)       out << v[i] << (i + 1 == v.size() ?   n  :    );     out.flush();     return out;   }   struct Node {     int l, r;     int emp;     ll end;     Node() {}   } T[1000010 << 2];   void maintain(int id) {     ll ext = max(0LL, T[id << 1].end - T[id << 1 | 1].l);     T[id].emp = T[id << 1].emp + max(0LL, T[id << 1 | 1].emp - ext) +                 max(0LL, T[id << 1 | 1].l - T[id << 1].end);     T[id].end = max(0LL, ext - T[id << 1 | 1].emp) + T[id << 1 | 1].end;     return;   }   void build(int id = 1, int l = 0, int r = 1e6) {     T[id].l = l;     T[id].r = r;     T[id].emp = 0;     T[id].end = l;     if (l + 1 == r) {       return;     }     build(id << 1, l, l + r >> 1);     build(id << 1 | 1, l + r >> 1, r);     return;   }   void add(int t, int d, int id = 1, int l = 0, int r = 1e6) {     if (t >= r || l > t) return;     if (l + 1 == r) {       T[id].emp = 0;       T[id].end = t + d;       return;     }     add(t, d, id << 1, l, l + r >> 1);     add(t, d, id << 1 | 1, l + r >> 1, r);     maintain(id);     return;   }   void rem(int t, int id = 1, int l = 0, int r = 1e6) {     if (t >= r || l > t) return;     if (l + 1 == r) {       T[id].emp = 0;       T[id].end = l;       return;     }     rem(t, id << 1, l, l + r >> 1);     rem(t, id << 1 | 1, l + r >> 1, r);     maintain(id);     return;   }   void ask(int t, ll &res, int id = 1, int l = 0, int r = 1e6) {     if (l > t) return;     if (t + 1 >= r) {       ll ext = max(0LL, res - T[id].l);       ext = max(0LL, ext - T[id].emp);       res = T[id].end + ext;       return;     }     ask(t, res, id << 1, l, l + r >> 1);     ask(t, res, id << 1 | 1, l + r >> 1, r);     return;   }   int records[300010];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     build();     string op;     for (int i = 1; i <= n; i++) {       cin >> op;       if (op ==  ? ) {         int t;         ll res = -1;         cin >> t;         --t;         ask(t, res);         cout << max(0LL, res - t) << endl;       } else if (op ==  + ) {         int d;         cin >> records[i] >> d;         --records[i];         add(records[i], d);       } else if (op ==  - ) {         int id;         cin >> id;         rem(records[id]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010, mod = 1e9 + 7;   int i, j, k, n, m, y, e;   long long ans = 1, a[maxn];   int main() {     a[0] = 1;     a[1] = 1;     cin >> n;     for (i = 2; i <= n; i++) a[i] = (a[i - 2] * (i - 1) + a[i - 1]) % mod;     for (i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       if (x == 1)         y++;       else         e++;     }     for (i = n; e; i--, e--) {       ans *= i;       ans %= mod;     }     cout << ans * a[y] % mod << endl;   }