malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   namespace LCT {   int fa[500005], ch[500005][2];   bool rev[500005], val[500005];   bool isr(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }   bool isc(int x) { return ch[fa[x]][1] == x; }   void upd(int x) { val[x] = val[ch[x][0]] | val[ch[x][1]] | (x > n); }   void pd(int x) {     if (rev[x])       swap(ch[x][0], ch[x][1]), rev[x] = 0, rev[ch[x][0]] ^= 1,                                 rev[ch[x][1]] ^= 1;   }   void pdpath(int x) {     if (!isr(x)) pdpath(fa[x]);     pd(x);   }   void rot(int x) {     int y = fa[x], z = fa[y], c = isc(x);     if (!isr(y)) ch[z][ch[z][1] == y] = x;     fa[ch[y][c] = ch[x][!c]] = y;     fa[ch[x][!c] = y] = x, fa[x] = z;     upd(y);   }   void splay(int x) {     for (pdpath(x); !isr(x); rot(x))       if (!isr(fa[x])) rot(isc(fa[x]) == isc(x) ? fa[x] : x);     upd(x);   }   void access(int x) {     for (int y = 0; x; x = fa[y = x]) splay(x), ch[x][1] = y, upd(x);   }   void prefer(int x) { access(x), splay(x); }   void bert(int x) { prefer(x), rev[x] ^= 1; }   void link(int x, int y) { bert(x), fa[x] = y; }   void cut(int x, int y) { bert(x), prefer(y), fa[x] = ch[y][0] = 0, upd(y); }   int find(int x) {     pd(x);     if (val[ch[x][1]])       return find(ch[x][1]);     else       return x > n ? x : find(ch[x][0]);   }   }  // namespace LCT   using LCT::cut;   using LCT::link;   vector<int> G[500005];   int X[500005], Y[500005], deg[500005], stk[500005], top, fa[500005];   void dfs(int u) {     for (int i = G[u].size() - 1, v; i >= 0; i--)       if ((v = G[u][i]) != fa[u]) fa[v] = u, dfs(v);   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), G[x].push_back(y), G[y].push_back(x);     for (int i = 1; i < n; i++)       scanf( %d%d , &X[i], &Y[i]), link(X[i], n + i), link(Y[i], n + i);     dfs(1);     for (int i = 1; i <= n; i++) deg[fa[i]]++;     for (int i = 1; i <= n; i++)       if (!deg[i]) stk[++top] = i;     printf( %d n , n - 1);     for (int i = 1, k; i < n; i++) {       int x = stk[i];       if (!--deg[fa[x]]) stk[++top] = fa[x];       LCT::bert(fa[x]), LCT::prefer(x);       k = LCT::find(LCT::ch[x][0]) - n;       printf( %d %d %d %d n , x, fa[x], X[k], Y[k]);       cut(X[k], n + k), cut(Y[k], n + k), link(x, fa[x]);     }   }
#include <bits/stdc++.h>   using namespace std;   int a[3005], b[3005], c[3005], vis[3005];   bool cmp(int i, int j) { return a[i] > a[j]; }   int main() {     vector<int> p, q;     int T, i, j, k, ca = 0, n, m, K;     int s, t;     scanf( %d%d%d , &n, &s, &t);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]), c[i] = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);     }     sort(c, c + n, cmp);     for (int i = 0; i < s; i++) {       vis[c[i]] = 1;     }     while (t--) {       k = 0;       while (k < n && vis[c[k]]) k++;       int mx = -1, v, l = c[k];       for (int i = n - 1; i >= 0; i--) {         j = -0x7f7f7f7f;         if (vis[i] == 0)           j = b[i];         else if (vis[i] == 1)           j = -a[i] + a[l] + b[i];         if (j > mx) mx = j, v = i;       }       if (vis[v]) vis[l] = 1;       vis[v] = 2;     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (vis[i] == 1) {         p.push_back(i + 1);         ans += a[i];       } else if (vis[i] == 2) {         q.push_back(i + 1);         ans += b[i];       }     }     printf( %d n , ans);     for (auto it : p) {       printf( %d  , it);     }     puts(  );     for (auto it : q) {       printf( %d  , it);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a, b;   vector<pair<int, int> > des[110];   int dist(int i, int j) {     if (i <= j) return j - i;     return n - i + j;   }   bool cmp(pair<int, int> a, pair<int, int> b) {     int i = a.second;     int x = a.first, y = b.first;     return dist(i, x) < dist(i, y);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       des[a].push_back(pair<int, int>(b, a));     }     for (int i = 1; i <= n; i++) sort(des[i].begin(), des[i].end(), cmp);     for (int s = 1; s <= n; s++) {       int ans = 0;       for (int i = 1; i <= n; i++) {         if (des[i].empty()) continue;         int d;         if (s <= i)           d = i - s;         else           d = n - s + i;         d += n * (des[i].size() - 1);         int j = des[i][0].first;         if (i <= j)           d += j - i;         else           d += n - i + j;         ans = max(ans, d);       }       cout << ans <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long a[maxn], b[maxn];   long long dp[maxn];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       a[i] -= i;       b[i] = a[i];     }     sort(b + 1, b + 1 + n);     memset(dp, (0), sizeof(dp));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (j == 1)           dp[j] += abs(a[i] - b[j]);         else {           dp[j] = min(dp[j - 1], dp[j] + abs(a[i] - b[j]));         }       }     }     printf( %lld n , (dp[n]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Q, n, m, ans[600005], a[505][505];   char S[505];   struct O {     int p, q, x, y, i;   } o[600005], O[600005];   bitset<505> f[505][505], g[505][505];   void go(int l, int r, int p, int q) {     if (p > q) return;     int mi = l + r >> 1, L, R, t;     for (int i = 1; i <= n; ++i)       if (!a[i][mi])         g[i][mi].reset();       else         g[i][mi] = g[i - 1][mi], g[i][mi].set(i);     for (int j = mi + 1; j <= r; ++j)       for (int i = 1; i <= n; ++i) {         g[i][j].reset();         if (!a[i][j]) continue;         if (a[i][j - 1]) g[i][j] |= g[i][j - 1];         if (a[i - 1][j]) g[i][j] |= g[i - 1][j];       }     for (int i = n; i; --i)       if (!a[i][mi])         f[i][mi].reset();       else         f[i][mi] = f[i + 1][mi], f[i][mi].set(i);     for (int j = mi - 1; j >= l; --j)       for (int i = n; i; --i) {         f[i][j].reset();         if (!a[i][j]) continue;         if (a[i][j + 1]) f[i][j] |= f[i][j + 1];         if (a[i + 1][j]) f[i][j] |= f[i + 1][j];       }     L = p;     R = q;     for (int i = p; i <= q; ++i)       if (o[i].q < mi && o[i].y < mi)         O[L++] = o[i];       else if (o[i].q > mi && o[i].y > mi)         O[R--] = o[i];     t = L;     for (int i = p; i <= q; ++i)       if (o[i].q <= mi && o[i].y >= mi) O[t++] = o[i];     for (int i = p; i <= q; ++i) o[i] = O[i];     for (int i = L; i <= R; ++i)       if (o[i].p <= o[i].x && o[i].q <= o[i].y)         ans[o[i].i] = (f[o[i].p][o[i].q] & g[o[i].x][o[i].y]).any();     if (l == r) return;     go(l, mi - 1, p, L - 1);     go(mi + 1, r, R + 1, q);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s , S + 1);       for (int j = 1; j <= m; ++j) a[i][j] = S[j] ==  . ;     }     scanf( %d , &Q);     for (int i = 1; i <= Q; ++i)       scanf( %d%d%d%d , &o[i].p, &o[i].q, &o[i].x, &o[i].y), o[i].i = i;     go(1, m, 1, Q);     for (int i = 1; i <= Q; ++i) puts(ans[i] ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double pi = acos(-1.0);   const double G = 6.67430e-11;   int n, q;   set<int> p;   multiset<int> d;   void in(int x) {     p.insert(x);     if (p.size() == 1) return;     auto pos = p.find(x);     if (pos == --p.end()) {       d.insert(x - *--pos);     } else if (pos == p.begin()) {       int y = *++pos;       d.insert(y - x);     } else {       auto r = ++pos;       pos--;       auto l = --pos;       pos++;       d.insert(x - *l);       d.insert(*r - x);       d.erase(d.find(*r - *l));     }   }   void er(int x) {     set<int>::iterator pos;     pos = p.find(x);     if (p.size() < 2) {       p.erase(x);       return;     }     if (pos == --p.end())       d.erase(d.find(x - *--pos));     else if (pos == p.begin())       d.erase(d.find(*++pos - x));     else {       set<int>::iterator l;       set<int>::iterator r;       l = --pos;       ++pos;       r = ++pos;       --pos;       d.erase(d.find(x - *l));       d.erase(d.find(*r - x));       d.insert(*r - *l);     }     p.erase(x);   }   int kk() {     if (p.size() <= 2) return 0;     auto l = p.begin();     auto r = --p.end();     return (*r - *l - *--d.end());   }   int main() {     cin >> n >> q;     int x;     for (int i = 1; i <= n; ++i) {       cin >> x;       in(x);     }     cout << kk() <<   n ;     int op;     while (q--) {       cin >> op >> x;       if (op == 1)         in(x);       else         er(x);       cout << kk() <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 2, MAX2 = 2e6 + 4;   int ans[MAX], val[MAX], depth[MAX];   vector<int> G[MAX], d[MAX2], occ[MAX2];   void init(int a) {     if (d[a].size()) return;     for (int i = 2; i * i <= a; i++) {       if (a % i == 0) {         d[a].push_back(a / i);         if (i * i != a) d[a].push_back(i);       }     }     if (a != 1) d[a].push_back(a);   }   void dfs(int vv, int par, int dv = 0) {     ans[vv] = -1, depth[vv] = dv;     int v = val[vv];     for (int i = 0; i < d[v].size(); i++) {       int u = d[v][i];       if (not occ[u].empty()) {         int x = occ[u].back();         if (ans[vv] == -1 or depth[ans[vv]] < depth[x]) ans[vv] = x;       }       occ[u].push_back(vv);     }     for (int i = 0; i < G[vv].size(); i++) {       int u = G[vv][i];       if (u == par) continue;       dfs(u, vv, dv + 1);     }     for (int i = 0; i < d[v].size(); i++) {       int u = d[v][i];       occ[u].pop_back();     }   }   int main() {     int n, q;     cin >> n >> q;     for (int i = 1; i < n + 1; i++) {       scanf( %d , val + i);       init(val[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     dfs(1, 0);     while (q--) {       int type;       scanf( %d , &type);       if (type == 1) {         int x;         scanf( %d , &x);         printf( %d n , ans[x]);       } else {         int x, v;         scanf( %d %d , &x, &v);         val[x] = v;         init(val[x]);         dfs(1, 0);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 27, maxm = 5e4 + 20, inf = 1e9;   vector<int> ar[maxn][maxn][maxn][maxn];   int q, a[maxm], bs[4], bs2[4];   string s, qs, qss;   map<pair<string, string>, int> mp;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> s >> q;     for (int i = 0; i < s.size(); i++)       a[i] = (int)s[i] -  a , ar[(int)s[i] -  a ][26][26][26].push_back(i);     for (int i = 0; i < (int)s.size() - 1; i++)       ar[a[i]][a[i + 1]][26][26].push_back(i);     for (int i = 0; i < (int)s.size() - 2; i++)       ar[a[i]][a[i + 1]][a[i + 2]][26].push_back(i);     for (int i = 0; i < (int)s.size() - 3; i++)       ar[a[i]][a[i + 1]][a[i + 2]][a[i + 3]].push_back(i);     while (q--) {       cin >> qs >> qss;       if (qss < qs) swap(qss, qs);       fill(bs, bs + 4, 26), fill(bs2, bs2 + 4, 26);       for (int i = 0; i < qs.size(); i++) bs[i] = qs[i] -  a ;       for (int i = 0; i < qss.size(); i++) bs2[i] = qss[i] -  a ;       if (ar[bs[0]][bs[1]][bs[2]][bs[3]].size() >           ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].size())         swap(qs, qss), swap(bs, bs2);       if (mp.count(make_pair(qs, qss))) {         cout << mp[make_pair(qs, qss)] << endl;         continue;       }       int ans = inf, j;       for (int i : ar[bs[0]][bs[1]][bs[2]][bs[3]]) {         auto it = upper_bound(ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].begin(),                               ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].end(), i);         if (it != ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].end()) {           j = *it;           ans = min(ans, max(i + (int)qs.size(), j + (int)qss.size()) - i);         }         if (it != ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].begin()) {           it--;           j = *it;           ans = min(ans, max(i + (int)qs.size(), j + (int)qss.size()) - j);         }       }       if (ans == inf) ans = -1;       mp[make_pair(qs, qss)] = ans;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int deg[100000], x[100000];   map<pair<int, int>, int> m;   vector<pair<int, int> > v;   int main() {     int n, k;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &deg[i], &x[i]);       if (deg[i] > 0) {         pair<int, int> a;         a.first = deg[i];         a.second = i;         m[a] = i;       }     }     while (!m.empty()) {       pair<pair<int, int>, int> b = *(m.begin());       m.erase(m.begin());       int neighbor = x[b.first.second];       v.push_back(pair<int, int>(b.first.second, neighbor));       map<pair<int, int>, int>::iterator it =           m.find(pair<int, int>(deg[neighbor], neighbor));       pair<int, int> c = it->first;       m.erase(it);       deg[neighbor]--;       x[neighbor] ^= b.first.second;       if (deg[neighbor] > 0) {         c.first--;         m[c] = neighbor;       }     }     k = v.size();     printf( %d n , v.size());     for (int i = 0; i < k; i++) {       printf( %d %d n , v[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 7340033;   long long n, k;   long long DP[100][1009], dp[100][1009];   long long DFS(int h, int k);   long long dfs(int h, int k) {     long long &d = dp[h][k];     if (~d) return d;     d = 0;     for (int i = 0; i <= k; i++)       d = (d + DFS(h - 1, i) * DFS(h - 1, k - i)) % mod;     return d;   }   long long DFS(int h, int k) {     long long &d = DP[h][k];     if (~d) return d;     if (h == 0) {       if (k == 0) return d = 1;       return d = 0;     }     if (k == 0) return 1;     d = 0;     for (int i = 0; i < k; i++) d = (d + dfs(h, i) * dfs(h, k - 1 - i)) % mod;     return d;   }   void pre() {     memset(dp, -1, sizeof(dp));     memset(DP, -1, sizeof(DP));     for (int i = 0; i <= 30; i++)       for (int j = 0; j <= 1000; j++) DFS(i, j);   }   int main() {     int w;     cin >> w;     pre();     while (w--) {       int n, k;       cin >> n >> k;       int cnt = 0;       while (n > 1 && (n & 1)) cnt++, n >>= 1;       cout << DFS(cnt, k) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int ku[maxn], kd[maxn], posu[maxn], posd[maxn];   long long tl[maxn], tr[maxn];   int main() {     int n;     cin >> n;     char s[maxn];     scanf( %s , s + 1);     int a = 0, b = 0;     for (int i = 1; i <= n; i++) {       ku[i + 1] = ku[i] + (s[i] ==  U );       kd[n - i] = kd[n - i + 1] + (s[n - i + 1] ==  D );       tl[i] = tl[i - 1] + 2 * ku[i] + 1;       tr[n - i + 1] = tr[n - i + 2] + 2 * kd[n - i + 1] + 1;       if (s[i] ==  U )         posu[a++] = i;       else         posd[b++] = i;     }     long long ans = 0, nb, ind;     for (int i = 1; i <= n; i++) {       if (s[i] ==  U ) {         if (ku[i] < kd[i]) {           nb = kd[i] - ku[i] - 1;           ind = posd[b - nb - 1];           ans = tl[i] + tr[i] - tr[ind] - (2 * nb + 1) * (ind - i);         } else {           nb = ku[i] - kd[i];           ind = posu[nb];           ans = tl[i] + tr[i] - tl[ind] - (2 * nb + 1) * (i - ind);         }       } else {         if (kd[i] < ku[i]) {           nb = ku[i] - kd[i] - 1;           ind = posu[nb];           ans = tl[i] + tr[i] - tl[ind] - (2 * nb + 1) * (i - ind);         } else {           nb = kd[i] - ku[i];           ind = posd[b - nb - 1];           ans = tl[i] + tr[i] - tr[ind] - (2 * nb + 1) * (ind - i);         }       }       cout << ans <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC optimize( no-stack-protector,fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int N = 5e5 + 100, OO = 1e6, T = (1 << 20) + 10, M = 998244353, P = 6151,             SQ = 280, lg = 64;   int a[N], b[N];   vector<int> v, v1, t, t1;   vector<pair<int, int> > is[N];   int dp[N], dp1[N], ant[N], ans[N], n1[N], n2[N];   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       is[x - 1].push_back({y, i});     }     for (int i = 0; i < n; i++) {       for (auto u : is[i]) {         int l = 0, r = (int)v.size();         int nw = u.first;         while (l < r) {           int mid = (l + r) / 2;           if (v[mid] >= nw)             r = mid;           else             l = mid + 1;         }         n1[u.second] = l + 1;       }       int l = 0, r = (int)v.size();       while (l < r) {         int mid = (l + r) / 2;         if (v[mid] >= a[i])           r = mid;         else           l = mid + 1;       }       if (l == (int)v.size())         v.push_back(a[i]);       else         v[l] = a[i];       dp[i] = l + 1;       b[i] = -1 * a[i];     }     int lis = (int)v.size();     for (int i = n - 1; i >= 0; i--) {       for (auto u : is[i]) {         int l = 0, r = (int)v1.size();         int nw = u.first * -1;         while (l < r) {           int mid = (l + r) / 2;           if (v1[mid] >= nw)             r = mid;           else             l = mid + 1;         }         n2[u.second] = l;       }       int l = 0, r = (int)v1.size();       while (l < r) {         int mid = (l + r) / 2;         if (v1[mid] >= b[i])           r = mid;         else           l = mid + 1;       }       if (l + dp[i] == (int)v.size())         ans[i] = 3, t.push_back(a[i]), t1.push_back(i);       else         ans[i] = 1;       if (l == (int)v1.size())         v1.push_back(b[i]);       else         v1[l] = b[i];     }     v.clear();     v1.clear();     for (int i = t.size() - 1; i >= 0; i--) {       int l = 0, r = (int)v.size();       while (l < r) {         int mid = (l + r) / 2;         if (v[mid] >= t[i])           r = mid;         else           l = mid + 1;       }       if (l == (int)v.size()) {         v.push_back(t[i]);         v1.push_back(t1[i]);       } else {         ans[v1[l]] = 2;         ans[t1[i]] = 2;         v[l] = t[i];         v1[l] = t1[i];       }     }     for (int i = 0; i < n; i++) {       for (auto u : is[i]) {         int lt = n1[u.second] + n2[u.second];         if (lt >= lis) {           ant[u.second] = lt;           continue;         }         if (ans[i] == 1 || ans[i] == 2) {           ant[u.second] = lis;           continue;         } else           ant[u.second] = lis - 1;       }     }     for (int i = 0; i < m; i++) cout << ant[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     cin >> TESTS;     while (TESTS--) {       int n;       cin >> n;       string s;       cin >> s;       if ((long long int)s.size() == 1)         cout <<  NO n ;       else if ((long long int)s.size() == 2) {         if (s[0] < s[1]) {           cout <<  YES n2 n ;           cout << s[0] <<     << s[1] <<   n ;         } else           cout <<  NO n ;       } else {         cout <<  YES n2 n ;         cout << s[0] <<     << s.substr(1, n - 1) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   int solve(int c, int d, int n, int m, int k) {     int s = n * m;     if (k >= n * m) return 0;     s = n * m - k;     int sum = 0;     while (1) {       if (s <= n) {         if (c < s * d)           sum += c;         else           sum += s * d;         break;       }       if (c < n * d)         sum += c;       else         sum += n * d;       s -= n;     }     return sum;   }   int main() {     int c, d, n, m, k;     while (scanf( %d%d%d%d%d , &c, &d, &n, &m, &k) != EOF) {       int s = solve(c, d, n, m, k);       printf( %d n , s);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int maxn = 100 + 10;   long long ma[100];   void init() {     long long x = 1;     for (int i = 0; i <= 32; i++) {       ma[i] = x;       x *= 2;     }   }   int main() {     init();     int T;     scanf( %d , &T);     while (T--) {       long long n;       long long ans = 0;       scanf( %lld , &n);       long long x1 = n;       long long x2 = (n + 1);       if (x1 % 2 == 0)         x1 /= 2;       else         x2 /= 2;       ans = x1 * x2;       for (int i = 0; i <= 32; i++) {         if (n < ma[i])           break;         else           ans -= 2 * ma[i];       }       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, p = 0;     cin >> n >> m;     if (n == 1 && m != 0) {       cout << m <<     << m << endl;       return 0;     } else if (m == 1 && n != 0) {       cout << n <<     << n << endl;       return 0;     } else if (n == 0 && m == 0) {       cout << p <<     << p << endl;       return 0;     } else if (n == 0) {       cout <<  Impossible n ;       return 0;     } else if (m == 0) {       cout << n <<     << n << endl;       return 0;     } else if (n == m) {       cout << m <<     << n + m - 1 << endl;       return 0;     } else if (n > m) {       if (n % m == 0)         cout << m + (n / m) <<     << n + m - 1 << endl;       else         cout << m + (n - m) <<     << n + m - 1 << endl;     } else if (m > n) {       if (m % n == 0)         cout << n + (m / n) <<     << n + m - 1 << endl;       else         cout << n + (m - n) <<     << n + m - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, s;     cin >> n >> k >> s;     if ((n - 1) * k < s || s < k) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     long long m = s / k;     int rem = s % k;     int count = 0;     int room = 1;     for (; count < rem; ++count) {       room = (count % 2 == 0) ? room + m + 1 : room - m - 1;       cout << room <<    ;     }     for (; count < k; ++count) {       room = (count % 2 == 0) ? room + m : room - m;       cout << room <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     int N;     vector<int> V;     cin >> N;     int X;     for (int i = 0; i < N; i++) {       cin >> X;       V.push_back(X);     }     int ans = 100100, t = 0;     for (int i = 1; i <= 100; i++) {       int cost = 0;       for (int j = 0; j < N; j++) {         if (abs(V[j] - i) > 1) {           cost += min(abs(V[j] - (i + 1)), abs(V[j] - (i - 1)));         }       }       if (cost < ans) {         ans = cost;         t = i;       }     }     cout << t <<     << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     bool temp = false;     cin >> n;     string *arr = new string[n];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       if (arr[i][0] ==  O  && arr[i][1] ==  O ) {         temp = true;         cout <<  YES  << endl;         arr[i][0] =  + ;         arr[i][1] =  + ;         for (int i = 0; i < n; i++) cout << arr[i] << endl;         break;       }       if (arr[i][3] ==  O  && arr[i][4] ==  O ) {         temp = true;         cout <<  YES  << endl;         arr[i][3] =  + ;         arr[i][4] =  + ;         for (int i = 0; i < n; i++) cout << arr[i] << endl;         break;       }     }     if (temp == false) {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[500 + 5];   long long ans = 1LL << 60;   void cal(int x) {     if (!x) return;     long long sum = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] % x == 0 || (a[i] / x >= x - 1 - a[i] % x))         sum += a[i] / x + bool(a[i] % x);       else         return;     }     ans = min(ans, sum);   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (i = 1; i * i <= a[1]; ++i)       cal(i), cal(a[1] / i), cal(a[1] / i - 1), cal(a[1] / i + 1);     printf( %I64d , ans);   }