malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500050;   const long long inf = 1e18;   int a[maxn];   vector<int> G[maxn];   int f[maxn][20], root;   long long ans = 0;   void dfs(int x, int par) {     f[x][0] = par;     long long t = inf;     if (par) t = a[x] + a[par];     for (int i = 1; f[x][i - 1]; ++i) {       f[x][i] = f[f[x][i - 1]][i - 1];       if (f[x][i])         t = min(t, (1ll + i) * a[f[x][i]] + a[x]);       else         t = min(t, (1ll + i) * a[root] + a[x]);     }     if (par) ans += t;     for (auto &v : G[x]) {       if (v != par) dfs(v, x);     }   }   int main() {     int n;     scanf( %d , &n);     root = 1;     for (int i = 1; i <= n; ++i)       scanf( %d , a + i), a[i] < a[root] ? root = i : 0;     for (int i = 0; i < n - 1; ++i) {       int x, y;       scanf( %d%d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);     }     dfs(root, 0);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double PI = 3.14159265358979323843;   int BS(int arr[], int sz, int n) {     int l = 0, r = sz - 1, mid;     while (l <= r) {       if (arr[mid] >= n)         r = mid - 1;       else         l = mid + 1;     }     return l;   }   bool prime(long long x) {     for (int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) {         return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     int c = 0;     if (s.size() == 1) {       return puts( 0 ), 0;     }     while (true) {       long long sum = 0;       for (int i = 0; i < s.size(); i++) {         sum += s[i] -  0 ;       }       s.clear();       if (sum / 10 == 0) {         break;       }       c++;       s = to_string(sum);     }     cout << ++c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sta[10][100005];   int top[10];   int tail[10];   int a[100005][10];   int ans[10];   int main() {     int n, m;     int k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 1; i <= m; i++) {       top[i] = 1;     }     int ma = -1;     int i = 1;     for (int l = 1; l <= n; l++) {       if (l > 1) {         for (int j = 1; j <= m; j++) {           if (top[j] <= tail[j] && sta[j][top[j]] < l) {             top[j]++;           }         }       }       for (i = max(i, l); i <= n; i++) {         int sum = 0;         for (int j = 1; j <= m; j++) {           sum += max(a[sta[j][top[j]]][j], a[i][j]);         }         if (sum > k) break;         for (int j = 1; j <= m; j++) {           while (tail[j] >= top[j] && a[sta[j][tail[j]]][j] < a[i][j]) {             tail[j]--;           }           sta[j][++tail[j]] = i;         }         if (i - l + 1 > ma) {           ma = i - l + 1;           for (int j = 1; j <= m; j++) ans[j] = a[sta[j][top[j]]][j];         }       }     }     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int imax = INT32_MAX;   const int imin = INT32_MIN;   const long long int inf = 1e18;   const long long int MOD = 1e9 + 7;   const long long int range = 1e9 + 7;   vector<vector<int>> g;   template <class T>   T cal(T n) {     return (n * 1ll * (n + 1));   }   template <class T>   T mx(T begin, T end) {     return max_element(begin, end);   }   template <class T>   T mn(T begin, T end) {     return min_element(begin, end);   }   template <class T>   void getUnique(vector<T>& nums) {     sort(nums.begin(), nums.end());     nums.erase(unique(nums.begin(), nums.end()), nums.end());   }   template <class T>   void print(vector<T> nums) {     for (T i : nums) cout << i <<    ;     cout <<   n ;   }   template <class T>   void read(vector<T>& nums) {     for (T& i : nums) cin >> i;   }   template <class T>   void alloc(vector<vector<T>*> nums, T n) {     for (auto nums : nums) nums->resize(n + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       vector<long long int> dp(n + 1, imax);       dp[0] = 0;       for (long long int i = 1; i <= n; ++i) {         long long int num = i;         while (num > 0) {           dp[i] = min(dp[i], 1 + dp[i - num % 10]);           num /= 10;         }       }       cout << dp[n];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, a2, a3;     getline(cin, a);     getline(cin, a2);     getline(cin, a3);     int lin1 = 0, lin2 = 0, lin3 = 0;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  e  || a[i] ==  a  || a[i] ==  i  || a[i] ==  o  ||           a[i] ==  u  || a[i] ==  E  || a[i] ==  A  || a[i] ==  O  ||           a[i] ==  I  || a[i] ==  U ) {         lin1++;       }     }     for (int i = 0; i < a2.size(); i++) {       if (a2[i] ==  e  || a2[i] ==  a  || a2[i] ==  i  || a2[i] ==  o  ||           a2[i] ==  u  || a2[i] ==  E  || a2[i] ==  A  || a2[i] ==  O  ||           a2[i] ==  I  || a2[i] ==  U ) {         lin2++;       }     }     for (int i = 0; i < a3.size(); i++) {       if (a3[i] ==  e  || a3[i] ==  a  || a3[i] ==  i  || a3[i] ==  o  ||           a3[i] ==  u  || a3[i] ==  E  || a3[i] ==  A  || a3[i] ==  O  ||           a3[i] ==  I  || a3[i] ==  U ) {         lin3++;       }     }     if (lin1 == 5 && lin2 == 7 && lin3 == 5) {       cout <<  YES ;       return 0;     } else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, t, a, b, da, db;     cin >> x >> t >> a >> b >> da >> db;     for (int i = 0; i < t; i++)       for (int h = 0; h <= 1; h++)         for (int j = 0; j < t; j++)           for (int s = 0; s <= 1; s++)             if (((a - (da * i)) * h) + ((b - (db * j)) * s) == x) {               cout <<  YES  << endl;               return 0;             }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int times = 1;     cin >> times;     for (int i = 0; i < times; i++) {       solve();       cout <<   n ;     }     return 0;   }   long long a, b, c, d, e, f, g, h;   long long arr[500000 + 50];   void solve() {     cin >> a >> b >> c;     for (int i = 1; i <= a; i++) cin >> arr[i];     sort(arr + 1, arr + a + 1);     long long dp[a + 50][2];     for (int i = 1; i <= a; i++) dp[i][0] = dp[i][1] = 21474836477777;     dp[0][0] = dp[0][1] = 0;     for (int i = 1; i <= a; i++) {       if (i > 0) {         dp[i][0] = min(dp[i][0], dp[i - 1][0] + arr[i]);         dp[i][0] = min(dp[i][0], dp[i - 1][1] + arr[i]);       }       if (i >= c) {         dp[i][1] = min(dp[i][1], dp[i - c][0] + arr[i]);         dp[i][1] = min(dp[i][1], dp[i - c][1] + arr[i]);       }     }     int ans = 0;     for (int i = 1; i <= a; i++) {       if (dp[i][0] <= b || dp[i][1] <= b) ans = i;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const int maxn = 3e5 + 10;   const int mod = 1e9 + 7;   long long a[maxn];   int main() {     long long n, m;     scanf( %I64d%I64d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %I64d , &a[i]);     }     int now = 0;     for (int i = 0; i < n; i++) {       printf( %I64d%c , (a[i] + now) / m,    n [i == n - 1]);       now = (a[i] + now) % m;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a, x;     long long ans = 0;     map<vector<pair<int, int>>, int> mp;     for (int i = 0; i < n; i++) {       vector<pair<int, int>> v;       cin >> a;       for (int j = 2; j * j <= a; j++) {         int pow = 0;         while (a % j == 0) {           a = a / j;           pow++;         }         pow = pow % k;         if (pow) {           v.push_back({j, k - pow});         }       }       if (a != 1) {         v.push_back({a, k - 1});       }       ans = ans + mp[v];       for (int i = 0; i < v.size(); i++) v[i].second = k - v[i].second;       mp[v]++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int long long n, a, b, x = 4, y = 2, ans, m, ans1, ans2, ans3;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> m >> a >> b;     while (x > 0 || y > 0) {       ans++;       n = m;       while (x > 0 && n >= a) {         x--;         n -= a;       }       while (y > 0 && n >= b) {         y--;         n -= b;       }     }     x = 4;     y = 2;     while (x > 0 || y > 0) {       ans1++;       n = m;       while (y > 0 && n >= b) {         y--;         n -= b;       }       while (x > 0 && n >= a) {         x--;         n -= a;       }     }     x = 4;     y = 2;     while (x > 0 || y > 0) {       ans2++;       n = m;       while (x > 0 && y > 0 && n >= a + b) {         x--;         y--;         n -= a + b;       }       while (y > 0 && n >= b) {         y--;         n -= b;       }       while (x > 0 && n >= a) {         x--;         n -= a;       }     }     x = 4;     y = 2;     while (x > 0 || y > 0) {       ans3++;       n = m;       while (x > 0 && y > 0 && n >= a + b) {         x--;         y--;         n -= a + b;       }       while (x > 0 && n >= a) {         x--;         n -= a;       }       while (y > 0 && n >= b) {         y--;         n -= b;       }     }     cout << min(min(ans, ans1), min(ans2, ans3));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 1;   vector<int> s[N], e[N];   int n, m, l[N], r[N], x[N], res[N];   bool vis[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &l[i], &r[i], &x[i]);       s[l[i]].push_back(i);       e[r[i]].push_back(i);     }     priority_queue<int> qu;     vector<int> w;     for (int i = 1; i <= n; ++i) {       for (size_t j = 0; j < s[i].size(); ++j) qu.push(-s[i][j]);       bool can = false;       while (!qu.empty()) {         int v = -qu.top();         if (!vis[v]) {           can = true;           break;         }         qu.pop();       }       if (!can) continue;       w.clear();       while (!qu.empty()) {         int v = -qu.top();         if (x[v] == i || i < l[v] || i > r[v]) {           qu.pop();           w.push_back(v);           continue;         }         res[i] = x[v];         break;       }       for (size_t j = 0; j < w.size(); ++j) qu.push(-w[j]);       for (size_t j = 0; j < e[i].size(); ++j) vis[e[i][j]] = true;     }     for (int i = 1; i <= n; ++i) printf( %s%d , i > 1 ?     :   , res[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int i, j = 0, k, a, b;   int main() {     long long int n, m;     cin >> n;     long long int aa[n + 1];     for (i = 1; i <= n; i++) cin >> aa[i];     cin >> m;     while (m--) {       cin >> a >> b;       if (a != 1) aa[a - 1] += b - 1;       if (a != n) aa[a + 1] += aa[a] - b;       aa[a] = 0;     }     for (i = 1; i <= n; i++) cout << aa[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     int a[n + 2][3];     for (int i = 0; i < n + 1; i++)       for (int j = 0; j < 3; j++) a[i][j] = 0;     for (int k = 0; k < s.length(); k++) {       if (s[k] ==  . )         continue;       else if (s[k] ==  A ) {         a[k][1] = 1;         a[k + 1][1] = 1;         a[k + 2][1] = 1;       } else if (s[k] ==  B ) {         a[k][0] = 1;         a[k + 1][0] = 1;         a[k + 2][0] = 1;       } else {         a[k][2] = 1;         a[k + 1][2] = 1;         a[k + 2][2] = 1;       }     }     for (int l = 1; l <= n; l++) {       if (a[l][0] == 1 && a[l][1] == 1 && a[l][2] == 1) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   vector<int> g[N];   int pos[N], to[N];   int kw = 0, w[N];   void dfs(int v, int pr) {     pos[v] = kw;     w[kw++] = v;     for (int j = 0; j < (int)g[v].size(); j++) {       int u = g[v][j];       if (u != pr) {         dfs(u, v);       }     }     to[v] = kw - 1;   }   long long a[4 * N];   bool put[4 * N];   int color[N];   void build(int x, int l, int r) {     if (l < r) {       int y = (l + r) >> 1;       build(x + x, l, y);       build(x + x + 1, y + 1, r);       a[x] = a[x + x] | a[x + x + 1];       put[x] = false;     } else {       a[x] = 1LL << color[w[l]];       put[x] = true;     }   }   inline void push(int x) {     if (put[x]) {       a[x + x] = a[x + x + 1] = a[x];       put[x + x] = put[x + x + 1] = true;       put[x] = false;     }   }   inline void gather(int x) { a[x] = a[x + x] | a[x + x + 1]; }   void modify(int x, int l, int r, int ll, int rr, long long v) {     if (r < ll || rr < l) {       return;     }     if (ll <= l && r <= rr) {       a[x] = v;       put[x] = true;       return;     }     push(x);     int y = (l + r) >> 1;     modify(x + x, l, y, ll, rr, v);     modify(x + x + 1, y + 1, r, ll, rr, v);     gather(x);   }   long long get(int x, int l, int r, int ll, int rr) {     if (r < ll || rr < l) {       return 0;     }     if (ll <= l && r <= rr) {       return a[x];     }     push(x);     int y = (l + r) >> 1;     long long res = get(x + x, l, y, ll, rr);     res |= get(x + x + 1, y + 1, r, ll, rr);     gather(x);     return res;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , color + i);     }     for (int i = 0; i < n; i++) {       g[i].clear();     }     for (int i = 0; i < n - 1; i++) {       int foo, bar;       scanf( %d %d , &foo, &bar);       foo--;       bar--;       g[foo].push_back(bar);       g[bar].push_back(foo);     }     dfs(0, -1);     build(1, 0, n - 1);     while (m--) {       int type;       scanf( %d , &type);       if (type == 1) {         int foo, bar;         scanf( %d %d , &foo, &bar);         foo--;         modify(1, 0, n - 1, pos[foo], to[foo], 1LL << bar);       } else {         int foo;         scanf( %d , &foo);         foo--;         long long value = get(1, 0, n - 1, pos[foo], to[foo]);         printf( %d n , __builtin_popcountll(value));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long max(long long a, long long b) { return a > b ? a : b; }   bool r(long long p1, long long p2) { return (p2 < p1); }   long long min(long long a, long long b) { return a < b ? a : b; }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   const int N = 9;   long long power(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) {         ans = (ans * a);       }       a = (a * a);       b >>= 1;     }     return ans;   }   void solve() {     int n;     cin >> n;     int a[n], b[n], c[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> c[i];     int p[n];     p[0] = a[0];     for (int i = 1; i < n; i++) {       p[i] = a[i];       if (p[i] == p[i - 1]) p[i] = b[i];     }     if (p[n - 1] == p[0]) p[n - 1] = c[n - 1];     if (p[n - 1] == p[n - 2]) p[n - 1] = b[n - 1];     for (int i = 0; i < n; i++) cout << p[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int n;     string s;     while (t--) {       cin >> n >> s;       int x = 0, y = 0;       map<pair<int, int>, int> m;       int l = 0, r = n + 1;       m[{0, 0}] = 1;       for (int i = 0; i < n; i++) {         if (s[i] ==  L ) x--;         if (s[i] ==  R ) x++;         if (s[i] ==  U ) y++;         if (s[i] ==  D ) y--;         if (m[{x, y}]) {           if (i - m[{x, y}] < r - l) {             l = m[{x, y}];             r = i;           }         }         m[{x, y}] = i + 2;       }       if (l == 0) {         cout << -1 <<   n ;       } else {         cout << l <<     << r + 1 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5;   long long a[N], pos[N];   long long n;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       long long ok = 1;       for (long long i = 1; i + 1 <= n; i++) {         if (a[i + 1] == a[i] + 1 || a[i + 1] < a[i]) continue;         ok = 0;       }       if (ok)         cout <<  Yes               <<   n ;       else         cout <<  No               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[100500];   int b[200500];   int c[100500];   multiset<int> pl, mnus;   int addpl, addmn;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       c[a[i]] = i;     }     for (int i = 0; i < n; ++i) {       cin >> b[i];       b[i + n] = b[i];     }     for (int i = 0; i < n; ++i) {       if (c[b[i]] >= i)         mnus.insert(c[b[i]] - i);       else         pl.insert(i - c[b[i]]);     }     pl.insert(1e9);     mnus.insert(1e9);     cout << min(*mnus.begin() + addmn, *pl.begin() + addpl) << endl;     for (int i = 0; i < n - 1; ++i) {       addpl--;       addmn++;       mnus.erase(mnus.lower_bound(c[b[i]] + 1 - addmn));       pl.insert(n - c[b[i]] - 1 - addpl);       while (*pl.begin() + addpl == 0) mnus.insert(-addmn), pl.erase(pl.begin());       cout << min(*mnus.begin() + addmn, *pl.begin() + addpl) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string s[110 * 110];   vector<string> v;   char sub(string s1, string s2) {     int dem[30];     memset(dem, 0, sizeof(dem));     for (int i = 0; i < s1.size(); i++) dem[s1[i] -  a ]++;     for (int i = 0; i < s2.size(); i++) dem[s2[i] -  a ]--;     for (int i = 0; i <=  z  -  a ; i++)       if (dem[i] == 1) return char(i +  a );   }   bool cmp(string s1, string s2) { return (s1.length() > s2.length()); }   int main() {     int n;     cin >> n;     if (n == 1) {       cout <<  ?             <<     << 1 <<     << 1 << endl;       cout.flush();       string s;       cin >> s;       cout <<  !   << s;       return 0;     }     cout <<  ?           <<     << 1 <<     << n - 1 << endl;     cout.flush();     int t = (n * (n - 1)) / 2;     map<string, int> ma;     for (int i = 1; i <= t; i++) {       string s;       cin >> s;       sort(s.begin(), s.end());       ma[s]++;     }     cout <<  ?           <<     << 1 <<     << n << endl;     cout.flush();     t = (n * (n + 1)) / 2;     for (int i = 1; i <= t; i++) {       string s;       cin >> s;       sort(s.begin(), s.end());       if (ma[s] > 0)         ma[s]--;       else         v.push_back(s);     }     sort(v.begin(), v.end(), cmp);     cout <<  !  ;     for (int i = 0; i < v.size() - 1; i++) cout << sub(v[i], v[i + 1]);     cout << v.back();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long rand_int(long long l, long long r) {     static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());     return uniform_int_distribution<long long>(l, r)(gen);   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e % 2)       return ((b * power((b) * (b), (e - 1) / 2)));     else       return power((b) * (b), e / 2);   }   long long modpower(long long b, long long e, long long q) {     long long MOD = q;     if (e == 0) return 1;     if (e % 2)       return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;     else       return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;   }   void dpv(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }   void dpv(vector<pair<long long, long long> > v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i].first <<     << v[i].second << endl;     }   }   void dpv(set<long long> v) {     for (auto i : v) {       cout << i <<    ;     }     cout << endl;   }   bool check(long long l, long long r) {     assert(l <= r);     cout << l <<     << r << endl;     string s;     cin >> s;     if (s ==  Bad ) {       exit(0);     }     if (s ==  Yes ) {       if (l == r) exit(0);       return true;     }     return false;   }   void oblivious() {     srand(time(0));     long long n, K;     cin >> n >> K;     long long L = 1, R = n;     while (true) {       if (R - L + 1 > 70) {         long long M = (L + R) / 2;         if (check(L, M))           R = M;         else           L = M + 1;       } else {         long long p = rand() % (R - L + 1) + L;         check(p, p);       }       L = max(1LL, L - K);       R = min(n, R + K);     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       oblivious();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 110000;   int n, q;   map<pair<int, int>, int> M;   int u[maxn], v[maxn];   int s[maxn], e[maxn];   vector<int> V[maxn << 4];   struct DSU {     int fa[maxn], col[maxn], sz[maxn];     stack<pair<pair<int *, int>, int>> stk;     int findfa(int x, int &val) {       val ^= col[x];       return x == fa[x] ? x : findfa(fa[x], val);     }     void init() {       for (int i = 1; i <= n; i++) fa[i] = i, col[i] = 0, sz[i] = 1;     }     bool dsunion(int x, int y, int t) {       int cx = 0, cy = 0;       int fx = findfa(x, cx), fy = findfa(y, cy);       if (fx == fy) return cx ^ cy;       if (sz[fx] > sz[fy]) swap(fx, fy);       stk.push({{&fa[fx], fa[fx]}, t});       fa[fx] = fy;       stk.push({{&sz[fy], sz[fy]}, t});       sz[fy] += sz[fx];       stk.push({{&col[fx], col[fx]}, t});       col[fx] = cx ^ cy ^ 1;       return 1;     }     void goback(int t) {       while (!stk.empty()) {         if (stk.top().second != t) break;         (*stk.top().first.first) = stk.top().first.second;         stk.pop();       }     }   } dsu;   void Add(int L, int R, int val, int l, int r, int rt) {     if (L <= l && R >= r) {       V[rt].push_back(val);       return;     }     int m = (l + r) >> 1;     if (L <= m) Add(L, R, val, l, m, rt << 1);     if (R > m) Add(L, R, val, m + 1, r, rt << 1 | 1);   }   void solve(int l, int r, int rt) {     for (int i = 0; i < V[rt].size(); i++) {       int _ = V[rt][i];       if (!dsu.dsunion(u[_], v[_], rt)) {         for (int j = l; j <= r; j++) puts( NO );         dsu.goback(rt);         return;       }     }     if (l == r)       puts( YES );     else {       int m = (l + r) >> 1;       solve(l, m, rt << 1);       solve(m + 1, r, rt << 1 | 1);     }     dsu.goback(rt);   }   int main() {     int cnt = 0;     scanf( %d%d , &n, &q);     dsu.init();     for (int i = 1; i <= q; i++) {       int uu, vv;       scanf( %d%d , &uu, &vv);       if (!M.count({uu, vv})) {         ++cnt;         u[cnt] = uu, v[cnt] = vv;         M[{uu, vv}] = cnt;         s[cnt] = i;       } else {         e[M[{uu, vv}]] = i - 1;         M.erase({uu, vv});       }     }     for (auto it = M.begin(); it != M.end(); it++) e[it->second] = q;     for (int i = 1; i <= cnt; i++) Add(s[i], e[i], i, 1, q, 1);     solve(1, q, 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 20;   char s1[N], s2[N], ans[N];   int main() {     scanf( %s%s , s1, s2);     int n1 = strlen(s1), cnt = 0;     ans[cnt++] = s1[0];     for (int i = 1; i < n1; i++) {       if (s1[i] >= s2[0]) break;       ans[cnt++] = s1[i];     }     ans[cnt++] = s2[0];     printf( %s n , ans);     return 0;   }