malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const double INF = 1e12, EPS = 1e-9;   const int B = 2000;   const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};   int h, w, q;   int qs[100000][4];   char in[100010][12], dir[256];   int dp[100010 * 12], vis[100010][12];   inline int to(int y, int x) {     int &res = dp[y * 12 + x];     if (res != -1) return res;     if (y == 0 || x == 0 || x == w + 1) return res = y * 12 + x;     res = -2;     int d = dir[in[y][x]];     return res = to(y + dy[d], x + dx[d]);   }   int main() {     dir[ < ] = 1;     dir[ ^ ] = 0;     dir[ > ] = 3;     scanf( %d%d%d , &h, &w, &q);     for (int i = 0; i < (int)h; i++) scanf( %s , in[i + 1] + 1);     for (int i = 0; i < (int)q; i++) {       char c, d;       int y, x;       scanf(  %c%d%d , &c, &y, &x);       qs[i][0] = c ==  A ;       qs[i][1] = y;       qs[i][2] = x;       if (c ==  C ) {         scanf(  %c , &d);         qs[i][3] = d;       }     }     memset(vis, -1, sizeof(vis));     for (int it = 0; it < (int)q; it++) {       if (it % B == 0) {         memset(dp, -1, sizeof(dp));         for (int i = it; i < it + B && i < q; i++)           if (qs[i][0] == 0) {             int y = qs[i][1], x = qs[i][2];             dp[y * 12 + x] = y * 12 + x;           }       }       int y = qs[it][1], x = qs[it][2];       if (!qs[it][0]) {         in[y][x] = (char)qs[it][3];         continue;       }       while (1) {         if (x == 0 || x == w + 1 || y == 0) {           printf( %d %d n , y, x);           break;         }         if (vis[y][x] == it) {           puts( -1 -1 );           break;         }         vis[y][x] = it;         int ny = to(y, x), nx;         if (ny < 0) {           puts( -1 -1 );           break;         }         nx = ny % 12;         ny /= 12;         if (nx == 0 || nx == w + 1 || ny == 0) {           printf( %d %d n , ny, nx);           break;         }         int d = dir[in[ny][nx]];         y = ny + dy[d];         x = nx + dx[d];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 350;   const long long PHI = (long long)998244352;   const long long INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long long MOD = (long long)998244353;   const long long OVER_FLOW = 0x7fffffff;   const long long LOVER_FLOW = 0x7fffffffffffffff;   long long n;   struct op {     long long x1, y1, x2, y2;   };   long long vis[MAXN][MAXN];   vector<op> res;   string str;   void add(long long x1, long long y1, long long x2, long long y2) {     res.push_back((op){x1, y1, x2, y2});     vis[x2][y2]++;   }   void move(long long x1, long long y1, bool x) {     if (x) {       if (x1 != 1) {         add(x1, y1, 1, y1);       } else {         add(x1, y1, 1, y1 == 1 ? 2 : 1);       }     } else {       if (x1 != 2) {         add(x1, y1, 2, y1);       } else {         add(x1, y1, 2, y1 == 1 ? 2 : 1);       }     }   }   int main() {     ios::sync_with_stdio(false);     long long m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         cin >> str;         for (long long k = str.size() - 1; k >= 0; k--) {           move(i, j, str[k] ==  1 );         }       }     }     for (long long i = 1; i <= 2; i++) {       for (long long j = 2; j <= m; j++) {         while (vis[i][j]) {           add(i, j, i, 1);           vis[i][j]--;         }       }     }     long long cnt = res.size();     memset(vis, 0, sizeof vis);     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         cin >> str;         for (auto k : str) {           move(i, j, k ==  1 );         }       }     }     for (long long i = 1; i <= 2; i++) {       for (long long j = 2; j <= m; j++) {         while (vis[i][j]) {           add(i, j, i, 1);           vis[i][j]--;         }       }     }     cout << res.size() <<   n ;     for (long long i = 0; i < cnt; i++) {       cout << res[i].x1 <<     << res[i].y1 <<     << res[i].x2 <<                << res[i].y2 <<   n ;     }     for (long long i = res.size() - 1; i >= cnt; i--) {       cout << res[i].x2 <<     << res[i].y2 <<     << res[i].x1 <<                << res[i].y1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   long long k, L, R, a[2222222], b[2222222], ans, sum[2222222];   int n, r;   long long min(long long a, long long b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   bool check(long long x) {     long long ans = 0, now = 0;     memset(b, 0, sizeof(b));     for (int i = 1; i <= n; i++) {       now += b[i];       if (a[i] + now < x)         ans += x - a[i] - now, b[i + 2 * r + 1] -= x - a[i] - now,             now += x - a[i] - now;       if (ans > k) return 0;     }     return 1;   }   int main() {     scanf( %d%d%lld , &n, &r, &k);     L = 2e18;     for (int i = 1; i <= n; i++)       scanf( %lld , &sum[i]), L = min(L, sum[i]), sum[i] += sum[i - 1];     for (int i = 1; i <= n; i++)       a[i] = sum[min(i + r, n)] - sum[max(0, i - r - 1)];     R = 1e20;     while (L <= R) {       long long mid = L + R >> 1;       if (check(mid))         L = mid + 1, ans = mid;       else         R = mid - 1;     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<long long> a(n);     vector<int> nx(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     map<long long, int> mp;     long long sig = 0;     for (int i = 0; i < 3 * n; i++) {       int ri = (i % n);       nx[mp[sig]] = ri;       mp[sig] = ri;       sig += a[ri];     }     int res = n;     for (int i = 0; i < n; i++) {       int len = 1, p = nx[i];       if (p == -1) {         continue;       }       nx[i] = -1;       while (p != i) {         len++;         int np = nx[p];         nx[p] = -1;         p = np;       }       res = min(n - len, res);     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, t;     cin >> n >> t;     long long int A[n];     for (long long int i = 0; i < n; i++) {       cin >> A[i];     }     long long int cnt = 0;     long long int sum = 0;     long long int i = 0;     long long int j = 0;     for (i = 0; i < n; i++) {       sum += A[i];       if (sum <= t) {         cnt++;       } else {         sum -= A[j];         j++;       }     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   int nnext[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};   long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }   int main() {     int n, m, k, idx, x, y, now, have, array[350][350];     cin >> n >> m >> k, x = y = 1, idx = now = have = 0;     vector<vector<pair<int, int> > > ans(k);     while (k) {       if (k == 1) {         if (y > m)           x++, y = m, now = 1;         else if (!y)           x++, y = 1, now = 0;         ans[idx].push_back(make_pair(x, y)), have++;         if (have == n * m) break;         if (!now)           y++;         else           y--;         continue;       } else {         ans[idx].push_back(make_pair(x, y)), have++;         if (!now)           y++;         else           y--;         if (y > m)           x++, y = m, now = 1;         else if (!y)           x++, y = 1, now = 0;       }       if (ans[idx].size() == 2) idx++, k--;     }     for (int i = 0; i < int(ans.size()); i++) {       cout << ans[i].size() <<    ;       for (int j = 0; j < int(ans[i].size()); j++)         cout << ans[i][j].first <<     << ans[i][j].second <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long BINF = 9e18, LINF = 2e9, mod = 998244353, P = 179,                   Q = 1791791791;   const long long MAXN = 1e4 + 7;   long long a[MAXN], b[MAXN], c[MAXN];   vector<pair<long long, long long>> g[MAXN];   bool cmp(vector<pair<long long, long long>> &a,            vector<pair<long long, long long>> &b) {     return a.size() < b.size();   }   struct way {     long long a, b, c;   };   vector<way> ways;   long long h[MAXN];   long long c1[MAXN], c2[MAXN];   long long f[MAXN];   long long tin[MAXN], tout[MAXN];   long long par[MAXN];   long long timer = 0;   void dfs(long long v, long long p = -1, long long pc = -1) {     par[v] = p;     h[v] = (p == -1 ? 0 : h[p] + 1);     tin[v] = timer++;     if (g[v].size() == 1 && p != -1) {       long long u, c;       for (pair<long long, long long> e : g[v])         if (e.first != p) u = e.first, c = e.second;       if (pc != c) {         cout <<  NO ;         exit(0);       }       dfs(u, p, pc);       return;     }     for (pair<long long, long long> e : g[v]) {       if (e.first == p) continue;       dfs(e.first, v, e.second);       if (c1[v] == -1)         c1[v] = f[e.first];       else if (c2[v] == -1)         c2[v] = f[e.first];       f[v] = f[e.first];     }     tout[v] = timer++;     if (p != -1) ways.push_back(way{p, v, pc});     if (g[v].size() == 0) f[v] = c1[v] = c2[v] = v;   }   void dfsd(long long v, long long p = -1) {     long long ps = -1;     for (long long i = 0; i < g[v].size(); ++i) {       if (g[v][i].first == p)         ps = i;       else         dfsd(g[v][i].first, v);     }     if (ps != -1) g[v].erase(g[v].begin() + ps);   }   vector<way> answ;   void add(long long a, long long b, long long c) {     if (a == b) return;     answ.push_back({a, b, c});   }   long long lca(long long a, long long b) {     if (h[a] < h[b]) swap(a, b);     while (h[a] > h[b]) a = par[a];     while (a != b) a = par[a], b = par[b];     return a;   }   long long dist(long long a, long long b) {     return h[a] + h[b] - 2 * h[lca(a, b)];   }   void solve() {     long long n;     cin >> n;     fill(c1, c1 + n, -1);     fill(c2, c2 + n, -1);     for (long long i = 0; i < n - 1; ++i) {       cin >> a[i] >> b[i] >> c[i];       --a[i];       --b[i];       g[a[i]].push_back({b[i], c[i]});       g[b[i]].push_back({a[i], c[i]});     }     long long root = min_element(g, g + n, cmp) - g;     dfsd(root, -1);     dfs(root);     for (way w : ways) {       if (h[w.a] > h[w.b]) swap(w.a, w.b);       long long lul = c1[w.a];       if (dist(lul, w.b) != dist(lul, w.a) + dist(w.a, w.b)) lul = c2[w.a];       if (lul == -1) lul = root;       add(c1[w.b], c2[w.b], -(w.c / 2));       add(root, lul, -(w.c / 2));       add(root, c1[w.b], w.c / 2);       add(lul, c2[w.b], w.c / 2);     }     cout <<  YES n ;     cout << answ.size() <<   n ;     for (way w : answ) cout << w.a + 1 <<     << w.b + 1 <<     << w.c <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     cout.precision(40);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 202000;   int n, m;   struct edge {     int u, v, w;   } edges[maxn];   int pre[maxn];   vector<edge> vec;   int found(int x) {     int rx = x;     while (pre[rx] != rx) rx = pre[rx];     while (pre[x] != rx) {       int tmp = pre[x];       pre[x] = rx;       x = tmp;     }     return rx;   }   int cmp(edge alpha, edge beta) { return alpha.w < beta.w; }   void read() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &edges[i].u, &edges[i].v, &edges[i].w);     sort(edges + 1, edges + m + 1, cmp);   }   void work() {     int ans = 0;     for (int i = 1; i <= n; i++) pre[i] = i;     for (int i = 1; i <= m;) {       int j = i;       vec.clear();       while (edges[i].w == edges[j].w) {         if (found(edges[j].u) == found(edges[j].v)) {           j++;           continue;         }         vec.push_back(edges[j]);         j++;       }       for (int k = 0; k < vec.size(); k++) {         if (found(vec[k].u) == found(vec[k].v))           ans++;         else           pre[found(vec[k].u)] = found(vec[k].v);       }       i = j;     }     printf( %d n , ans);   }   int main() {     read();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 18) + 100;   const int maxnode = maxn << 2;   int n, ai[maxn + 5];   int ls[maxnode + 5], rs[maxnode + 5];   int re[maxnode + 5], sp[maxnode + 5];   long long sum[maxnode + 5];   void Build(int x, int l, int r) {     re[x] = sp[x] = 0;     ls[x] = x << 1, rs[x] = x << 1 | 1;     if (l == r) {       sum[x] = ai[l];       return;     }     int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1;     Build(lson, l, mid);     Build(rson, mid + 1, r);     sum[x] = sum[lson] + sum[rson];   }   void Replace(int d, int x, int l, int r, int p, int v) {     if (l == r) {       sum[x] = v;       return;     }     int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1;     if (re[x] >> d & 1) {       re[x] ^= (1 << d), sp[x] ^= (1 << d), re[lson] ^= (1 << (d + 1)),           re[rson] ^= (1 << (d + 1));     }     if (sp[x] >> d & 1) {       sp[x] ^= (1 << d), swap(lson, rson);     }     re[lson] ^= re[x], re[rson] ^= re[x], re[x] = 0;     sp[lson] ^= sp[x], sp[rson] ^= sp[x], sp[x] = 0;     if (p <= mid)       Replace(d + 1, lson, l, mid, p, v);     else       Replace(d + 1, rson, mid + 1, r, p, v);     sum[x] = sum[lson] + sum[rson];   }   long long Sum(int d, int x, int l, int r, int ll, int rr) {     if (ll <= l && r <= rr) return sum[x];     int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1;     long long res = 0;     if (re[x] >> d & 1) {       re[x] ^= (1 << d), sp[x] ^= (1 << d), re[lson] ^= (1 << (d + 1)),           re[rson] ^= (1 << (d + 1));     }     if (sp[x] >> d & 1) {       sp[x] ^= (1 << d), swap(lson, rson);     }     re[lson] ^= re[x], re[rson] ^= re[x], re[x] = 0;     sp[lson] ^= sp[x], sp[rson] ^= sp[x], sp[x] = 0;     if (ll <= mid) res += Sum(d + 1, lson, l, mid, ll, rr);     if (mid < rr) res += Sum(d + 1, rson, mid + 1, r, ll, rr);     return res;   }   int main() {     int _;     scanf( %d%d , &n, &_);     int pn = n;     n = (1 << n);     for (int i = 1; i <= n; ++i) scanf( %d , ai + i);     Build(1, 1, n);     while (_--) {       int o, x, k, l, r;       scanf( %d , &o);       if (o == 1) {         scanf( %d%d , &x, &k);         Replace(0, 1, 1, n, x, k);       } else if (o == 2) {         scanf( %d , &k);         k = pn - k;         re[1] ^= (1 << k);       } else if (o == 3) {         scanf( %d , &k);         k = pn - 1 - k;         sp[1] ^= (1 << k);       } else {         scanf( %d%d , &l, &r);         long long ans = Sum(0, 1, 1, n, l, r);         printf( %lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; }   inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; }   struct matrix {     double x[128][128];     double *operator[](int a) { return x[a]; }     void clear() { memset(x, 0, sizeof(x)); }     void reset() {       clear();       for (int i = 0; i < 128; ++i) x[i][i] = 1;     }   } p, a, ans;   matrix operator*(matrix &a, matrix &b) {     p.clear();     for (int i = 0; i < 128; i++)       for (int j = 0; j < 128; j++)         for (int k = 0; k < 128; k++) p[i][j] += a[i][k] * b[k][j];     return p;   }   int n, x;   double pos[128];   int main() {     scanf( %d%d , &n, &x);     for (int i = 0; i <= x; ++i) scanf( %lf , &pos[i]);     a.clear();     for (int i = 0; i < 128; ++i)       for (int j = 0; j < 128; ++j) a[i][j] = pos[i ^ j];     ans.reset();     for (; n; n >>= 1, a = a * a)       if (n & 1) ans = ans * a;     printf( %.10f n , 1.0 - double(ans[0][0]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int n, value;     char str[200];     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> str;       if (strcmp(str,  add ) == 0) {         cin >> value;         v.insert(lower_bound(v.begin(), v.end(), value), value);       } else if (strcmp(str,  del ) == 0) {         cin >> value;         v.erase(lower_bound(v.begin(), v.end(), value));       } else if (strcmp(str,  sum ) == 0) {         long long sum = 0;         for (int j = 2; j < v.size(); j += 5) {           sum += v[j];         }         cout << sum << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool read(T &x) {     int c = getchar();     int sgn = 1;     while ((~c && c <  0 ) || c >  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   int X[] = {-1, 0, 1, 0};   int Y[] = {0, 1, 0, -1};   int main() {     int n;     read(n);     int win = 2;     for (int i = 1; i <= n; i++) {       int a;       read(a);       if (a % 2 == 0) {         win = (win == 2) ? 1 : 2;       }       printf( %d n , win);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   set<pair<long long, long long> > st;   int resp[maxn];   struct island {     long long ini, fim;   } isl[maxn];   struct event {     long long type, val, ini;     event() { type = 0, val = 0, ini = 0; }     event(long long a, long long b, long long c) {       type = a;       val = b;       ini = c;     }   } e[2 * maxn];   bool cmp(event a, event b) {     if (a.ini == b.ini && a.type == b.type) return a.val < b.val;     if (a.ini == b.ini) return a.type < b.type;     return a.ini < b.ini;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     long long al, bl;     int siz = 0;     for (int i = 0; i < n; i++) {       long long a, b;       scanf( %I64d %I64d , &a, &b);       if (i != 0) {         isl[i - 1].fim = b - al;         isl[i - 1].ini = a - bl;         int atual = i - 1;         e[siz++] = event(1, atual, isl[i - 1].ini);       }       al = a;       bl = b;     }     for (int i = 0; i < m; i++) {       long long q;       scanf( %I64d , &q);       e[siz++] = event(2, i, q);     }     sort(e, e + siz, cmp);     for (int i = 0; i < siz; i++) {       if (e[i].type == 1) {         st.insert(make_pair(isl[e[i].val].fim, e[i].val));       } else {         set<pair<long long, long long> >::iterator it =             st.lower_bound(make_pair(e[i].ini, -1LL));         if (it != st.end()) {           resp[it->second] = e[i].val;           st.erase(it);         }       }     }     int ok = 1;     if (!st.empty()) ok = 0;     if (ok) {       puts( Yes );       for (int i = 0; i < n - 1; i++) {         printf( %d  , resp[i] + 1);       }       printf(  n );     } else {       puts( No );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[10000], i, sum = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int maxv = a[0];     int minv = a[0];     for (i = 1; i < n; ++i) {       if (maxv < a[i]) {         maxv = a[i];         sum++;       } else if (minv > a[i]) {         minv = a[i];         sum++;       }     }     printf( %d n , sum);   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int s[505][505];   int main() {     scanf( %d%d , &n, &m);     char c = getchar();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         c = getchar();         if (c ==  S )           s[i][j] = 0;         else if (c ==  W )           s[i][j] = 1;         else           s[i][j] = 2;       }       getchar();     }     bool f = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] == 1) {           if (i > 1 && s[i - 1][j] == 0) f = 1;           if (j > 1 && s[i][j - 1] == 0) f = 1;           if (i < n && s[i + 1][j] == 0) f = 1;           if (j < m && s[i][j + 1] == 0) f = 1;         }       }     }     if (f) {       printf( No n );       return 0;     }     printf( Yes n );     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] == 0) {           printf( S );         } else if (s[i][j] == 1)           printf( W );         else           printf( D );       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, j, c = 0, p, q, f = 0;     scanf( %d , &n);     scanf( %d , &p);     int a[p];     for (i = 0; i < p; i++) scanf( %d , &a[i]);     scanf( %d , &q);     int b[q];     for (i = 0; i < q; i++) scanf( %d , &b[i]);     for (i = 1; i <= n; i++) {       f = 0;       for (j = 0; j < p; j++) {         if (a[j] == i) {           c++;           f++;         }       }       if (f == 0) {         for (j = 0; j < q; j++) {           if (b[j] == i) {             c++;           }         }       }     }     if (n == c)       printf( I become the guy. n );     else       printf( Oh, my keyboard! n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000018;   char str[2][510000], text[1010000];   int n, ans[1010000], num_node, fail[1010000], nxt[1010000], len[1010000],       to[1010000][26], path[1010000], pa[1010000];   int dl[1010000], last, save[1010000], ie[1010000];   void init() {     num_node = 2;     fail[0] = 1;     len[1] = -1;     len[0] = 0;     nxt[0] = 1;     last = 0;   }   int get_fail(int id, int pos) {     while (pos - len[id] - 1 < 1 || text[pos - len[id] - 1] != text[pos])       id = fail[id];     return id;   }   void add_letter(int pos) {     int cur = get_fail(last, pos);     if (!to[cur][text[pos] -  a ]) {       len[num_node] = len[cur] + 2;       fail[num_node] = to[get_fail(fail[cur], pos)][text[pos] -  a ];       dl[num_node] = len[num_node] - len[fail[num_node]];       if (dl[num_node] == dl[fail[num_node]])         nxt[num_node] = nxt[fail[num_node]];       else         nxt[num_node] = fail[num_node];       to[cur][text[pos] -  a ] = num_node++;     }     last = to[cur][text[pos] -  a ];   }   int main() {     scanf( %s%s , str[0], str[1]);     n = strlen(str[0]);     int i, j, s, p, q;     for (i = 0; i < n; i++) {       text[2 * i] = str[0][i];       text[2 * i + 1] = str[1][i];     }     n *= 2;     for (i = n - 1; i >= 0; i--) text[i + 1] = text[i];     init();     for (i = 1; i <= n; i++) {       add_letter(i);       ans[i] = inf;       for (j = last; len[j] > 0; j = nxt[j]) {         save[j] = ans[i - len[nxt[j]] - dl[j]];         path[j] = i - len[nxt[j]] - dl[j];         if (dl[j] == dl[fail[j]]) {           if (save[j] > save[fail[j]]) {             save[j] = save[fail[j]];             path[j] = path[fail[j]];           }         }         if (!(i & 1)) {           if (ans[i] > save[j] + 1) {             ans[i] = save[j] + 1;             pa[i] = path[j];           }         }       }       if (!(i & 1) && text[i] == text[i - 1]) {         if (ans[i] > ans[i - 2]) {           ans[i] = ans[i - 2];           pa[i] = i - 2;         }       }     }     if (ans[n] == inf)       puts( -1 );     else {       printf( %d n , ans[n]);       int id = n;       while (id > 0) {         if (pa[id] + 2 != id) printf( %d %d n , pa[id] / 2 + 1, id / 2);         id = pa[id];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     vector<long long> arr(n);     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr.begin(), arr.end());     if (arr[n - 1] == 1) {       arr[n - 1] = 2;     } else {       arr[n - 1] = 1;     }     sort(arr.begin(), arr.end());     for (long long i = 0; i < n; i++) {       cout << arr[i] <<    ;     }   }