malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN();   map<string, int> d;   int main() {     d[ void ] = 0;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       string a, b, c;       cin >> a;       if (a ==  typedef ) {         cin >> b >> c;         int k1 = 0, k2 = b.size() - 1, m = 0;         while (k1 < b.size() && b[k1] ==  & ) k1++, m--;         while (k2 >= 0 && b[k2] ==  * ) k2--, m++;         string t = b.substr(k1, k2 - k1 + 1);         if (!d.count(t) || d[t] == -1 || d[t] + m < 0)           d[c] = -1;         else           d[c] = d[t] + m;       } else {         cin >> b;         int k1 = 0, k2 = b.size() - 1, m = 0;         while (k1 < b.size() && b[k1] ==  & ) k1++, m--;         while (k2 >= 0 && b[k2] ==  * ) k2--, m++;         string t = b.substr(k1, k2 - k1 + 1);         if (!d.count(t) || d[t] == -1 || d[t] + m < 0)           printf( errtype n );         else {           printf( void );           int l = d[t];           for (int j = 0; j < l + m; j++) printf( * );           printf(  n );         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   bool f[300010];   map<pair<int, int>, int> mp;   vector<int> g[300010];   long long nm[300010], kk[300010], x, y, p;   long long ans, n, i;   void go(int now) {     f[now] = 1;     for (int i = 0; i < g[now].size(); i++)       if (!f[g[now][i]])         if (nm[now] + nm[g[now][i]] - mp[make_pair(now, g[now][i])] < p &&             p <= nm[now] + nm[g[now][i]])           ans -= 2;     for (int i = 0; i < g[now].size(); i++)       if (!f[g[now][i]]) go(g[now][i]);   }   int main() {     cin >> n >> p;     for (i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       mp[make_pair(x, y)]++;       mp[make_pair(y, x)]++;       if (mp[make_pair(x, y)] == 1) {         g[x].push_back(y);         g[y].push_back(x);       }       nm[x]++;       nm[y]++;     }     for (i = 1; i <= n; i++)       if (2 * nm[i] >= p) ans--;     for (i = 1; i <= n; i++) kk[nm[i]]++;     for (i = 300000; i >= 0; i--) kk[i] += kk[i + 1];     for (i = 1; i <= n; i++) ans += kk[max(0LL, p - nm[i])];     for (i = 1; i <= n; i++)       if (!f[i]) go(i);     cout << ans / 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     set<long long> v;     set<long long>::iterator j;     for (long long i = 1; i <= pow(n, 0.5); i++) {       if (n % i == 0) {         long long x = n / i;         v.insert((x * (2 + (x - 1) * i)) / 2);         v.insert((i * (2 + (i - 1) * x)) / 2);       }     }     for (j = v.begin(); j != v.end(); j++) {       cout << *j <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline int dcmp(double a, double b) {     return fabs(a - b) < (1e-9) ? 0 : a < b ? -1 : +1;   }   const int N = 1000 + 9;   int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};   int ans[N];   vector<vector<int> > g;   int x[N];   bitset<N> del;   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       int n;       scanf( %d , &n);       for (auto i = 0; i < n; ++i) scanf( %d , x + i);       for (int cnt = 0, p = 0; cnt != n; p++) {         g.emplace_back(vector<int>());         for (auto i = 0; i < n; ++i)           if (!del[i] && x[i] % pr[p] == 0)             del[i] = 1, g.back().emplace_back(i), cnt++;         if (g.back().empty()) g.pop_back();       }       for (auto i = 0; i < ((int)((g).size())); ++i)         for (auto j = 0; j < ((int)((g[i]).size())); ++j) ans[g[i][j]] = i;       printf( %d n , ((int)((g).size())));       for (auto i = 0; i < n; ++i) printf( %d  , ans[i] + 1);       puts(  );       del.reset();       g.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   int main() {     int n, m, x, y, a, b;     while (cin >> n >> m >> x >> y >> a >> b) {       int g = gcd(a, b);       a /= g;       b /= g;       g = min(n / a, m / b);       a *= g;       b *= g;       int lx = max(0, x - (a + 1) / 2);       int ly = max(0, y - (b + 1) / 2);       int rx = lx + a;       int ry = ly + b;       if (rx > n) {         lx -= rx - n;         rx = n;       }       if (ry > m) {         ly -= ry - m;         ry = m;       }       if (lx > rx) swap(lx, rx);       if (ly > ry) swap(ly, ry);       cout << lx <<     << ly <<     << rx <<     << ry << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > a;   vector<long long> bus;   long long n, t, z;   int main() {     cin >> n >> t;     for (int i = 0; i < n; i++) {       cin >> z;       t -= z;     }     if (t > n - 1 || t < n - 1) {       cout <<  NO ;     } else       cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     cin >> n >> d;     int a[n];     int x = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       x += a[i];     }     if (x + (n - 1) * 10 > d) {       cout << -1;     } else {       cout << 2 * n - 2 + (d - x - (n - 1) * 10) / 5;     }   }
#include <bits/stdc++.h>   using namespace std;   long long arr[1000000], pref[1000000], suf[1000000];   int main() {     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     for (long long i = 0; i < n; i++) pref[i + 1] = pref[i] + arr[i];     long long mini = 1e18;     for (long long i = 0, j = 0; i < n; i = j) {       for (; j < n && arr[j] == arr[i]; j++)         ;       long long dif = j - i;       if (dif >= k) {         cout << 0;         return 0;       }       long long l = ((arr[i] - 1) * i) - pref[i],                 r = pref[n] - pref[j] - ((arr[i] + 1) * (n - j));       if (i + dif >= k && mini > l + k - dif) mini = l + k - dif;       if (dif + n - j >= k && mini > r + k - dif) mini = r + k - dif;       if (mini > l + r + k - dif) mini = l + r + k - dif;     }     cout << mini;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long INF64 = 1e18;   const int INF32 = 1e9;   const int MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       int x;       cin >> x;       string s = to_string(x);       set<char> st;       for (char &c : s) st.insert(c);       int sqrtX = sqrt(x), res = 0;       for (int i = (1); i <= (sqrtX); i++)         if (x % i == 0) {           s = to_string(i);           for (char &c : s)             if (st.count(c)) {               res++;               break;             }           int j = x / i;           if (j == i) break;           s = to_string(x / i);           for (char &c : s)             if (st.count(c)) {               res++;               break;             }         }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   const int INF = 2000000000;   const ll LLINF = 9000000000000000000;   void fix_mod(ll &v, ll M) { v = ((v - 1) % M + M) % M + 1; }   int main() {     int N;     ll M;     ll T;     cin >> N >> M >> T;     vii Si(N, {0LL, 0LL});     vi pos(N, 0LL);     ll shift = 0;     for (int i = 0; i < N; i++) {       ll x;       char c;       cin >> x >> c;       ll slope = (c ==  L  ? -1 : 1);       ll ic = (slope == 1 ? 1 - x : x);       shift += ((T / M) % N) * slope;       fix_mod(ic, M);       if (ic <= T % M) shift += slope;       Si[i] = {x, i};       pos[i] = x + (T % M) * slope;       fix_mod(pos[i], M);     }     sort(Si.begin(), Si.end());     sort(pos.begin(), pos.end());     fix_mod(shift, N);     vi ans(N, 0LL);     for (int i = 0; i < N; i++) ans[Si[i].second] = pos[(i + shift) % N];     for (int i = 0; i < N - 1; i++) cout << ans[i] <<    ;     cout << ans[N - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[200001];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int k, h;     k = a[n - 1] - a[1];     h = a[n - 2] - a[0];     if (k > h) {       cout << h;     } else {       cout << k;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int r[10005];   struct N {     int l, r, x;   } p[10005];   bool cmp(N a, N b) { return a.l < b.l; }   bool vis[10005];   int main() {     int n, q;     cin >> n >> q;     memset(vis, 0, sizeof vis);     for (int i = 0; i < q; i++) {       cin >> p[i].l >> p[i].r >> p[i].x;     }     sort(p, p + q, cmp);     for (int i = 0; i < q; i++) {       for (int j = n - p[i].x; j >= 0; j--) {         if (r[j] >= p[i].l)           vis[j + p[i].x] = 1,                   r[j + p[i].x] = max(r[j + p[i].x], min(p[i].r, r[j]));       }       r[p[i].x] = max(r[p[i].x], p[i].r);       vis[p[i].x] = 1;     }     int cnt = 0;     for (int i = 1; i <= n; i++)       if (vis[i]) cnt++;     cout << cnt << endl;     for (int i = 1; i <= n; i++) {       if (vis[i]) {         if (i == n)           cout << i << endl;         else           cout << i <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct nod {     int x, y;   } num[110000];   struct nod2 {     int qian, zhi;   } bian[110000];   struct nod3 {     int ls, rs, l, r, mi;   } t[410000];   int n, p, a, b, mi, i, x[110000], wei[410000], use[110000], use2[110000],       w[110000];   int build(int l, int r) {     int mid, k;     k = ++p;     mid = (l + r) / 2;     t[k].mi = 10000000;     t[k].l = l;     t[k].r = r;     if (l == r) return (k);     t[k].ls = build(l, mid);     t[k].rs = build(mid + 1, r);     return (k);   }   bool cmp(nod a, nod b) {     if (a.x != b.x) return (a.x > b.x);     return (a.y > b.y);   }   void build2(int d, int a) {     p++;     bian[p].qian = wei[d];     bian[p].zhi = a;     wei[d] = p;   }   int qiu(int d, int l, int r) {     int mid;     if (l <= t[d].l && r >= t[d].r) return (t[d].mi);     mid = (t[d].l + t[d].r) / 2;     if (l > mid) return (qiu(t[d].rs, l, r));     if (r <= mid) return (qiu(t[d].ls, l, r));     return (min(qiu(t[d].ls, l, mid), qiu(t[d].rs, mid + 1, r)));   }   void jia(int d, int a, int b) {     int mid;     if (t[d].l == t[d].r) {       t[d].mi = min(t[d].mi, b);       return;     }     mid = (t[d].l + t[d].r) / 2;     if (a <= mid) jia(t[d].ls, a, b);     if (a > mid) jia(t[d].rs, a, b);     t[d].mi = min(t[t[d].ls].mi, t[t[d].rs].mi);   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &num[i].x, &num[i].y);       use[i] = num[i].y - num[i].x;     }     for (i = 1; i <= n; i++) {       scanf( %d , &w[i]);       use2[i] = w[i];     }     sort(use + 1, use + 1 + n);     sort(use2 + 1, use2 + 1 + n);     for (i = 1; i <= n; i++)       if (use[i] != use2[i]) {         printf( No n );         return (0);       }     build(0, 100000);     p = 0;     for (i = 1; i <= n; i++) build2(w[i] + 110000, i);     sort(num + 1, num + 1 + n, cmp);     for (i = 1; i <= n; i++) {       a = 110000 + num[i].y - num[i].x;       b = wei[a];       mi = qiu(1, num[i].y, 100000);       if (bian[b].zhi > mi) {         printf( No n );         return (0);       }       jia(1, num[i].y, bian[b].zhi);       x[bian[b].zhi] = i;       wei[a] = bian[b].qian;     }     printf( Yes n );     for (i = 1; i <= n; i++) printf( %d %d n , num[x[i]].x, num[x[i]].y);   }
#include <bits/stdc++.h>   using namespace std;   long long m, l, r, k, n;   long long a[2][2], b[2][2];   void cc(long long a[2][2], long long b[2][2]) {     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) a[i][j] = b[i][j];   }   void mul(long long a[2][2], long long b[2][2], long long m) {     long long c[2][2];     memset(c, 0, sizeof(c));     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         for (int k = 0; k < 2; k++) c[i][j] += a[i][k] * b[k][j], c[i][j] %= m;     cc(a, c);   }   void mi(long long a[2][2], long long n, long long m) {     long long y[2][2];     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) y[i][j] = 0;     y[0][0] = 1;     y[1][1] = 1;     while (n > 0) {       if (n % 2 == 1) mul(y, a, m);       n = n / 2;       mul(a, a, m);     }     cc(a, y);   }   int main() {     cin >> m >> l >> r >> k;     n = -1;     for (long long i = k;; i++) {       long long x = r / i;       long long y = r / x;       long long z = (l - 1) / x;       if (x <= 1000000) break;       if (y - z >= k) {         n = x;         break;       }     }     if (n == -1)       for (long long i = 1000000; i >= 1; i--) {         long long y = r / i;         long long z = (l - 1) / i;         if (y - z >= k) {           n = i;           break;         }       }     a[0][1] = 1;     a[1][0] = 1;     a[1][1] = 1;     b[0][1] = 1;     b[0][0] = 1;     mi(a, n - 2, m);     mul(b, a, m);     cout << b[0][1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int total;     cin >> total;     while (total--) {       int n, k, cont_l = 0, cont_r = 0;       vector<pair<int, int> > ans;       string s;       cin >> n >> k;       cin >> s;       for (int i = 0; i < s.size(); i++) {         if ((i + 2) / 2 < k) {           if (i % 2 == 0) {             if (s[i] !=  ( ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ( ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           } else {             if (s[i] !=  ) ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ) ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           }         } else {           int cont = (n - (k - 1) * 2);           if (cont_l < cont) {             if (s[i] !=  ( ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ( ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           } else {             if (s[i] !=  ) ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ) ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           }         }       }       cout << ans.size() << endl;       for (int i = 0; i < ans.size(); i++) {         cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e18;   const long long minN = -1e18;   const long long MOD = 1e9 + 7;   const long long MOD1 = 998244353;   const int baseHash = 331;   const int bigNumLength = 5000;   const long double PI = acos(-1);   const long long limit = 2e5 + 5;   const long long limit1 = 1e6 + 5;   const long long limit2 = 1e3 + 5;   pair<long long, long long> dir[] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},                                       {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   int n, m;   map<int, bool> check[limit];   set<int> s;   int root[limit];   int cur[limit];   int d = 0;   bool compo[limit];   long long ans = 0;   int findRoot(int u) { return (root[u] < 0) ? u : findRoot(root[u]); }   void mergeRoot(int u, int v) {     u = findRoot(u);     v = findRoot(v);     if (u == v) return;     if (root[u] > root[v]) swap(u, v);     root[u] += root[v];     root[v] = u;   }   void solveProblem() {     queue<int> q;     vector<int> cur;     memset(root, -1, sizeof(root));     for (int i = (1); i <= (n); ++i) s.insert(i);     for (int i = (1); i <= (n); ++i) {       if (s.count(i)) {         s.erase(i);         q.push(i);         ++ans;         while (!q.empty()) {           int u = q.front();           q.pop();           for (auto it : s) {             if (check[it][u]) continue;             cur.push_back(it);             mergeRoot(u, it);             q.push(it);           }           for (auto it : cur) s.erase(it);           cur.clear();         }       }     }     cout << ans - 1 <<   n ;   }   void fastInput() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void readInput() {     cin >> n >> m;     for (int i = (1); i <= (m); ++i) {       int u, v;       cin >> u >> v;       check[u][v] = true;       check[v][u] = true;     }   }   int main() {     fastInput();     readInput();     solveProblem();   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 10, N = 2e6 + 10, mod = 1e9 + 7, LG = 20, SQ = 450;   long long n, T[N], L[N], dp[N], ps[N];   inline void KMP(string s) {     long long k = -1;     T[0] = -1;     for (int i = 1; i < s.size(); i++) {       while (k != -1 and s[k + 1] != s[i]) k = T[k];       if (s[k + 1] == s[i]) k++;       T[i] = k;     }   }   string s, t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s >> t;     n = s.size();     KMP(t +  #  + s);     for (int i = t.size() + 1; i < s.size() + t.size() + 1; i++)       T[i - t.size() - 1] = T[i] + 1;     L[0] = -1;     for (int i = 0; i < n; i++) {       L[i + 1] = L[i];       if (T[i] == t.size()) L[i + 1] = i - t.size() + 1;     }     dp[0] = 1;     ps[0] = 1;     for (int i = 1; i <= n; i++) {       dp[i] = dp[i - 1];       if (L[i] > -1) dp[i] = (ps[L[i]] + dp[i]) % mod;       ps[i] = (ps[i - 1] + dp[i]) % mod;     }     cout << ((dp[n] + mod - 1) % mod);   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     if (m == 3 && n >= 5) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       cout << i <<     << i * i + 10000000 << endl;     }     for (int i = 1; i <= n - m; i++) {       cout << i <<     << -i * i - 10000000 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 55;   int n, d, a[N], dp[N * 10005], gao[N * 10005];   vector<int> v;   int main() {     int sum = 0;     cin >> n >> d;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     dp[0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = sum; j >= a[i]; j--) {         dp[j] |= dp[j - a[i]];       }     }     for (int i = 0; i <= sum; i++) {       if (dp[i]) v.push_back(i);     }     memset(gao, 0x11, sizeof(dp));     int now = 0, step = 0;     while (true) {       if (now == v.size() - 1) break;       int nxt = now;       while (nxt + 1 < v.size() && v[nxt + 1] - v[now] <= d) nxt++;       if (nxt == now) break;       now = nxt;       step++;     }     cout << v[now] <<     << step << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   long long arr[200010];   long long factorial[200010];   long long factinv[200010];   long long fact[200010];   long long ans;   long long pw(long long a, long long b) {     a %= 1000000007;     if (b == 0) {       return 1ll;     }     if (b == 1) {       return a;     }     long long res = pw(a, b / 2);     if (b % 2) {       return (((res * res) % 1000000007) * a) % 1000000007;     }     return (res * res) % 1000000007;   }   long long inv(long long a) { return pw(a, 1000000007 - 2); }   long long choose(long long a, long long b) {     return ((factorial[a] * factinv[b] % 1000000007) * factinv[a - b]) %            1000000007;   }   int32_t main() {     ios_base::sync_with_stdio(false);     if (fopen( cf815b.in ,  r )) {       freopen( cf815b.in ,  r , stdin);       freopen( cf815b.out ,  w , stdout);     }     cin >> N;     for (int i = 0; i < N; i++) {       cin >> arr[i];       arr[i] %= 1000000007;     }     factorial[0] = 1;     for (int i = 1; i <= N; i++) {       factorial[i] = factorial[i - 1] * i;       factorial[i] %= 1000000007;     }     for (int i = 0; i <= N; i++) {       factinv[i] = inv(factorial[i]);     }     if (N % 4 == 0) {       long long choosev = (N - 2) / 2;       for (int i = 0; i < N; i++) {         fact[i] = choose(choosev, i / 2);         if (i % 2) {           fact[i] *= (1000000007 - 1);         }         fact[i] %= 1000000007;       }     }     if (N % 4 == 1) {       long long choosev = (N - 1) / 2;       for (int i = 0; i < N; i += 2) {         fact[i] = choose(choosev, i / 2);       }     }     if (N % 4 == 2) {       long long choosev = (N - 2) / 2;       for (int i = 0; i < N; i++) {         fact[i] = choose(choosev, i / 2);       }     }     if (N % 4 == 3) {       long long choosev = (N - 3) / 2;       fact[0] = 1;       fact[N - 1] = 1000000007 - 1;       for (int i = 1; i < N - 1; i++) {         if (i % 2) {           fact[i] = choose(choosev, (i - 1) / 2) + choose(choosev, (i - 1) / 2);         } else {           fact[i] = choose(choosev, (i / 2)) - choose(choosev, (i - 1) / 2);         }         fact[i] %= 1000000007;         fact[i] += 1000000007;         fact[i] %= 1000000007;       }     }     for (int i = 0; i < N; i++) {       cerr << fact[i] <<    ;       ans += fact[i] * arr[i];       ans %= 1000000007;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct seg {     int l, r, i;     bool operator<(const seg& b) const { return l < b.l; }   };   int n, k;   seg a[200005];   bool u[400005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i].l >> a[i].r, a[i].i = i;     sort(a, a + n);     set<pair<int, int>> pq;     for (int i = 0; i < k; i++) pq.insert({0, n + i});     for (int i = 0; i < n; i++) {       auto it = pq.lower_bound({a[i].l, -1});       if (it == pq.begin()) {         it = --pq.end();         if (a[i].r < it->first) {           u[it->second] = 1;           pq.erase(it);           pq.insert({a[i].r, a[i].i});         } else {           u[a[i].i] = 1;         }       } else {         --it;         pq.erase(it);         pq.insert({a[i].r, a[i].i});       }     }     cout << count(u, u + n, 1) <<   n ;     for (int i = 0; i < n; i++)       if (u[i]) cout << i + 1 <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n / 2 << endl;     if (n % 2 == 0) {       for (int i = 0; i < n / 2; i++) {         cout <<  2  ;       }     } else {       for (int i = 0; i < n / 2 - 1; i++) {         cout <<  2  ;       }       cout << 3;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e3 + 10;   int n;   int a[N], b[N];   long long dp[N][N];   long long solve(int idx = 0, int val = 0) {     if (idx == n) return 0;     if (val == n) return 1e18;     long long &ret = dp[idx][val];     if (ret == -1)       ret = min(solve(idx + 1, val) + abs(a[idx] - b[val]), solve(idx, val + 1));     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       b[i] = a[i] -= i;     }     sort(b, b + n);     memset(dp, -1, sizeof(dp));     printf( %lld n , solve());     return 0;   }