malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r, id;     bool operator<(const node& nd) const {       return l == nd.l ? r > nd.r : l < nd.l;     }   } a[300010];   int main() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); ++i) {       scanf( %d%d , &a[i].l, &a[i].r);       a[i].id = i;     }     sort(a, a + n);     int idx = 0;     for (int i = (1); i < (n); ++i) {       if (a[i].r <= a[idx].r) {         printf( %d %d n , a[i].id + 1, a[idx].id + 1);         return 0;       } else {         idx = i;       }     }     puts( -1 -1 );     return 0;   }
#include <bits/stdc++.h>   int perm[100010 + 1];   using namespace std;   int main() {     int n;     cin >> n;     int s = 1;     int e = n;     while (e - s > 0) {       perm[s] = s + 1;       perm[s + 1] = e;       perm[e] = e - 1;       perm[e - 1] = s;       s += 2;       e -= 2;     }     if (s == e) perm[s] = s;     if ((n % 4) > 1)       cout << -1;     else       for (int i = 1; i <= n; i++) cout << perm[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, cnt, head[N], vis[N], in[N], u, v, ans, op[N];   int idx, dfn[N], g[N], f[N];   struct edge {     int v, nxt;   } e[N];   void add(int u, int v) {     e[++cnt] = (edge){v, head[u]};     head[u] = cnt;   }   int dfs(int u) {     vis[u] = in[u] = 1;     for (int i = head[u], v; v = e[i].v, i; i = e[i].nxt)       if (in[v] || (!vis[v] && !dfs(v))) return 0;     return in[dfn[++idx] = u] = 0, 1;   }   int main() {     cin >> n >> m;     for (int i = (1); i <= (m); i++) scanf( %d%d , &u, &v), add(u, v);     for (int i = (1); i <= (n); i++)       if (!vis[i] && !dfs(i)) return puts( -1 ), 0;     memset(g, 0x3f, sizeof g), memset(f, 0x3f, sizeof f);     for (int j = (1); j <= (n); j++)       for (int i = head[dfn[j]], v; v = e[i].v, i; i = e[i].nxt)         g[dfn[j]] = min(g[dfn[j]], min(v, g[v]));     for (int j = (n); j >= (1); j--)       for (int i = head[dfn[j]], v; v = e[i].v, i; i = e[i].nxt)         f[v] = min(f[v], min(dfn[j], f[dfn[j]]));     for (int i = (1); i <= (n); i++)       if (min(g[i], f[i]) > i) ans++, op[i] = 1;     cout << ans << endl;     for (int i = (1); i <= (n); i++) putchar(op[i] ?  A  :  E );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 122;   string s[N];   bool eq[N];   vector<int> g[30];   int used[N];   string ans;   void dfs(int x) {     used[x] = 1;     for (int to : g[x]) {       if (!used[to]) {         dfs(to);       } else if (used[to] == 1) {         puts( Impossible );         exit(0);       }     }     used[x] = 2;     ans += x +  a ;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       cin >> s[i];     }     fill(eq, eq + N, 1);     for (int j = 0; j < N; ++j) {       for (int i = 1; i < n; ++i) {         if (s[i].size() > j && eq[i]) {           if (s[i - 1].size() > j) {             if (s[i - 1][j] != s[i][j]) {               g[s[i - 1][j] -  a ].push_back(s[i][j] -  a );               eq[i] = 0;             } else {               eq[i] = 1;             }           } else {             eq[i] = 0;           }         } else if (eq[i]) {           puts( Impossible );           return 0;         } else {           eq[i] = 0;         }       }     }     for (int i = 0; i < 26; ++i) {       if (!used[i]) {         dfs(i);       }     }     reverse(ans.begin(), ans.end());     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p1, p2, p3, p4, a, b;   int fun(int x) { return x % p1 % p2 % p3 % p4; }   int main() {     while (~scanf( %d%d%d%d%d%d , &p1, &p2, &p3, &p4, &a, &b)) {       int cnt = 0;       for (int i = a; i <= b; i++) {         if (fun(i) == i) cnt++;       }       printf( %d n , cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void main2() {     long long int n, m, sum = 0, t = INT_MAX, temp, r = 0;     cin >> n >> m;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         cin >> temp;         if (temp < 0) r++;         sum += abs(temp);         t = min(t, abs(temp));       }     }     if (r % 2 == 0)       cout << sum <<   n ;     else       cout << sum - 2 * t <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       main2();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     if ((n - 2) % 3 == 0) {       cout <<  1             <<                <<  2             <<     << n - 3 << endl;     } else {       cout <<  1             <<                <<  1             <<     << n - 2 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> lucky;   long long int l, r;   void gen(long long int a) {     if (a <= 1e11) lucky.push_back(a);     if (a * 10 + 4 <= 1e11) gen(a * 10 + 4);     if (a * 10 + 7 <= 1e11) gen(a * 10 + 7);   }   void solve() {     cin >> l >> r;     gen(4);     gen(7);     sort(lucky.begin(), lucky.end());     if (l == r) {       cout << *lower_bound(lucky.begin(), lucky.end(), l);       return;     }     long long int lb = lower_bound(lucky.begin(), lucky.end(), l) - lucky.begin();     long long int ans = (min(r, lucky[lb]) - l + 1) * lucky[lb], i;     for (i = lb + 1; lucky[i] <= r; i++) {       ans += (lucky[i] - lucky[i - 1]) * lucky[i];     }     i--;     if (lucky[i] < r) {       ans += (r - lucky[i]) * lucky[i + 1];     }     cout << ans;   }   int32_t main() {     ios::sync_with_stdio(false);     long long int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int N, S, M, K;   int A[2020], B[2020];   int L[2020], R[2020];   vector<int> V;   int MR[2020];   int dp[1600][1600];   int ok(int v) {     int i, j;     for (i = 0; i < (N); i++) B[i + 1] = B[i] + (A[i] <= v);     memset(dp, 0, sizeof(dp));     for (i = 0; i < (N); i++) {       for (j = 0; j < (M); j++) {         if (MR[i] > i) {           dp[MR[i]][j + 1] = max(dp[MR[i]][j + 1], dp[i][j] + B[MR[i]] - B[i]);           if (dp[MR[i]][j + 1] >= K) return 1;         }         dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);       }     }     return 0;   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> S >> M >> K;     for (i = 0; i < (N); i++) {       cin >> A[i];       V.push_back(A[i]);     }     for (i = 0; i < (S); i++) {       cin >> L[i] >> R[i];       for (j = L[i] - 1; j < R[i]; j++) MR[j] = max(MR[j], R[i]);     }     sort((V.begin()), (V.end()));     V.erase(unique((V.begin()), (V.end())), V.end());     if (ok(V.back()) == 0) return (void)printf( -1 n );     int ret = V.size() - 1;     for (i = 12; i >= 0; i--) {       if (ret >= (1 << i) && ok(V[ret - (1 << i)])) ret -= 1 << i;     }     cout << V[ret] << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7fffffff;   const int maxn = 2e5 + 5;   int bit[2][maxn], num[maxn];   int n, k, a, b, q;   void update(int id, int x, int v) {     while (x <= n) {       bit[id][x] += v;       x += (x & -x);     }   }   int sum(int id, int x) {     int ans = 0;     while (x) {       ans += bit[id][x];       x -= x & -x;     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> a >> b >> q;     int x, y, z;     while (q--) {       cin >> x;       if (x == 1) {         cin >> y >> z;         if (num[y] + z < b) {           update(0, y, z);           update(1, y, z);         } else if (num[y] + z < a) {           if (num[y] < b) update(0, y, b - num[y]);           update(1, y, z);         } else {           if (num[y] < b) update(0, y, b - num[y]);           if (num[y] < a) update(1, y, a - num[y]);         }         num[y] += z;       } else {         cin >> y;         int ans = sum(0, y - 1) + sum(1, n) - sum(1, y + k - 1);         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005], c[100005];   int main() {     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       c[i] = c[i - 1] + 20;       long long x = upper_bound(a + 1, a + 1 + n, a[i] - 90) - a;       c[i] = min(c[i], c[x - 1] + 50);       x = upper_bound(a + 1, a + 1 + n, a[i] - 1440) - a;       c[i] = min(c[i], c[x - 1] + 120);     }     for (int i = 1; i <= n; i++) {       cout << c[i] - c[i - 1] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;   int n;   char s[N][10];   int val[N];   int l[N], r[N];   set<int> st[N];   void go(int u, int v) {     if (st[v].size() > st[u].size()) {       st[u].swap(st[v]);     }     for (int x : st[v]) st[u].insert(x);     set<int>().swap(st[v]);   }   void dfs(int u) {     if (*s[u] ==  I ) {       st[u].insert(u);       return;     }     if (*s[u] ==  N ) {       int v = l[u];       dfs(v);       val[u] = !val[v];       go(u, v);     } else if (*s[u] ==  A ) {       int v1 = l[u], v2 = r[u];       dfs(v1);       dfs(v2);       val[u] = val[v1] & val[v2];       if (val[u] != ((val[v1] ^ 1) & val[v2])) {         go(u, v1);       }       if (val[u] != (val[v1] & (val[v2] ^ 1))) {         go(u, v2);       }     } else if (*s[u] ==  O ) {       int v1 = l[u], v2 = r[u];       dfs(v1);       dfs(v2);       val[u] = val[v1] | val[v2];       if (val[u] != ((val[v1] ^ 1) | val[v2])) {         go(u, v1);       }       if (val[u] != (val[v1] | (val[v2] ^ 1))) {         go(u, v2);       }     } else {       int v1 = l[u], v2 = r[u];       dfs(v1);       dfs(v2);       val[u] = val[v1] ^ val[v2];       if (val[u] != ((val[v1] ^ 1) ^ val[v2])) {         go(u, v1);       }       if (val[u] != (val[v1] ^ (val[v2] ^ 1))) {         go(u, v2);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %s , s[i]);       if (*s[i] ==  I ) {         scanf( %d , val + i);       } else if (*s[i] ==  N ) {         scanf( %d , l + i);       } else {         scanf( %d%d , l + i, r + i);       }     }     dfs(1);     for (int i = 1; i <= n; ++i) {       if (*s[i] ==  I ) {         printf( %d , val[1] ^ (st[1].count(i)));       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool smin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <typename T>   inline bool smax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const long long N = 3e5 + 10;   long long n, bad[N], m;   vector<long long> adj[N];   bool pos[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     while (m--) {       long long u, v;       cin >> u >> v;       adj[v].push_back(u);       adj[u].push_back(v);     }     set<pair<long long, long long> > s;     for (long long i = 1; i <= n; i++)       bad[i] = (long long)adj[i].size(), s.insert({bad[i], i});     while (1) {       pair<long long, long long> pi = *s.rbegin();       s.erase(pi);       long long v = pi.second;       if (bad[v] < 2) break;       bad[v] = (long long)adj[v].size() - bad[v];       for (long long u : adj[v]) {         s.erase({bad[u], u});         if (pos[u] == pos[v]) {           bad[u]--;         } else {           bad[u]++;         }         s.insert({bad[u], u});       }       pos[v] ^= 1;       s.insert({bad[v], v});     }     for (long long i = 1; i <= n; i++) cout << pos[i];   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int arr[maxn];   int main() {     int n;     scanf( %d , &n);     int pos = n;     cout << 1 << endl;     for (int i = 1; i <= n; i++) {       int tmp;       scanf( %d , &tmp);       arr[tmp] = 1;       while (arr[pos]) pos--;       printf(  %d , i - (n - pos) + 1);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long pw(long long a, long long b, long long p) {     if (b == 0) return 1;     long long t = pw(a, b / 2, p);     if (b % 2)       return ((a * t * t) % p);     else       return ((t * t) % p);   }   map<long long, pair<long long, long long> > m;   long long b[100005];   void solve() {     long long n, k;     cin >> n >> k;     long long a[n];     for (long long i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     for (long long j = 1; j <= n; j++) {       long long i = a[j];       b[j] = i;       b[j] += b[j - 1];       m[i].first++;       if (m[i].first == 1) m[i].second = j;     }     long long mx = 0, mn = -1;     for (auto z : m) {       long long lmx = 0;       lmx += z.second.first;       long long u = z.second.second, l = 0, f = u - 1;       while (u >= l) {         long long mid = (l + u) / 2;         long long ss = b[z.second.second - 1] - b[mid];         ss = z.first * (z.second.second - mid - 1) - ss;         if (k < ss) {           l = mid + 1;         }         if (k >= ss) {           f = mid;           u = mid - 1;         }       }       lmx += z.second.second - f - 1;       if (lmx > mx) {         mx = lmx;         mn = z.first;       }     }     cout << mx <<     << mn;   }   signed main() {     ios_base::sync_with_stdio(false);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, k;   char a[5][500];   bool vis[5][500], check;   bool valid(int x, int y) {     if (x < 0 || x > 2 || vis[x][y]) return 0;     return 1;   }   void dfs(int x, int y, int tm) {     if (!valid(x, y) || check) return;     if (a[x][y + 2 * tm] !=  . ) return;     vis[x][y] = 1;     if (y >= n - 1) {       check = 1;       return;     }     if (a[x][y + 2 * tm + 1] !=  . ) return;     dfs(x, y + 1, tm + 1);     if (a[x + 1][y + 1 + 2 * tm] ==  . ) dfs(x + 1, y + 1, tm + 1);     if (a[x - 1][y + 1 + 2 * tm] ==  . ) dfs(x - 1, y + 1, tm + 1);   }   int main() {     cin >> t;     while (t--) {       check = 0;       memset(vis, 0, sizeof(vis));       for (int i = 0; i < 4; i++)         for (int j = 0; j < 500; j++) a[i][j] =  . ;       cin >> n >> k;       for (int i = 0; i < 3; i++)         for (int j = 0; j < n; j++) cin >> a[i][j];       int p;       for (int i = 0; i < 3; i++)         if (a[i][0] ==  s ) p = i;       a[p][0] =  . ;       dfs(p, 0, 0);       if (check)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma hdrstop   using namespace std;   void rot(int n, int *x, int *y, int rx, int ry);   int xy2d(int n, int x, int y) {     int rx, ry, s, d = 0;     for (s = n / 2; s > 0; s /= 2) {       rx = (x & s) > 0;       ry = (y & s) > 0;       d += s * s * ((3 * rx) ^ ry);       rot(s, &x, &y, rx, ry);     }     return d;   }   void d2xy(int n, int d, int *x, int *y) {     int rx, ry, s, t = d;     *x = *y = 0;     for (s = 1; s < n; s *= 2) {       rx = 1 & (t / 2);       ry = 1 & (t ^ rx);       rot(s, x, y, rx, ry);       *x += s * rx;       *y += s * ry;       t /= 4;     }   }   void rot(int n, int *x, int *y, int rx, int ry) {     int t;     if (ry == 0) {       if (rx == 1) {         *x = n - 1 - *x;         *y = n - 1 - *y;       }       t = *x;       *x = *y;       *y = t;     }   }   #pragma argsused   int main(int argc, char *argv[]) {     int a, b;     cin >> a >> b;     int x, y;     d2xy(1 << a, b, &x, &y);     cout << x <<     << y << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Read(int &p) {     p = 0;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) p = p * 10 + c -  0 ;   }   int n, k;   struct Node {     long long siz;     int mxx[12], mnn[12];     bool operator<(const Node &b) const {       for (int i = 1; i <= k; i++)         if (mxx[i] > b.mnn[i]) return 0;       return 1;     }   } S;   set<Node> M;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       S.siz = 1;       for (int j = 1; j <= k; j++) {         int x;         Read(x);         S.mnn[j] = S.mxx[j] = x;       }       set<Node>::iterator it = M.find(S);       while (it != M.end()) {         S.siz += it->siz;         for (int j = 1; j <= k; j++) {           S.mxx[j] = max(S.mxx[j], it->mxx[j]);           S.mnn[j] = min(S.mnn[j], it->mnn[j]);         }         M.erase(it);         it = M.find(S);       }       M.insert(S);       printf( %lld n , M.rbegin()->siz);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, ind, mini(1000000000);   int t[11];   string ans =   ;   char chr(int x) { return char( 0  + x); }   int main() {     cin >> n;     for (int i = 1; i < 10; i++) {       cin >> t[i];       if (t[i] <= mini) {         mini = t[i];         ind = i;       }     }     if (mini > n) {       cout << -1;       return 0;     }     while (n - mini >= 0) {       ans += chr(ind);       n -= mini;     }     for (int i = 0; i < (int)ans.size(); i++) {       for (int j = 9; j > ind; j--) {         if (n - t[j] + mini >= 0) {           ans[i] = chr(j);           n -= t[j] - mini;           break;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int nax = 500000 + 10;   int arr[nax], color[nax];   vector<int> graph[nax];   map<int, set<int> > map1;   int main() {     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> color[i];     while (m--) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       for (auto x : graph[i]) {         if (color[i] != color[x]) map1[color[i]].insert(color[x]);       }     }     int maxi = map1[color[1]].size(), ans = color[1];     for (int i = 2; i <= n; i++) {       if (map1[color[i]].size() == maxi && color[i] < ans) {         ans = color[i];       } else if (map1[color[i]].size() > maxi) {         maxi = map1[color[i]].size();         ans = color[i];       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 200001;   const long long int MOD = 1000000007;   long long int N = 1, c[M], i, j, N2, m;   bool flag;   int main() {     cin >> m;     fill(c, c + M, 1);     while (m--) {       int p;       cin >> p;       c[p]++;       N *= p, N %= MOD;     }     for (i = 1; i < M; i++)       if (c[i] % 2 == 0 && !flag) {         c[i] /= 2, flag = true;         break;       }     if (!flag) {       N = 1;       for (i = 1; i < M; i++)         for (j = 1; j * 2 < c[i]; j++) N *= i, N %= MOD;     }     for (i = 1; i < M; i++) {       N2 = N;       for (j = 1; j < c[i]; j++) N *= N2, N %= MOD;     }     cout << N << endl;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, int> mp;   int x[2005], y[2005];   int main() {     int n, ans = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , x + i, y + i);       for (int j = 0; j < i; j++) ans += mp[{x[i] + x[j], y[i] + y[j]}]++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, T, fa[500005], top, st[500005 << 2], d[500005], a[500005];   struct E {     int x, y, l, r;   } e[500005];   int Getfa(int x) {     while (fa[x] != x) x = fa[x];     return x;   }   int col(int x) {     int now = 0;     while (fa[x] != x) now ^= a[x], x = fa[x];     return now;   }   void link(int x, int y, int D) {     if (d[x] > d[y]) swap(x, y);     if (d[x] == d[y]) d[y]++, st[++top] = -y;     fa[x] = y;     a[x] = D;     st[++top] = x;   }   void RE(int t) {     for (; top > t; top--)       if (st[top] < 0)         d[-st[top]]--;       else         fa[st[top]] = st[top], a[st[top]] = 0;   }   void work(int l, int r, int k) {     int mid = (l + r) >> 1, now = top;     for (int i = 1; i <= k; i++)       if (e[i].l <= l && r <= e[i].r) {         int u = Getfa(e[i].x), v = Getfa(e[i].y);         if (u != v)           link(u, v, col(e[i].x) == col(e[i].y));         else if (col(e[i].x) == col(e[i].y)) {           for (int i = l; i <= r; i++) puts( NO );           RE(now);           return;         }         swap(e[k--], e[i--]);       }     if (l == r)       puts( YES );     else {       int i, j;       for (i = 1, j = 0; i <= k; i++)         if (e[i].l <= mid) swap(e[i], e[++j]);       work(l, mid, j);       for (i = 1, j = 0; i <= k; i++)         if (e[i].r > mid) swap(e[i], e[++j]);       work(mid + 1, r, j);     }     RE(now);   }   map<int, int> M[500005];   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= T; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (x > y) swap(x, y);       if (M[x][y])         e[M[x][y]].r = i - 1, M[x][y] = 0;       else {         M[x][y] = ++m;         e[m].x = x;         e[m].y = y;         e[m].l = i - 1;         e[m].r = T;       }     }     for (int i = 1; i <= m; i++) {       if (++e[i].l > e[i].r) {         i--, m--;         assert(false);       }     }     for (int i = 1; i <= n; i++) fa[i] = i, d[i] = 1;     work(1, T, m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[100010];   int main() {     cin >> n >> m;     scanf( %s , s + 1);     while (m--) {       int l, r;       cin >> l >> r;       char a[2], b[2];       scanf( %s%s , a, b);       for (int i = l; i <= r; i++)         if (s[i] == a[0]) s[i] = b[0];     }     printf( %s , s + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   bool vis[N][N];   int n, ai, aj;   bool can(int i, int j) {     if (ai == i || aj == j || i + j == ai + aj || i - j == ai - aj) return 0;     return (i <= n && i >= 1 && j <= n && j >= 1);   }   int bi, bj, ci, cj;   int di[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dj[] = {1, -1, 0, 1, -1, 0, 1, -1};   void dfs(int i, int j) {     if (!can(i, j) || vis[i][j]) return;     vis[i][j] = 1;     for (int z = 0; z < 8; ++z) dfs(i + di[z], j + dj[z]);   }   int main() {     cin >> n >> ai >> aj >> bi >> bj >> ci >> cj;     dfs(bi, bj);     if (vis[ci][cj])       puts( YES );     else       puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long int> v;     long long int n, num, max_ind = 0, max_num = -1;     cin >> n;     for (long long int i = 0; i < n; i++) {       cin >> num;       v.push_back(num);       if (num > max_num) {         max_num = num;         max_ind = i;       }     }     if (max_num != 1)       v[max_ind] = 1;     else       v[max_ind] = 2;     sort(v.begin(), v.end());     for (long long int i = 0; i < n; i++) {       cout << v[i] <<    ;     }     return 0;   }