malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   void initialize(int *arr, int length) {     for (int i = 0; i < length; i++) arr[i] = 0;   }   int teams(int *arr, int length) {     for (int i = 1; i < length; i++) {       if (arr[i - 1] == 1 && arr[i] == 1) return 2;     }     return 1;   }   int main() {     int queries, len, curr, sieve[100];     scanf( %d n , &queries);     for (int i = 0; i < queries; i++) {       initialize(sieve, 100);       scanf( %d n , &len);       for (int j = 0; j < len; j++) {         scanf( %d , &curr);         sieve[curr - 1] = 1;       }       scanf(  n );       printf( %d n , teams(sieve, 100));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T_container, typename T = typename enable_if<                                       !is_same<T_container, string>::value,                                       typename T_container::value_type>::type>   ostream &operator<<(ostream &os, const T_container &v) {     string sep;     for (const T &x : v) os << sep << x, sep =    ;     return os;   }   const int mxN = 12, oo = 1e9;   bool g[12][12], used[13];   long long ans = 0;   int n = 12, k;   int a[12];   bool pused[6];   bool goodr(int i = 0, int d = 0) {     if (d == n - 2) return g[a[i]][a[i + 1]];     for (int to = 0; to < n; to += 2)       if (!pused[to]) {         if ((g[a[i]][a[to]] and g[a[i + 1]][a[to + 1]]) or             (g[a[i]][a[to + 1]] and g[a[i + 1]][a[to]])) {           pused[to] = true;           if (goodr(to, d + 2)) {             pused[to] = false;             return true;           }           pused[to] = false;         }       }     return false;   }   bool good() {     for (int i = 0; i < n; i += 2) {       pused[i] = true;       if (goodr(i)) {         pused[i] = false;         return true;       }       pused[i] = false;     }     return false;   }   set<array<char, 12>> s;   int eq = 0;   array<char, 12> equiv, mp, reale;   void normalize() {     fill(begin(mp), end(mp), -1);     int t = 0;     for (int i = 0; i < n; ++i) {       if (mp[equiv[i]] == -1) mp[equiv[i]] = t++;       reale[i] = mp[equiv[i]];     }   }   void rec2(int i = 0) {     if (i == n) {       normalize();       if (eq > k) return;       if (!s.count(reale)) {         int cur = 1;         for (int j = k - eq + 1; j <= k; ++j) {           cur *= j;         }         ans += cur;         s.insert(reale);       }       return;     }     equiv[a[i]] = eq;     equiv[a[i + 1]] = eq;     eq++;     rec2(i + 2);     eq--;     for (int j = 0; j < eq; ++j) {       equiv[a[i]] = j;       equiv[a[i + 1]] = j;       rec2(i + 2);     }   }   void rec(int i, int d = 0) {     while (used[i]) ++i;     if (i == n) {       if (good()) {         rec2();       }       return;     }     used[i] = true;     for (int j = i + 1; j < n; ++j)       if (!used[j]) {         used[j] = true;         a[d] = i;         a[d + 1] = j;         rec(i + 1, d + 2);         used[j] = false;       }     used[i] = false;   }   int main() {     int m;     cin >> n >> m >> k;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v, --u, --v;       g[u][v] = true;       g[v][u] = true;     }     rec(0);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       vector<int> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];       }       int i;       bool poss = 1;       for (i = 0; i < n; i++)         if (v[i] < i) break;       i--;       for (int j = i; j < n - 1; j++) {         if (v[j + 1] >= v[j]) v[j + 1] = v[j] - 1;         if (v[j + 1] < 0) {           poss = 0;           break;         }       }       if (poss)         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 998244353;   int main() {     ios_base::sync_with_stdio(false);     long long r, s, p;     cin >> r >> s >> p;     double dp[r + 1][s + 1][p + 1];     int visited[r + 1][s + 1][p + 1];     for (int i = 0; i < r + 1; i++) {       for (int j = 0; j < s + 1; j++) {         for (int k = 0; k < p + 1; k++) {           dp[i][j][k] = 0;           visited[i][j][k] = 0;         }       }     }     dp[r][s][p] = 1;     visited[r][s][p] = 1;     queue<pair<pair<double, double>, double> > q;     q.push(make_pair(make_pair(r, s), p));     while (!q.empty()) {       int sz = q.size();       for (int i = 0; i < sz; i++) {         pair<pair<double, double>, double> curp = q.front();         q.pop();         double rr = curp.first.first;         double ss = curp.first.second;         double rp = curp.second;         if ((int)rr > 0 && (int)ss > 0) {           dp[(int)rr][(int)ss - 1][(int)rp] +=               dp[(int)rr][(int)ss][(int)rp] *               (((rr * ss)) / ((rr * ss + rp * rr + ss * rp)));           if (visited[(int)rr][(int)ss - 1][(int)rp] == 0) {             q.push(make_pair(make_pair(rr, ss - 1), rp));             visited[(int)rr][(int)ss - 1][(int)rp] = 1;           }         }         if ((int)rr > 0 && (int)rp > 0) {           dp[(int)rr - 1][(int)ss][(int)rp] +=               dp[(int)rr][(int)ss][(int)rp] *               (((rr * rp)) / ((rr * ss + rp * rr + ss * rp)));           if (visited[(int)rr - 1][(int)ss][(int)rp] == 0) {             q.push(make_pair(make_pair(rr - 1, ss), rp));             visited[(int)rr - 1][(int)ss][(int)rp] = 1;           }         }         if ((int)rp > 0 && (int)ss > 0) {           dp[(int)rr][(int)ss][(int)rp - 1] +=               dp[(int)rr][(int)ss][(int)rp] *               (((rp * ss)) / ((rr * ss + rp * rr + ss * rp)));           if (visited[(int)rr][(int)ss][(int)rp - 1] == 0) {             q.push(make_pair(make_pair(rr, ss), rp - 1));             visited[(int)rr][(int)ss][(int)rp - 1] = 1;           }         }       }     }     double ans1, ans2, ans3;     ans1 = ans2 = ans3 = 0;     for (int i = 1; i <= r; i++) {       ans1 += dp[i][0][0];     }     for (int i = 1; i <= s; i++) {       ans2 += dp[0][i][0];     }     for (int i = 1; i <= p; i++) {       ans3 += dp[0][0][i];     }     std::cout << std::setprecision(9) << ans1 <<     << ans2 <<     << ans3;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int a[4]{0};       int i, j, k, ans, min1 = 0, min2 = 0;       for (i = 0; i < s.size(); i++) {         if (s[i] ==  L ) a[0]++;         if (s[i] ==  R ) a[1]++;         if (s[i] ==  U ) a[2]++;         if (s[i] ==  D ) a[3]++;       }       min1 = min(a[0], a[1]);       min2 = min(a[2], a[3]);       if (min1 >= 1 && min2 == 0) {         cout <<  2  << endl;         cout <<  LR ;       } else if (min1 == 0 && min2 >= 1) {         cout <<  2  << endl;         cout <<  UD ;       } else {         string b(2 * (min1 + min2),  1 );         for (i = 0; i < 2 * (min1 + min2); i++) {           if (i < min1)             b[i] =  R ;           else if (i >= min1 + min2 && i < (2 * min1 + min2))             b[i] =  L ;           else if (i >= (2 * min1 + min2))             b[i] =  U ;           else             b[i] =  D ;         }         cout << b.size() << endl;         cout << b;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int e, s, n, m;   vector<int> comp;   vector<pair<int, int> > has;   vector<int> all, butR, onlyS;   int query[200013];   int id(int x) {     return lower_bound(comp.begin(), comp.end(), x) - comp.begin();   }   vector<int> cover(int use) {     vector<int> res(comp.size());     for (auto i : has)       if (i.second >= use) {         res[id(i.first)] += 1;         res[id(i.first + s)] -= 1;       }     int prev = 0;     for (int& i : res) i += prev, prev = i;     for (int i = 0; i < res.size() - 1; i++) {       if (res[i]) res[i] = comp[i + 1] - comp[i];     }     prev = 0;     for (int& i : res) i += prev, prev = i;     return res;   }   bool test(vector<int>& vec, int ind) {     return ind != 0 && vec[ind] > vec[ind - 1];   }   pair<int, int> solve(int f) {     if (f + s >= e) return make_pair(0, 0);     f += s;     int eAt = id(e) - 1, fAt = id(f) - 1;     if (all[eAt] - all[fAt] != e - f) return make_pair(-1, -1);     int needR = (e - f) - (butR[eAt] - butR[fAt]);     int needP = (e - f) - (onlyS[eAt] - onlyS[fAt]) - needR;     return make_pair(needR, needP);   }   int main() {     scanf( %d%d%d%d , &e, &s, &n, &m);     comp.push_back(e);     comp.push_back(-1.01e9);     for (int i = 0; i < n; i++) {       int t, x;       scanf( %d%d , &t, &x);       if (x >= e) continue;       has.push_back(make_pair(x, t));       comp.push_back(x);       comp.push_back(x + s);     }     for (int i = 0; i < m; i++) {       scanf( %d , &query[i]);       comp.push_back(query[i]);       comp.push_back(query[i] + s);     }     sort(comp.begin(), comp.end());     comp.erase(unique(comp.begin(), comp.end()), comp.end());     all = cover(1);     butR = cover(2);     onlyS = cover(3);     for (int i = 0; i < m; i++) {       pair<int, int> ans = solve(query[i]);       printf( %d %d n , ans.first, ans.second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     int found;     string s =  +------------------------+ ;     string r1 =  |#.#.#.#.#.#.#.#.#.#.#.|D|) ;     string r2 =  |#.#.#.#.#.#.#.#.#.#.#.|.| ;     string r3 =  |#.......................| ;     string r4 =  |#.#.#.#.#.#.#.#.#.#.#.|.|) ;     for (int i = 1; i <= k; i++) {       found = 0;       for (int j = 1; j <= 21 && !found; j += 2) {         if (r1[j] ==  # ) {           r1[j] =  O ;           found = 1;         } else if (r2[j] ==  # ) {           r2[j] =  O ;           found = 1;         } else if (r3[j] ==  # ) {           r3[j] =  O ;           found = 1;         } else if (r4[j] ==  # ) {           r4[j] =  O ;           found = 1;         }       }     }     cout << s << endl          << r1 << endl          << r2 << endl          << r3 << endl          << r4 << endl          << s << endl;   }
#include <bits/stdc++.h>   const int N = 22;   const int M = (1 << 22);   const int INF = 0x3f3f3f3f;   bool dp[M] = {0};   int neib[N] = {0}, ex[M] = {0};   int main() {     int m, n, u, v;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       neib[i] = (1 << i);       dp[1 << i] = true;     }     for (int i = 0; i < m; ++i) {       scanf( %d%d , &u, &v);       --u;       --v;       dp[(1 << u) | (1 << v)] = true;       neib[u] |= (1 << v);       neib[v] |= (1 << u);     }     if (n == 1 || m == n * (n - 1) / 2) {       printf( 0 n );       return 0;     }     for (int i = 0; i < (1 << n); ++i)       if (dp[i]) {         for (int j = 0; j < n; ++j)           if (i & (1 << j)) {             ex[i] |= neib[j];           }         for (int j = 0; j < n; ++j)           if (ex[i] & (1 << j)) {             dp[i | (1 << j)] = true;           }       }     int best = INF;     std::vector<int> ans;     for (int i = 0; i < (1 << n); ++i)       if (dp[i] && ex[i] == (1 << n) - 1) {         int cnt = 0;         for (int j = 0; j < n; ++j)           if (i & (1 << j)) ++cnt;         if (cnt >= best) continue;         best = cnt;         ans.clear();         for (int j = 0; j < n; ++j)           if (i & (1 << j)) ans.push_back(j);       }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i] + 1);     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   set<int> s[100001];   int a[100001];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       s[x].insert(y);       s[y].insert(x);     }     srand(time(0));     for (int op = 1; op <= 200; op++) {       for (int i = 1; i <= n; i++) a[i] = i;       random_shuffle(a + 1, a + n + 1);       a[n + 1] = a[1];       int i;       for (i = 1; i <= m; i++) {         if (s[a[i]].count(a[i + 1])) break;       }       if (i == m + 1) {         for (i = 1; i <= m; i++) cout << a[i] <<     << a[i + 1] << endl;         return 0;       }     }     cout << -1;     return 0;   }
// BY : VIDIT BHARDWAJ   #include<bits/stdc++.h>   using namespace std;      #define int                 long long int   #define ff                  first   #define ss                  second   #define pb                  push_back   #define popb                pop_back   #define lb                  lower_bound   #define ub                  upper_bound   #define all(v)              (v).begin(),(v).end()   #define tc(t)               int t; cin>>t; while(t--)   #define pii                 pair<int,int>   #define max_pq              priority_queue<int>   #define min_pq              priority_queue<int,vector<int>, greater<int> >   #define fast_ios            ios_base::sync_with_stdio(false);cin.tie(NULL);   #define ps(x,y)             fixed<<setprecision(y)<<x    #define setbits(x)          __builtin_popcountll(x)   #define zerobits(x)         __builtin_ctzll(x)   #define YES                 cout<< YES <<  n    #define NO                  cout<< NO <<  n    #define Yes                 cout<< Yes <<  n    #define No                  cout<< No <<  n    #define endl                  n               const int N=200010;   const long long mod=1000000007;   // const long long mod=998244353;   const long long inf=1000000000000000000;   const long double pi=3.14159265358979323846264338;      /*_______________________________________________________________________*/      signed main(){   #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif       fast_ios       tc(t){           string str,s; cin>>str>>s;           int n=str.size(),m=s.size();              if(n<m){            string temp=str;            str=s,s=temp;            n=str.size(),m=s.size();           }              if(s!=str.substr(0,s.size())){            cout<< -1 <<endl;            continue;           }           int it=500,yes=0;        string temp=s;        while(it>0){         if(s.size()%str.size()==0){          yes=1;          break;         }         s+=temp,it--;        }        if(yes){         temp=str;         int x=s.size()/str.size();         for(int i=1;i<x;i++){          str+=temp;         }         if(str==s) cout<<s<<endl;         else cout<< -1 <<endl;        }        else cout<< -1 <<endl;       }          return 0;   }   /*      */
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   long long a[N];   struct t {     int lval, rval, mval;   } tr[N * 4];   int sign(long long x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   inline void cal(int cur, int l, int r) {     int m = (l + r) / 2;     int dcur = cur + cur, u = dcur, v = u + 1;     tr[cur].mval = max(tr[u].mval, tr[v].mval);     tr[cur].lval = tr[u].lval;     tr[cur].rval = tr[v].rval;     if (!(!a[m] || !a[m + 1] || sign(a[m]) < sign(a[m + 1]))) {       tr[cur].mval = max(tr[cur].mval, tr[u].rval + tr[v].lval);       if (tr[dcur].mval == m - l + 1) {         tr[cur].lval = tr[u].lval + tr[v].lval;       }       if (tr[dcur + 1].mval == r - m) {         tr[cur].rval = tr[v].rval + tr[u].rval;       }     }   }   void build(int pos, int l, int r) {     if (l == r) {       int x = !!a[l];       tr[pos].lval = tr[pos].rval = tr[pos].mval = x;       return;     }     int mid = (l + r) >> 1;     build(pos * 2, l, mid);     build(pos * 2 + 1, mid + 1, r);     cal(pos, l, r);   }   void update(int pos, int l, int r, int k, int d) {     int mid = (l + r) >> 1;     if (l == r) {       a[l] += d;       int x = !!a[l];       tr[pos].lval = tr[pos].rval = tr[pos].mval = x;       return;     } else {       int mid = (l + r) >> 1;       if (k <= mid)         update(pos * 2, l, mid, k, d);       else         update(pos * 2 + 1, mid + 1, r, k, d);       cal(pos, l, r);     }   }   int main() {     int u, v, n, i, m, l, r, d;     cin >> n;     cin >> u;     for (i = 1; i < n; ++i) scanf( %d , &v), a[i - 1] = v - u, u = v;     if (n > 1) build(1, 0, n - 2);     cin >> m;     while (m--) {       scanf( %d%d%d , &l, &r, &u);       if (n == 1) {         printf( 1 n );       } else {         if (l > 1) update(1, 0, n - 2, l - 2, u);         if (r < n) update(1, 0, n - 2, r - 1, -u);         printf( %d n , tr[1].mval + 1);       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long f[5005][5005];   long long mod = 1000000007, ans = 0;   char s1[5005], s2[5005];   int main() {     scanf( %s  n %s , s1 + 1, s2 + 1);     int len1 = strlen(s1 + 1);     int len2 = strlen(s2 + 1);     for (int i = 1; i <= len1; ++i)       for (int j = 1; j <= len2; ++j) {         if (s1[i] == s2[j]) f[i][j] = (f[i - 1][j - 1] + 1) % mod;         f[i][j] = (f[i][j] + f[i][j - 1]) % mod;       }     for (int i = 1; i <= len1; ++i) ans = (ans + f[i][len2]) % mod;     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int good = 0;     int bad = 0;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s.at(i) ==  a )         good++;       else         bad++;     }     if (good > bad)       cout << s.length();     else       cout << s.length() - (bad - good) - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x[3];     cin >> x[0] >> x[1] >> x[2];     sort(x, x + 3);     cout << (x[1] - x[0]) + (x[2] - x[1]) <<   n ;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long llINF = 9223372036854775807;   const int INF = 2147483647;   const int maxn = 2e5 + 7;   const int maxm = 5e4 + 7;   const long long mod = 1e9 + 7;   const double pi = acos(-1.0);   const double eps = 1e-12;   int n;   int fa[2][maxn];   int a[maxn], b[maxn];   int u[maxn], v[maxn], w[maxn];   long long ans;   void init() {     for (int j = 0; j < 2; j++)       for (int i = 0; i < maxn; i++) fa[j][i] = i;   }   int find(int x, int idx) {     return x == fa[idx][x] ? x : fa[idx][x] = find(fa[idx][x], idx);   }   void merge(int x, int y, int idx) { fa[idx][find(x, idx)] = find(y, idx); }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     for (int i = 1; i <= n - 1; i++) scanf( %d%d%d , &u[i], &v[i], &w[i]);     init();     for (int i = 1; i <= n - 1; i++) {       if (w[i] == 0)         merge(u[i], v[i], 0);       else         merge(u[i], v[i], 1);     }     for (int i = 1; i <= n; i++) a[find(i, 0)]++;     for (int i = 1; i <= n; i++) b[find(i, 1)]++;     for (int i = 1; i <= n; i++) ans += 1ll * a[find(i, 0)] * b[find(i, 1)];     printf( %lld n , ans - n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using point = complex<double>;   const int T = 1 << 16;   point root[T];   void fft(vector<point>& a) {     int n = a.size();     vector<int> reverse(n);     for (int i = 0; i < n; ++i) {       reverse[i] = (reverse[i / 2] + (i % 2) * n) / 2;       if (i < reverse[i]) {         swap(a[i], a[reverse[i]]);       }     }     for (int i = 1; i < n; i *= 2) {       for (int j = 0; j < n; j += 2 * i) {         for (int k = 0; k < i; ++k) {           point l = a[j + k];           point r = a[i + j + k] * root[i + k];           a[j + k] = l + r;           a[i + j + k] = l - r;         }       }     }   }   vector<point> mul(vector<point> a, vector<point> b) {     int n = 1, m = a.size() + b.size();     while (n < m) {       n *= 2;     }     a.resize(n), b.resize(n);     fft(a), fft(b);     for (int i = 0; i < n; ++i) {       a[i] *= b[i];     }     fft(a);     for (auto& i : a) {       i /= n;     }     reverse(a.begin() + 1, a.end());     a.resize(m - 1);     return a;   }   const int M = 100;   const int N = 50;   double prob[M][T], expect[M][T], ans[N][T];   array<int, 3> edges[M];   long long dist[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(6);     for (int i = 1; i < T; i *= 2) {       for (int j = 0; j < i; ++j) {         root[i + j] = polar(1.0, j * M_PI / i);       }     }     int n, m, t, x;     cin >> n >> m >> t >> x;     for (int i = 0; i < m; ++i) {       int u, v, w;       cin >> u >> v >> w;       edges[i] = {u - 1, v - 1, w};       for (int j = 1; j <= t; ++j) {         int p;         cin >> p;         prob[i][j] = p / 100000.0;       }     }     fill(dist, dist + n - 1, LLONG_MAX);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         auto [u, v, w] = edges[j];         if (dist[v] < LLONG_MAX) {           dist[u] = min(dist[u], dist[v] + w);         }       }     }     for (int i = 0; i < n - 1; ++i) {       fill(ans[i], ans[i] + t + 1, HUGE_VAL);     }     for (int i = 0; i < m; ++i) {       auto [u, v, w] = edges[i];       double sum = 0.0;       for (int j = t; j >= 0; --j) {         expect[i][j] = w + sum * (dist[v] + x);         sum += prob[i][j];       }       ans[u][0] = min(ans[u][0], expect[i][0]);     }     for (int i = 1; i <= t; ++i) {       for (int j = 0; j < m; ++j) {         auto [u, v, w] = edges[j];         for (int k = 1; i % k == 0; k *= 2) {           vector<point> poly =               mul(vector<point>(ans[v] + i - k, ans[v] + i),                   vector<point>(prob[j] + k, prob[j] + min(2 * k, t + 1)));           for (int l = 0; l <= t - i && l <= (int)poly.size(); ++l) {             expect[j][l + i] += poly[l].real();           }         }         ans[u][i] = min(ans[u][i], expect[j][i]);       }     }     cout << ans[0][t] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool prime[1007];   int n;   void sieve() {     for (int i = 4; i <= 1005; i += 2) prime[i] = false, prime[i - 1] = true;     prime[2] = true;     for (int i = 3; i <= 1000; i += 2) {       if (prime[i]) {         for (int j = i * i; j <= 1005; j += i * 2) prime[j] = false;       }     }   }   int main() {     ios::sync_with_stdio(false);     sieve();     scanf( %d , &n);     vector<int> ans;     for (int i = 1; i <= n; i++) {       if (prime[i]) {         int q = 1;         while (q <= n / i) {           q *= i;           ans.push_back(q);         }       }     }     cout << (ans.size()) << endl;     for (int i : ans) {       printf( %d  , i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q, x;     cin >> q >> x;     long long n = q;     long long a[n];     map<long long, long long> m;     long long min = 0;     map<long long, long long> f;     for (long long i = 0; i < n; i++) {       cin >> a[i];       long long mod = a[i] % x;       f[mod]++;       m[mod + ((f[mod] - 1) * x)]++;       while (m[min] == 1) min++;       cout << min << endl;     }     map<long long, long long>::iterator it;   }
#include <bits/stdc++.h>   int read() {     static int c, x;     while ((c = getchar()) < 48) {     }     x = c & 15;     while ((c = getchar()) >= 48) x = x * 10 + (c & 15);     return x;   }   struct edge {     int next, to;   } e[100010 << 1];   int ans = 0;   int head[100010], deg[100010], f0[100010], f1[100010];   inline void add(const int &x, const int &y) {     static int ei;     e[++ei].next = head[x];     e[ei].to = y;     head[x] = ei;     ++deg[x];   }   void dfs(const int &x, const int &fa) {     f1[x] = 1;     f0[x] = deg[x] - 1;     for (int i = head[x]; i; i = e[i].next) {       const int y = e[i].to;       if (y != fa) {         dfs(y, x);         ans = std::max(ans, f0[x] + std::max(f0[y], f1[y]));         ans = std::max(ans, f1[x] + f0[y]);         f0[x] = std::max(f0[x], std::max(f0[y], f1[y]) + deg[x] - 2);         f1[x] = std::max(f1[x], f0[y] + 1);       }     }   }   int main() {     const int n = read();     for (int i = n; --i;) {       const int x = read(), y = read();       add(x, y);       add(y, x);     }     dfs(1, 0);     printf( %d n , ans);     return 0;   }