malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   long double scal(long double x, long double y, long double x1, long double y1) {     return x * y1 - x1 * y;   }   int n, m;   int a[20][2], b[20][2];   int aa[20][10], bb[20][10];   int p[10];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];     for (int i = 0; i < m; i++) cin >> b[i][0] >> b[i][1];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if ((a[i][0] == b[j][0] && a[i][1] == b[j][1]) ||             (a[i][1] == b[j][0] && a[i][0] == b[j][1]))           continue;         if (a[i][0] == b[j][0]) {           aa[i][a[i][0]] = 1;           bb[j][a[i][0]] = 1;         }         if (a[i][0] == b[j][1]) {           aa[i][a[i][0]] = 1;           bb[j][a[i][0]] = 1;         }         if (a[i][1] == b[j][1]) {           aa[i][a[i][1]] = 1;           bb[j][a[i][1]] = 1;         }         if (a[i][1] == b[j][0]) {           aa[i][a[i][1]] = 1;           bb[j][a[i][1]] = 1;         }       }     }     for (int i = 0; i < n; i++)       for (int j = 1; j <= 9; j++)         if (aa[i][j] == 1) p[j] = 1;     int anss = 0;     for (int i = 1; i <= 9; i++) anss += p[i];     if (anss == 1) {       for (int i = 1; i <= 9; i++)         if (p[i]) cout << i;       return 0;     }     int ans1 = 1, ans2 = 1;     for (int i = 0; i < n; i++) {       int t = 0;       for (int j = 1; j <= 9; j++) t += aa[i][j];       if (t > 1) ans1 = 0;     }     for (int i = 0; i < m; i++) {       int t = 0;       for (int j = 1; j <= 9; j++) t += bb[i][j];       if (t > 1) ans2 = 0;     }     if (ans1 && ans2)       cout << 0;     else       cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   int n, p, k;   int a[333333];   long long ans;   map<int, int> mp, mpb;   int main() {     scanf( %d%d%d , &n, &p, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       mp[a[i]]++;     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       if (1ll * ((it->first) + (it->first)) *               (2ll * (it->first) * (it->first) % p) % p !=           k)         ans -= (1ll * (it->second) * ((it->second) - 1));     }     for (int i = 1; i <= n; i++) {       mpb[((1ll * a[i] * a[i] % p * a[i] % p * a[i] - 1ll * k * a[i]) % p + p) %           p]++;     }     for (map<int, int>::iterator it = mpb.begin(); it != mpb.end(); it++) {       ans += (1ll * (it->second) * ((it->second) - 1));     }     printf( %lld n , ans / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i % 2 == 0) {           if (j % 2 == 0) {             cout <<  W ;           } else {             cout <<  B ;           }         } else {           if (j % 2 != 0) {             cout <<  W ;           } else {             cout <<  B ;           }         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int first, second;     cin >> second >> first;     if ((second == 1 && first == 0) || first == 0) {       cout <<  NO ;       return 0;     } else if (first == 1 && second == 0) {       cout <<  YES ;       return 0;     }     int tot = first;     int co = first - 1;     if (first == 1 && second >= 0) {       cout <<  NO ;       return 0;     }     if ((second - co) % 2 == 0 && (second - co) >= 0)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, k, lb, ub, ans = -1;   int main() {     long long l, r;     scanf( %lld%lld%lld%lld , &n, &l, &r, &k);     x = (r >= l ? r - l + 1 : r + n - l + 1) % n;     for (long long i = k, j, r; i; i = j) {       j = k / (k / i + 1);       r = k / i;       ub = min(2 * n, i);       lb = max(n, j + 1);       ub = min(ub, min((2 * n + k - 2 * x + 1) / (r + 1), (k - x) / r));       lb = max(lb, (k - 2 * x + r - 1) / r);       if (ub >= lb) ans = max(ans, ub);     }     if (x <= k && k <= x * 2) ans = max(ans, n + min(k - x, x - 1) + n - x + 1);     if (!x && k == n) ans = max(ans, n + 1);     printf( %lld n , ~ans ? ans - n : ans);   }
#include <bits/stdc++.h>   using namespace std;   char p[][20] = { vaporeon ,  jolteon ,  flareon ,  espeon ,                    umbreon ,   leafeon ,  glaceon ,  sylveon };   char s[20];   int main() {     int n, k, i;     scanf( %d , &n);     scanf( %s , s);     for (k = 0; k < 8; k++) {       int fl = 1;       for (i = 0; fl && i < n; i++) {         if (p[k][i] ==   0  || (p[k][i] != s[i] && s[i] !=  . )) fl = 0;       }       if (fl && p[k][i] ==   0 ) printf( %s n , p[k]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double epsilon = 1e-9;   int main() {     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     vector<pair<int, int> > moves;     for (int i = 0; i < n; i++) {       if (b[i] != a[i]) {         for (int j = i + 1; j < n; j++) {           if (b[j] == a[i]) {             for (int k = j; k > i; k--) {               moves.push_back(make_pair(k - 1, k));               swap(b[k], b[k - 1]);             }             break;           }         }       }     }     cout << moves.size() << endl;     for (int i = 0; i < moves.size(); i++)       cout << moves[i].first + 1 <<     << moves[i].second + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a, b, c, d, e, first;     cin >> a >> b >> c >> d >> e >> first;     b = min(c, b);     if (d < a && d < b)       cout << d * max(e, first);     else {       long long p = min(a, d) * e + min(d - min(d, a), b) * first;       long long q = min(b, d) * first + min(d - min(d, b), a) * e;       cout << max(p, q);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n;     cin >> n;     string s;     cin >> s;     for (long long i = 0; i < n - 1; i++) {       if (s[i] > s[i + 1]) {         cout <<  YES  << endl;         cout << i + 1 <<     << i + 2 << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 21;   int a[1 << maxn], n;   long long ans[maxn][2];   void mergesort(int l, int r, int dep) {     if (r - l <= 1) return;     int m = (l + r) / 2;     mergesort(l, m, dep - 1);     mergesort(m, r, dep - 1);     for (int i = l; i < m; i++) {       ans[dep][0] += lower_bound(a + m, a + r, a[i]) - a - m;     }     for (int i = m; i < r; i++) {       ans[dep][1] += lower_bound(a + l, a + m, a[i]) - a - l;     }     inplace_merge(a + l, a + m, a + r);   }   long long solve(int q) {     long long res = 0;     while (q) swap(ans[q][0], ans[q][1]), q--;     for (int i = 1; i <= n; i++) {       res += ans[i][0];     }     return res;   }   int main() {     int m, q;     cin >> n;     for (int i = 0; i < 1 << n; i++) scanf( %d , &a[i]);     cin >> m;     mergesort(0, 1 << n, n);     for (int i = 0; i < m; i++) {       scanf( %d , &q);       cout << solve(q) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const long long inf = (((long long)1) << 61) + 5;   const int N = 100005;   int f[N];   int g[N];   int a[N];   int bit[N];   int ans[N];   int sum1(int x) {     int ans = 0;     for (int i = x; i > 0; i -= i & -i) ans = max(bit[i], ans);     return ans;   }   void add1(int x, int val) {     for (int i = x; i <= N; i += i & -i) bit[i] = max(bit[i], val);   }   int sum2(int x) {     int ans = 0;     for (int i = x; i <= N; i += i & -i) ans = max(bit[i], ans);     return ans;   }   void add2(int x, int val) {     for (int i = x; i > 0; i -= i & -i) bit[i] = max(bit[i], val);   }   int main() {     int n, res = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       int x = sum1(a[i] - 1);       f[i] = x + 1;       if (f[i] > res) res = f[i];       add1(a[i], f[i]);     }     memset(bit, 0, sizeof bit);     for (int i = n; i >= 1; i--) {       int x = sum2(a[i] + 1);       g[i] = x + 1;       add2(a[i], g[i]);     }     vector<int> q[N];     for (int i = 1; i <= n; i++) {       if (f[i] + g[i] - 1 < res)         ans[i] = 1;       else         q[f[i]].push_back(i);     }     for (int i = 1; i <= res; i++) {       int sz = q[i].size();       for (int j = 0; j < sz; j++) {         int v = q[i][j];         if (sz == 1)           ans[v] = 3;         else           ans[v] = 2;       }     }     for (int i = 1; i <= n; i++) printf( %d , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   template <typename T>   inline void read(T &x) {     x = 0;     T fl = 1;     char ch = 0;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) fl = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 1) + (x << 3) + (ch ^ 48);     x *= fl;   }   template <typename T, typename... Args>   inline void read(T &x, Args &...args) {     read(x);     read(args...);   }   const int N = 1e5 + 5;   struct data {     int s, m, r, t;     data(int x = 0) { t = x; }     bool operator<(const data &b) const { return t < b.t; }     long long calc(long long tim) { return min(s + tim * r, m * 1ll); }   } a[18][N];   struct seg {     int trt[N << 2];     long long trm[18][N << 2], trr[18][N << 2];     void pushdown(int nod) {       if (trt[nod] >= 0) trt[(nod << 1)] = trt[(nod << 1 | 1)] = trt[nod];     }     void pushup(int nod) {       if (trt[(nod << 1)] != trt[(nod << 1 | 1)])         trt[nod] = -1;       else         trt[nod] = trt[(nod << 1)];     }     void build(int nod, int l, int r, int dep) {       trt[nod] = -2;       if (l == r) {         read(a[dep][l].s, a[dep][l].m, a[dep][l].r);         if (a[dep][l].r == 0)           a[dep][l].t = inf;         else           a[dep][l].t = a[dep][l].m % a[dep][l].r == 0                             ? a[dep][l].m / a[dep][l].r                             : a[dep][l].m / a[dep][l].r + 1;         trm[dep][l] = trm[dep][l - 1] + a[dep][l].m;         trr[dep][l] = trr[dep][l - 1] + a[dep][l].r;         return;       }       int mid = (l + r) >> 1;       build((nod << 1), l, mid, dep + 1);       build((nod << 1 | 1), mid + 1, r, dep + 1);       for (int i = (l); i <= (r); i++) a[dep][i] = a[dep + 1][i];       sort(a[dep] + l, a[dep] + r + 1);       for (int i = (l); i <= (r); i++) {         trm[dep][i] = trm[dep][i - 1] + a[dep][i].m;         trr[dep][i] = trr[dep][i - 1] + a[dep][i].r;       }     }     long long query(int tim, int nod, int l, int r, int ql, int qr, int dep) {       long long res = 0;       if (ql <= l && r <= qr && trt[nod] != -1) {         if (trt[nod] == -2)           for (int i = (l); i <= (r); i++) res += a[dep][i].calc(tim);         else {           int i = upper_bound(a[dep] + l, a[dep] + 1 + r, data(tim - trt[nod])) -                   a[dep] - 1;           res = (tim - trt[nod]) * (trr[dep][r] - trr[dep][i]) + trm[dep][i] -                 trm[dep][l - 1];         }         trt[nod] = tim;         return res;       }       pushdown(nod);       int mid = (l + r) >> 1;       if (ql <= mid) res += query(tim, (nod << 1), l, mid, ql, qr, dep + 1);       if (qr > mid)         res += query(tim, (nod << 1 | 1), mid + 1, r, ql, qr, dep + 1);       pushup(nod);       return res;     }   } sgt;   int n, m;   int main() {     read(n);     sgt.build(1, 1, n, 0);     read(m);     for (int _ = (1); _ <= (m); _++) {       int t, l, r;       read(t);       read(l);       read(r);       printf( %lld n , sgt.query(t, 1, 1, n, l, r, 0));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, i, j, n, aux, cnt, ans, div1[10000010], v[10000010];   int main() {     cin >> a >> n;     v[1] = 1;     for (i = 3; i * i <= a + n - 1; i += 2)       if (!div1[i]) {         div1[i] = i;         for (j = i * i; j <= a + n - 1; j += 2 * i) div1[j] = i;       }     for (i = 2; i <= a + n - 1; i += 2) div1[i] = 2;     for (i = 2; i <= a + n - 1; i++) {       aux = i;       cnt = 0;       if (!div1[i]) div1[i] = i;       while (aux % div1[i] == 0) aux /= div1[i], cnt++;       v[i] = v[aux];       if (cnt & 1) v[i] *= div1[i];     }     for (i = a; i <= a + n - 1; i++) ans += v[i];     cout << ans;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   vector<long long> v;   unordered_map<long long, long long> m;   long long falla(long long n) {     if (m.count(n)) {       return m[n];     }     long long ans;     long long k = 0;     for (int j = n - 1; j >= 1; j--) {       if (n % j == 0) {         ans = j;         break;       }       if (n % (n - j + 1) == 0) {         ans = n / (n - j + 1);         break;       }     }     m[ans] = ans;     return ans;   }   int main() {     long long casos;     cin >> casos;     long long num = pow(2, 25) - 1;     for (int i = 1; i < 30; i++) {       v.push_back((1 << i) - 1);     }     long long flag = 0;     while (casos--) {       long long num;       long long ans1;       cin >> num;       if (m.count(num)) {         cout << m[num] << endl;         flag = 1;       }       if (flag == 0) {         ans1 = lower_bound((v).begin(), (v).end(), num) - v.begin();         if (num == v[ans1]) {           ans1 = falla(num);           m[num] = ans1;           cout << ans1 << endl;         } else {           m[num] = v[ans1];           cout << v[ans1] << endl;         }       }       flag = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   long long dp[200005][2];   bool vst[200005][2];   long long A[200005], n;   long long go(long long v, bool b) {     if (vst[v][b]) return dp[v][b];     vst[v][b] = true;     long long val = 0;     if (!b) {       if ((v - A[v]) > 1)         val = go(v - A[v], b ^ 1);       else if ((v - A[v]) == 1)         val = -1;     } else {       if ((v + A[v]) <= n) val = go(v + A[v], b ^ 1);     }     if (val != -1)       dp[v][b] = A[v] + val;     else       dp[v][b] = -1;     return dp[v][b];   }   int main() {     long long i;     cin >> n;     for (i = (2); i <= (n); i++) {       cin >> A[i];     }     memset((vst), (0), sizeof(vst));     long long j;     memset((dp), (-1), sizeof(dp));     for (i = (2); i <= (n); i++) {       go(i, 0);       if (dp[i][0] != -1)         cout << dp[i][0] + i - 1 << endl;       else         cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const double Pi = 3.1415926535897932;   const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};   const int maxn = 1e4 + 5;   struct EDGE {     int a, b;     int A, B;   } edge[maxn];   int n, m;   int last[maxn];   vector<int> G[maxn], tree[maxn];   int d[maxn];   int A[maxn], B[maxn];   bool vis[maxn];   vector<int> ans;   int in[maxn];   void dfs_tree(int a, int fa) {     vis[a] = true;     for (int i = 0; i < G[a].size(); i++) {       int p = G[a][i];       if (p == last[a]) continue;       int b = edge[p].a ^ edge[p].b ^ a;       if (!vis[b]) {         tree[a].push_back(p);         in[p] = true;         d[b] = d[a] + 1;         last[b] = p;         dfs_tree(b, a);       } else if (d[a] > d[b]) {         if (d[a] - d[b] + 1 & 1) {           ans.push_back(p);           B[a]++;           B[b]--;         } else {           A[a]++;           A[b]--;         }       }     }   }   void dfs(int a) {     vis[a] = true;     for (int i = 0; i < tree[a].size(); i++) {       int p = tree[a][i];       int b = edge[p].a ^ edge[p].b ^ a;       if (!vis[b]) dfs(b);       A[a] += A[b];       B[a] += B[b];     }     edge[last[a]].A = A[a];     edge[last[a]].B = B[a];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       edge[i] = EDGE{a, b};       G[a].push_back(i);       G[b].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) dfs_tree(i, -1);     }     memset(vis, false, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (!vis[i]) dfs(i);     }     if (ans.size() == 0) {       for (int i = 1; i <= m; i++) ans.push_back(i);     } else if (ans.size() == 1) {       for (int i = 1; i <= m; i++)         if (in[i]) {           if (edge[i].A == 0 && edge[i].B) ans.push_back(i);         }     } else {       int t = ans.size();       ans.clear();       for (int i = 1; i <= m; i++)         if (in[i]) {           if (edge[i].B) {             if (edge[i].B == t && edge[i].A == 0) ans.push_back(i);           }         }     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++)       printf( %d , ans[i]), putchar(i == ans.size() - 1 ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> a[200];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].second;       long long tmp = a[i].second;       while (tmp % 3 == 0) {         a[i].first--;         tmp /= 3;       }     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) cout << a[i].second <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long arr[3];     scanf( %I64d%I64d%I64d , &arr[0], &arr[1], &arr[2]);     sort(arr, arr + 3);     if (arr[0] == arr[1] && arr[1] == arr[2])       printf( 0 n );     else if (arr[2] == arr[1] && arr[1] > arr[0]) {       printf( %I64d n , arr[2] - arr[0] - 1);     } else if (arr[2] > arr[1] && arr[1] == arr[0]) {       printf( %I64d n , (arr[2] - arr[1] - 1) + (arr[2] - arr[0] - 1));     } else if (arr[2] > arr[1] && arr[1] > arr[0]) {       printf( %I64d n , (arr[2] - arr[1] - 1) + (arr[2] - arr[0] - 1));     }   }
#include <bits/stdc++.h>   using namespace std;   long long const modul = 1;   long long mod_sum(long long x, long long y) { return (x + y) % modul; }   long long mod_sub(long long x, long long y) {     if (x > y) {       return (x - y) % modul;     } else {       return (modul + x - y) % modul;     }   }   long long mod_mpl(long long x, long long y) { return (x * y) % modul; }   void set_precise(int n) {     cout << fixed;     cout << setprecision(n);   }   int const N = 200000;   class Tree {    private:     long long tree[N * 4];     int start;     int size;     void rebuild(int id) {       if (id < 1) {         return;       }       tree[id] = tree[id * 2] + tree[id * 2 + 1];       rebuild(id / 2);     };     long long count_sum(int cur, int left, int right, int cur_l, int cur_r) {       int mid = (cur_l + cur_r) / 2;       if ((left == cur_l) && (right == cur_r)) {         return tree[cur];       }       if (right <= mid) {         return count_sum(cur * 2, left, right, cur_l, mid);       } else if (left >= mid + 1) {         return count_sum(cur * 2 + 1, left, right, mid + 1, cur_r);       } else {         return count_sum(cur * 2, left, mid, cur_l, mid) +                count_sum(cur * 2 + 1, mid + 1, right, mid + 1, cur_r);       }     };       public:     Tree() {       size = 0;       start = 0;     };     void initialize(int n) {       int cur = 1;       int sum = 0;       while (cur < n) {         sum += cur;         cur *= 2;       }       start = sum + 1;       size = cur;       for (int i = 1; i < start + cur; ++i) {         tree[i] = 0;       }     }     Tree(int n) {       int cur = 1;       int sum = 0;       while (cur < n) {         sum += cur;         cur *= 2;       }       start = sum + 1;       size = cur;       for (int i = 1; i < start + cur; ++i) {         tree[i] = 0;       }     };     void update(int pos, long long q, long long no_more) {       long long cur = tree[start + pos];       cur += q;       if (cur > no_more) {         cur = no_more;       }       tree[start + pos] = cur;       rebuild((start + pos) / 2);     };     long long get_sum(int left, int right) {       if (left > right) {         return 0;       }       return count_sum(1, left, right, 0, size - 1);     }   };   Tree max_a;   Tree max_b;   int main() {     int n, k;     long long a, b;     int q;     cin >> n >> k >> a >> b >> q;     max_a.initialize(n);     max_b.initialize(n);     for (int i = 0; i < q; ++i) {       int type;       cin >> type;       if (type == 1) {         int day;         long long x;         cin >> day >> x;         --day;         max_a.update(day, x, a);         max_b.update(day, x, b);       } else {         int p;         cin >> p;         --p;         long long ans = 0;         ans += max_b.get_sum(0, p - 1);         ans += max_a.get_sum(p + k, n - 1);         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void sove() {}   int main() {     int n;     cin >> n;     int nums[n];     for (int i = 0; i < n; ++i) {       cin >> nums[i];     }     for (int i = 0; i < n / 2; i += 2) {       int temp = nums[i];       nums[i] = nums[n - i - 1];       nums[n - i - 1] = temp;     }     for (int num : nums) {       cout << num <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   vector<int> e[maxn];   int dp[maxn], root[maxn], d[maxn], sz[maxn];   pair<int, int> dfs(int v, int st, int par) {     if (root[v] == -1) sz[st]++;     root[v] = st;     pair<int, int> p = make_pair(0, -1);     for (int i = 0; i < e[v].size(); i++)       if (e[v][i] != par) p = max(p, dfs(e[v][i], st, v));     if (par != -1) p.first++;     if (p.second == -1) p.second = v;     return p;   }   int get_root(int v) { return root[v] == v ? v : root[v] = get_root(root[v]); }   void merge(int v, int u) {     v = get_root(v);     u = get_root(u);     if (sz[v] > sz[u]) swap(v, u);     if (v == u) return;     root[v] = u;     sz[u] += sz[v];     d[u] = max((d[v] + 1) / 2 + (d[u] + 1) / 2 + 1, max(d[v], d[u]));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m, q;     cin >> n >> m >> q;     memset(root, -1, sizeof root);     for (int i = 0; i < m; i++) {       int u, v;       cin >> v >> u;       v--;       u--;       e[v].push_back(u);       e[u].push_back(v);     }     for (int i = 0; i < n; i++)       if (root[i] == -1) d[i] = dfs(dfs(i, i, -1).second, i, -1).first;     for (int i = 0; i < q; i++) {       int t;       cin >> t;       if (t == 1) {         int x;         cin >> x;         x--;         cout << d[get_root(x)] <<   n ;       } else {         int x, y;         cin >> x >> y;         x--;         y--;         merge(x, y);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     t = 1;     for (long long int _ = 0; _ < t; _++) {       long long int n, m, b, mod;       cin >> n >> m >> b >> mod;       vector<long long int> v(n + 1);       for (long long int i = 1; i <= n; i++) cin >> v[i];       long long int dp[2][m + 1][b + 1];       for (long long int i = 0; i <= 1; i++) {         for (long long int j = 0; j <= m; j++) {           for (long long int k = 0; k <= b; k++) dp[i][j][k] = 0;         }       }       dp[0][0][0] = 1;       for (long long int i = 1; i <= n; i++) {         for (long long int j = 0; j <= m; j++) {           for (long long int k = 0; k <= b; k++) {             if (k >= v[i] && j > 0)               dp[i % 2][j][k] =                   (dp[1 - (i % 2)][j][k] + dp[i % 2][j - 1][k - v[i]]) % mod;             else               dp[i % 2][j][k] = dp[1 - (i % 2)][j][k];           }         }       }       long long int ans = 0;       for (long long int k = 0; k <= b; k++) ans = (ans + dp[n % 2][m][k]) % mod;       cout << ans <<   n ;     }     return 0;   }