malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(int &x) {     char c = nc(), b = 1;     for (; !(c >=  0  && c <=  9 ); c = nc()) {       if (c ==  - ) b = -b;     }     for (x = 0; c >=  0  && c <=  9 ; x = x * 10 + c -  0 , c = nc())       ;     x *= b;   }   const int N = 500001;   const int sqN = 708;   int ans[N];   int fre[N];   int v[N];   int block[sqN];   int flag[sqN];   int answer = 0;   vector<int> bl;   struct query {     int l;     int r;     int idx;   } Q[N];   bool comp(query q1, query q2) {     if (q1.l / sqN != q2.l / sqN) {       return q1.l < q2.l;     }     if ((q1.l / sqN) & 1) {       return q1.r < q2.r;     }     return q1.r > q2.r;   }   inline void add(int idx) {     int val = v[idx];     fre[val]++;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;       if (!flag[val / sqN]) {         flag[val / sqN] = 1;         bl.push_back(val / sqN);       }     }     if (fre[val] == 2) {       answer--;       block[val / sqN]--;     }   }   inline void rem(int idx) {     int val = v[idx];     fre[val]--;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;       if (!flag[val / sqN]) {         flag[val / sqN] = 1;         bl.push_back(val / sqN);       }     }     if (fre[val] == 0) {       answer--;       block[val / sqN]--;     }   }   inline int solve() {     if (answer == 0) {       return 0;     }     while (!bl.empty() && block[bl.back()] < 1)       flag[bl.back()] = 0, bl.pop_back();     int i = bl.back();     for (int j = i * sqN; j < i * sqN + sqN; j++) {       if (fre[j] == 1) {         return j;       }     }   }   int main() {     int n;     read(n);     for (int i = 0; i < n; i++) {       read(v[i]);     }     int q, l, r;     read(q);     for (int i = 0; i < q; i++) {       read(l);       read(r);       l--;       r--;       Q[i].l = l;       Q[i].r = r;       Q[i].idx = i;     }     sort(Q, Q + q, comp);     l = 0, r = -1;     for (int i = 0; i < q; i++) {       int L = Q[i].l;       int R = Q[i].r;       while (l < L) {         rem(l);         l++;       }       while (l > L) {         l--;         add(l);       }       while (r < R) {         r++;         add(r);       }       while (r > R) {         rem(r);         r--;       }       ans[Q[i].idx] = solve();     }     for (int i = 0; i < q; i++) {       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     multiset<char> ms;     for (char c : s) ms.insert(c);     string t, u;     for (int i = 0; i < (s.size()); i++) {       ms.erase(ms.find(s[i]));       t += s[i];       while (!t.empty() && ms.lower_bound(t.back()) == ms.begin()) {         u += t.back();         t.pop_back();       }     }     cout << u << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 25e4 + 1;   const long long inf = 1e18;   int n, m, k, h[maxn], par[maxn], tests, ted;   bool vis[maxn];   vector<int> e[maxn];   vector<int> ans[maxn];   void path_ans(int v) {     cout <<  PATH  <<   n ;     cout << tests <<   n ;     for (int test = 1; test <= tests; test++) {       cout << v <<    ;       v = par[v];     }     cout << endl;     return;   }   void dfs(int v) {     vis[v] = 1;     int ch = 0;     for (auto u : e[v]) {       if (vis[u] == 0) {         ch++;         par[u] = v;         h[u] = h[v] + 1;         if (h[u] >= tests) {           path_ans(u);           exit(0);         }         dfs(u);       }     }     if (ch == 0 && ted < k) {       int t1 = 0, t2 = 0;       for (auto u : e[v]) {         if (u != par[v]) {           if (h[u] > h[t1]) {             t2 = t1;             t1 = u;           } else if (h[u] > h[t2]) {             t2 = u;           }         }       }       if ((h[v] - h[t1] + 1) % 3 != 0) {         int x = v;         while (x != par[t1]) {           ans[ted].push_back(x);           x = par[x];         }       } else if ((h[v] - h[t2] + 1) % 3 != 0) {         int x = v;         while (x != par[t2]) {           ans[ted].push_back(x);           x = par[x];         }       } else {         ans[ted].push_back(v);         int x = t1;         while (x != par[t2]) {           ans[ted].push_back(x);           x = par[x];         }       }       ted++;     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     tests = (n + k - 1) / k;     for (int i = 1; i <= m; i++) {       int t1, t2;       cin >> t1 >> t2;       e[t1].push_back(t2);       e[t2].push_back(t1);     }     h[1] = 1;     dfs(1);     cout <<  CYCLES  <<   n ;     for (int i = 0; i < k; i++) {       cout << ans[i].size() <<   n ;       for (auto u : ans[i]) {         cout << u <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[2][52][52][52][52] = {{{{{0}}}}};   int d[52];   int n;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> d[i];     }     dp[1][d[0] == 2][d[0] == 3][d[1] == 2][d[1] == 3] = 1;     for (int i = 2; i < n; ++i) {       memset(dp[i & 1], 0, sizeof dp[i & 1]);       for (int p1 = 0; p1 <= n; ++p1) {         for (int p2 = 0; p1 + p2 <= n; ++p2) {           for (int c1 = 0; p1 + p2 + c1 <= n; ++c1) {             for (int c2 = 0; p1 + p2 + c1 + c2 <= n; ++c2) {               long long cur = dp[(i - 1) & 1][p1][p2][c1][c2];               if (!p1 and !p2) {                 dp[(i - 1) & 1][c1][c2][0][0] += cur;                 dp[(i - 1) & 1][c1][c2][0][0] %= MOD;                 continue;               }               for (int last_level = 0; last_level < 2; ++last_level) {                 long long ways;                 if (last_level) {                   if (p1)                     ways = p1--;                   else                     continue;                 } else {                   if (p2)                     p1++, ways = p2--;                   else                     continue;                 }                 if (d[i] == 2) {                   dp[i & 1][p1][p2][c1 + 1][c2] += cur * ways;                   dp[i & 1][p1][p2][c1 + 1][c2] %= MOD;                   if (c1) {                     dp[i & 1][p1][p2][c1 - 1][c2] += cur * ways * c1;                     dp[i & 1][p1][p2][c1 - 1][c2] %= MOD;                   }                   if (c2) {                     dp[i & 1][p1][p2][c1 + 1][c2 - 1] += cur * ways * c2;                     dp[i & 1][p1][p2][c1 + 1][c2 - 1] %= MOD;                   }                 } else {                   dp[i & 1][p1][p2][c1][c2 + 1] += cur * ways;                   dp[i & 1][p1][p2][c1][c2 + 1] %= MOD;                   dp[i & 1][p1][p2][c1][c2] += cur * ways * c1;                   dp[i & 1][p1][p2][c1][c2] %= MOD;                   if (c1 && c2) {                     dp[i & 1][p1][p2][c1][c2 - 1] += cur * ways * c2 * c1;                     dp[i & 1][p1][p2][c1][c2 - 1] %= MOD;                   }                   if (c1 > 1) {                     dp[i & 1][p1][p2][c1 - 2][c2] +=                         cur * ways * (c1 * (c1 - 1)) >> 1;                     dp[i & 1][p1][p2][c1 - 2][c2] %= MOD;                   }                   if (c2) {                     dp[i & 1][p1][p2][c1 + 2][c2 - 1] += cur * ways * c2;                     dp[i & 1][p1][p2][c1 + 2][c2 - 1] %= MOD;                   }                   if (c2 > 1) {                     dp[i & 1][p1][p2][c1 + 2][c2 - 2] +=                         cur * ways * (c2 * (c2 - 1)) >> 1;                     dp[i & 1][p1][p2][c1 + 2][c2 - 2] %= MOD;                   }                 }                 if (last_level) {                   p1++;                 } else {                   p2++;                   p1--;                 }               }             }           }         }       }     }     cout << dp[(n - 1) & 1][0][0][0][0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     vector<vector<int> > v(n, vector<int>(7, 0));     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < 7; j++) v[i][j] = s[j] -  0 ;     }     vector<int> cnt(7, 0);     for (int i = 0; i < 7; i++) {       for (int j = 0; j < n; j++) cnt[i] += v[j][i];     }     int m = 0;     for (int i = 0; i < 7; i++) {       if (cnt[i] > m) m = cnt[i];     }     cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   inline long long readll() {     long long x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   const int N = 200005;   int tag[N << 2], f[N << 2][2][32], a[N];   int S, now;   inline void pushup(int rt) {     int ls = rt << 1, rs = rt << 1 | 1;     for (int i = 0; i < S; ++i)       f[rt][0][i] = f[ls][0][f[rs][0][i]], f[rt][1][i] = f[ls][1][f[rs][1][i]];   }   inline void Cover(int rt) { swap(f[rt][0], f[rt][1]), tag[rt] ^= 1; }   inline void pushdown(int rt) {     Cover(rt << 1);     Cover(rt << 1 | 1);     tag[rt] ^= 1;   }   void build(int l, int r, int rt) {     if (l == r) {       for (int i = 0; i < S; ++i)         f[rt][a[l]][i] = (i << 1) % S + 1,         f[rt][a[l] ^ 1][i] = (i << 1) % S + (i != S - 1);       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushup(rt);   }   void update(int l, int r, int rt, int L, int R) {     if (L <= l && r <= R) {       Cover(rt);       return;     }     if (tag[rt]) pushdown(rt);     int mid = (l + r) >> 1;     if (L <= mid) update(l, mid, rt << 1, L, R);     if (R > mid) update(mid + 1, r, rt << 1 | 1, L, R);     pushup(rt);   }   void query(int l, int r, int rt, int L, int R) {     if (L <= l && r <= R) {       now = f[rt][0][now];       return;     }     if (tag[rt]) pushdown(rt);     int mid = (l + r) >> 1;     if (R > mid) query(mid + 1, r, rt << 1 | 1, L, R);     if (L <= mid) query(l, mid, rt << 1, L, R);   }   int main() {     int n = read(), m = read(), q = read();     S = (1 << m);     for (int i = 1; i <= n; ++i) a[i] = readll() % 2;     build(1, n, 1);     while (q--) {       int opt = read(), l = read(), r = read();       if (opt == 1) {         if (readll() % 2) update(1, n, 1, l, r);       } else {         now = S - 1;         query(1, n, 1, l, r);         putchar(now % 2 ?  1  :  2 );         putchar(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string luck[7] = { 1869 ,  1968 ,  1689 ,  6198 ,  1698 ,  1986 ,  1896 };     string str;     cin >> str;     int ans = 0;     bool vis[10];     int zero = 0;     memset(vis, 0, sizeof(vis));     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  0 )         zero++;       else if (!vis[1] && str[i] ==  1 )         vis[1] = true;       else if (!vis[6] && str[i] ==  6 )         vis[6] = true;       else if (!vis[8] && str[i] ==  8 )         vis[8] = true;       else if (!vis[9] && str[i] ==  9 )         vis[9] = true;       else {         printf( %c , str[i]);         ans = ans * 10 + str[i] -  0 ;         ans %= 7;       }     }     ans = ans * 10000;     ans %= 7;     cout << luck[(7 - ans) % 7];     while (zero--) printf( 0 );     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using D = double;   using uint = unsigned int;   template <typename T>   using pair2 = pair<T, T>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int maxn = 100005;   vector<int> pos[maxn];   int n, bulls, cows;   priority_queue<pair2<int>> freq;   int a[maxn], b[maxn];   vector<pair2<int>> all;   void solve() {     scanf( %d%d%d , &n, &bulls, &cows);     cows -= bulls;     for (int i = 0; i < n + 1; i++) pos[i].clear();     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);       b[i]--;       pos[b[i]].push_back(i);     }     for (int i = 0; i < n; i++) a[i] = -1;     int missing_color = -1;     while (!freq.empty()) freq.pop();     for (int i = 0; i < n + 1; i++) {       if (pos[i].empty()) missing_color = i;       freq.push({(int)pos[i].size(), i});     }     assert(missing_color != -1);     for (int i = 0; i < bulls; i++) {       int color = freq.top().second;       freq.pop();       a[pos[color].back()] = color;       pos[color].pop_back();       freq.push({(int)pos[color].size(), color});     }     all.clear();     int max_occ = freq.top().first;     while (!freq.empty()) {       int color = freq.top().second;       freq.pop();       for (auto t : pos[color]) all.push_back({color, t});     }     int max_cows = (int)all.size();     if (2 * max_occ > (int)all.size()) max_cows -= 2 * max_occ - (int)all.size();     if (cows > max_cows) {       printf( NO n );       return;     }     int shift = (int)all.size() / 2;     for (int i = 0; i < (int)all.size(); i++) {       int j = (i + shift) % (int)all.size();       int color = all[j].first;       if (all[i].first == all[j].first || cows == 0) color = missing_color;       if (color != missing_color) cows--;       a[all[i].second] = color;     }     printf( Yes n );     for (int i = 0; i < n; i++) printf( %d  , a[i] + 1);     printf(  n );   }   int main() {     int NT;     scanf( %d , &NT);     for (int T = 0; T < NT; T++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long n, p;   const long long N = 1e6 + 2;   long long a[N];   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, i, v1, ans, x, y;     cin >> t;     while (t--) {       cin >> n >> p;       for (i = 1; i <= n; ++i) cin >> a[i];       if (p == 1) {         if (n % 2)           cout << 1 <<   n ;         else           cout << 0 <<   n ;         continue;       }       sort(a + 1, a + 1 + n, greater<long long>());       stack<long long> s1, s2;       for (i = 1; i <= n; ++i) {         if (s1.empty()) {           s1.push(a[i]);           s2.push(1);           continue;         } else {           if (s1.size() == 1 && a[i] == s1.top()) {             s1.pop();             s2.pop();           } else if (s1.top() != a[i]) {             s1.push(a[i]);             s2.push(1);           } else {             x = s1.top();             y = s2.top() + 1;             if (y == p) {               y = 1;               ++x;             }             s1.pop();             s2.pop();             while (!s1.empty() && s1.top() == x) {               y = y + s2.top();               s1.pop();               s2.pop();               if (y == p) {                 y = 1;                 ++x;               }             }             s1.push(x);             s2.push(y);           }         }         if (s1.size() == 1) {           s1.pop();           s2.pop();         }       }       ans = 0;       while (s1.size() > 1) {         ans =             (ans + ((s2.top() * binpow(p, s1.top(), 1000000007)) % 1000000007)) %             1000000007;         s1.pop();         s2.pop();       }       if (s1.size() == 1)         ans = ((binpow(p, s1.top(), 1000000007)) - ans) % 1000000007;       ans = (ans + 1000000007) % 1000000007;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (1LL << 60) - 1;   void solve() {     set<int> st;     int n, k, arr[1001];     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> arr[i];       st.insert(arr[i]);     }     if ((int)st.size() >= k) {       puts( YES );       int lst = -1;       for (int i = 0; i < n && k; i++) {         if (arr[i] != lst && st.find(arr[i]) != st.end()) {           cout << i + 1 <<    ;           lst = arr[i];           st.erase(arr[i]);           k--;         }       }     } else       puts( NO );   }   int main() { solve(); }
#include <bits/stdc++.h>   #include <stack>   using namespace std;   #define ll long long   #define rep(i,a,b) for(ll i=a; i<b; i++)   #define repi(i,a,b) for(ll i=b-1; i>=a; i--)   #define pb push_back   #define mod 1000000007   void fastscan(ll &num){       bool n=false;       register ll c;       num=0;       c=getchar();       if(c== - ){           n=true;           c=getchar();       }       for(;(c>47 && c<58); c=getchar()){           num=num*10+c-48;       }       if(n){           num*=-1;       }          }   ll max(ll a, ll b) {if(a>b){return a;}else {return b;}}   ll min(ll a, ll b) {if(a>b){return b;}else {return a;}}      ll gcd(ll a, ll b){       if(a>b){           if(b==0){               return a;           }else {               return gcd(a%b,b);           }       }else {           if(a==0){               return b;           }else {               return gcd(b%a,a);           }       }   }      bool isprime(ll n){       if(n<=1){           return false;       }else if(n<=3){           return true;       }       if(n%2==0 || n%3==0){           return false;       }       for(int i=5; i*i<=n; i=i+6){           if(n%i==0 || n%(i+2)==0){               return false;           }       }       return true;   }   int main() {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       ll t,n;       cin>>t;       rep(i,0,t){           cin>>n;           ll x=2050,y=0;           while(n>=x){               x*=10;           }           x/=10;           while(n>=2050){               if(x<=n){                   n-=x;                   y++;               }else {                   x/=10;               }           }           if(n==0){               cout<<y<<endl;           }else {               cout<<-1<<endl;           }       }    // your code goes here    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     cin >> n;     long sum = 2;     int k = 1;     int b = 0;     for (int i = 1;; i = i + k) {       if (i == n) {         break;       }       b++;       if (b == 2) {         b = b % 2;         k++;       }       if (i > n) {         break;       }       sum++;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z, a, b, c;     cin >> x >> y >> z;     cin >> a >> b >> c;     if (a < x) {       printf( No );       return 0;     }     if (a + b < x + y) {       printf( No );       return 0;     }     if (a + b + c < x + y + z) {       printf( No );       return 0;     }     printf( Yes );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int d, k, a, b, t, x = 0, ans = 0, y;     cin >> d >> k >> a >> b >> t;     ans = a * min(d, k);     x = min(d, k);     if (x < d) {       y = (d - x) / k;       if (t * y + a * y * k < b * y * k)         ans += (t * y + a * y * k);       else         ans += (b * y * k);       long long int left = d - x - y * k;       if (t + left * a < left * b)         ans += (t + left * a);       else         ans += (left * b);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   long long BIT[6][N];   int n, arr[N];   inline long long getPrefix(int z, int i) {     i = n - i - 1;     ++i;     long long ret = 0;     while (i) ret += BIT[z][i], i -= i & -i;     return ret;   }   inline void add(int z, int i, long long v) {     i = n - i - 1;     ++i;     while (i < N) BIT[z][i] += v, i += i & -i;   }   long long f(long long x) { return x * (x + 1) / 2; }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &arr[i]), arr[i]--;     double out = 0;     double fn = f(n);     for (int j = 0; j < n; j++) {       double i = getPrefix(0, arr[j]);       double i1 = getPrefix(1, arr[j]);       double fi = getPrefix(2, arr[j]);       double fni = getPrefix(3, arr[j]);       double ci = getPrefix(4, arr[j]);       double temp = ci * f(n - j - 1) / fn;       temp += (fni - ci * f(n - j - 1)) / fn;       temp += (i1 * j - fi * 2) / fn;       temp += fi / fn;       out += temp;       add(0, arr[j], j);       add(1, arr[j], j + 1);       add(2, arr[j], f(j));       add(3, arr[j], f(n - j - 1));       add(4, arr[j], 1);     }     for (long long len = 1; len <= n; len++)       out += len * (len - 1) / 4.0 * (n - len + 1) / fn;     printf( %.9lf n , out);   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long x = 0;     char zf = 1;     char ch;     while (ch !=  -  && !isdigit(ch)) ch = getchar();     if (ch ==  - ) zf = -1, ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * zf;   }   void write(long long y) {     if (y < 0) putchar( - ), y = -y;     if (y > 9) write(y / 10);     putchar(y % 10 +  0 );   }   inline void writeln(const long long y) {     write(y);     putchar(  n );   }   inline int min(const int x, const int y) { return x < y ? x : y; }   inline int max(const int x, const int y) { return x > y ? x : y; }   int i, j, k, m, n, x, y, z, cnt, la[1000010], fa[1000010], size[1000010], top,       g = 0;   int ask(int x) {     while (fa[x] != x) x = fa[x];     return x;   }   void merge(int x, int y) {     if (x == y) return;     if (size[x] > size[y]) swap(x, y);     la[++top] = x;     fa[x] = y;     size[y] += size[x];   }   void undo() {     int La = la[top];     size[fa[La]] -= size[La];     fa[La] = La;     top--;   }   struct ed {     int x, y, z;     inline bool operator<(const ed s) const { return z < s.z; }   } q[1000010];   struct query {     int id, x, y, val;     inline bool operator<(const query s) const {       if (val == s.val) return id < s.id;       return val < s.val;     }   } A[1000010];   int ans[1000010];   int main() {     n = read();     m = read();     for (register int i = 1; i <= n; i++) size[i] = 1, fa[i] = i;     for (register int i = 1; i <= m; i++) {       x = read();       y = read();       z = read();       q[i] = {x, y, z};     }     k = read();     for (register int e = 1; e <= k; e++) {       z = read();       ans[e] = 1;       for (register int i = 1; i <= z; i++) {         x = read();         A[++cnt] = {e, q[x].x, q[x].y, q[x].z};       }     }     sort(q + 1, q + m + 1);     sort(A + 1, A + cnt + 1);     int qd = 1;     for (register int i = 1; i <= cnt;) {       while (q[qd].z < A[i].val) merge(ask(q[qd].x), ask(q[qd].y)), qd++;       top = 0;       do {         if (ask(A[i].x) == ask(A[i].y)) ans[A[i].id] = 0;         merge(ask(A[i].x), ask(A[i].y));         i++;       } while (A[i].val == A[i - 1].val && A[i].id == A[i - 1].id);       while (top) undo();     }     for (register int i = 1; i <= k; i++) puts(ans[i] ?  YES  :  NO );     return 0;   }