malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const long long INFL = (long long)9e18;   const int MAXINT = ((~0) ^ (1 << 31));   const long long MAXLL = ((~0) ^ ((long long)1 << 63));   template <class T>   inline T pow2(T a) {     return a * a;   }   template <class T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, true) : false;   }   template <class T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, true) : false;   }   const int maxn = 2e5;   long long n, k, x, cnt;   pair<long long, long long> p[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) p[i] = {1e10, 0};     for (int i = 1; i <= k; i++) {       cin >> x;       p[x].first = min(p[x].first, (long long)i);       p[x].second = max(p[x].second, (long long)i);     }     if (p[1].first > p[2].second && n != 1) {       cnt++;     }     if (p[n].first > p[n - 1].second && n != 1) {       cnt++;     }     if (p[1].second == 0) cnt++;     if (p[n].second == 0 && n != 1) cnt++;     for (int i = 2; i <= n - 1; i++) {       if (p[i].second == 0) cnt++;       if (p[i].first > p[i + 1].second) {         cnt++;       }       if (p[i].first > p[i - 1].second) {         cnt++;       }     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ti[2005], co[2005], dp[2005][2005], i, j;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ti[i] >> co[i];       ti[i]++;     }     for (i = 0; i <= n; i++) {       for (j = 1; j <= n; j++) dp[i][j] = 1e16;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         dp[i][j] = min(dp[i - 1][j], dp[i - 1][max(0ll, j - ti[i])] + co[i]);       }     }     cout << dp[n][n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pen {     int color;     int diameter;   };   int n, m, u, v;   pen marker[100000], cap[100000];   struct match {     vector<pen> marker;     vector<pen> cap;   };   match singleMatch[1000 + 1];   match doubleMatch[1000 + 1][1000 + 1];   int main(int argc, char *argv[]) {     u = 0, v = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int color, diameter;       cin >> color >> diameter;       marker[i].color = color;       marker[i].diameter = diameter;       singleMatch[diameter].marker.push_back(marker[i]);       doubleMatch[diameter][color].marker.push_back(marker[i]);     }     for (int i = 0; i < m; i++) {       int color, diameter;       cin >> color >> diameter;       cap[i].color = color;       cap[i].diameter = diameter;       singleMatch[diameter].cap.push_back(marker[i]);       doubleMatch[diameter][color].cap.push_back(cap[i]);     }     for (int i = 1; i < 1000 + 1; i++) {       vector<pen> tempM = singleMatch[i].marker;       vector<pen> tempC = singleMatch[i].cap;       int temp1 = (int)tempM.size();       int temp2 = (int)tempC.size();       if (temp1 > 0 && temp2 > 0) u += min(temp1, temp2);     }     for (int i = 1; i < 1000 + 1; i++)       for (int j = 1; j < 1000 + 1; j++) {         vector<pen> tempM = doubleMatch[i][j].marker;         vector<pen> tempC = doubleMatch[i][j].cap;         int temp1 = (int)tempM.size();         int temp2 = (int)tempC.size();         if (temp1 > 0 && temp2 > 0) v += min(temp1, temp2);       }     cout << u <<     << v << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 109;   const int mod = 1000000007;   long long cnt[inf];   long long dp[inf];   long long temp[inf][inf];   long long sol[inf][inf];   long long bs[inf][inf];   int main() {     int n, x, a;     scanf( %d%d , &n, &x);     for (int i = 0; i < n; ++i) {       scanf( %d , &a);       cnt[a]++;     }     dp[0] = 1;     int all = 0;     for (int i = 1; i <= 100; ++i) {       for (int j = 1; j <= i; ++j) dp[i] = (dp[i] + dp[i - j] * cnt[j]) % mod;       all = (all + dp[i]) % mod;     }     dp[0] = all;     for (int i = 1; i <= 50; ++i) swap(dp[i], dp[101 - i]);     for (int i = 1; i <= 100; ++i) sol[i][i] = 1, bs[0][i] = bs[1][i] = cnt[i];     sol[0][0] = bs[0][0] = 1;     for (int i = 2; i <= 100; ++i) bs[i][i - 1] = 1;     if (x <= 100) {       int ad = 0;       for (int i = 100; i > 0 && x > 0; --i, --x) ad = (ad + dp[i]) % mod;       printf( %d n , ad + 1);       return 0;     }     x -= 100;     while (x) {       if (x & 1) {         for (int i = 0; i <= 100; ++i)           for (int j = 0; j <= 100; ++j) {             temp[i][j] = 0;             for (int u = 0; u <= 100; ++u)               temp[i][j] = (temp[i][j] + sol[i][u] * bs[u][j]) % mod;           }         for (int i = 0; i <= 100; ++i)           for (int j = 0; j <= 100; ++j) sol[i][j] = temp[i][j];       }       x = x >> 1;       for (int i = 0; i <= 100; ++i)         for (int j = 0; j <= 100; ++j) {           temp[i][j] = 0;           for (int u = 0; u <= 100; ++u)             temp[i][j] = (temp[i][j] + bs[i][u] * bs[u][j]) % mod;         }       for (int i = 0; i <= 100; ++i)         for (int j = 0; j <= 100; ++j) bs[i][j] = temp[i][j];     }     int ans = 0;     for (int i = 0; i <= 100; ++i) ans = (ans + sol[0][i] * dp[i]) % mod;     printf( %d n , (ans + 1) % mod);   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 4e5 + 10;   const int M = 22;   class SegmentTree {    public:     int ql, qr, qx;     int xorv[N];     int sumv[N];     void init() {       memset((xorv), (0), sizeof(xorv));       memset((sumv), (0), sizeof(sumv));     }     void set(int ql, int qr, int qx) {       this->ql = ql;       this->qr = qr;       this->qx = qx;     }     void pushdown(int o, int len) {       if (xorv[o]) {         xorv[o << 1] ^= 1;         xorv[o << 1 | 1] ^= 1;         sumv[o << 1] = (len - len / 2) - sumv[o << 1];         sumv[o << 1 | 1] = len / 2 - sumv[o << 1 | 1];         xorv[o] = 0;       }     }     void maintain(int o) { sumv[o] = sumv[o << 1] + sumv[o << 1 | 1]; }     int query(int l, int r, int o = 1) {       if (ql <= l && qr >= r) {         return sumv[o];       }       int mid = (l + r) >> 1;       pushdown(o, r - l + 1);       int ans = 0;       if (ql <= mid) ans += query(l, mid, o << 1);       if (qr > mid) ans += query(mid + 1, r, o << 1 | 1);       return ans;     }     void update(int l, int r, int o = 1) {       if (ql <= l && qr >= r) {         xorv[o] ^= 1;         sumv[o] = r - l + 1 - sumv[o];         return;       }       int mid = (l + r) >> 1;       pushdown(o, r - l + 1);       if (ql <= mid) update(l, mid, o << 1);       if (qr > mid) update(mid + 1, r, o << 1 | 1);       maintain(o);     }   } st[M];   int main() {     for (int i = 0; i < M; i++) st[i].init();     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       for (int j = 0; j < M; j++) {         if (x >> j & 1) st[j].set(i, i, 1), st[j].update(1, n);       }     }     int q;     cin >> q;     while (q--) {       int op;       cin >> op;       if (op == 1) {         int l, r;         cin >> l >> r;         long long ans = 0;         for (int i = 0; i < M; i++) {           st[i].set(l, r, 0);           ans += (1LL << i) * st[i].query(1, n);         }         cout << ans <<   n ;       } else {         int l, r, x;         cin >> l >> r >> x;         for (int i = 0; i < M; i++) {           if (x >> i & 1) st[i].set(l, r, 1), st[i].update(1, n);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct data {     int s, m, r, t;     int operator<(const data &b) const { return t < b.t; }     void get() {       scanf( %d , &s);       scanf( %d , &m);       scanf( %d , &r);       t = r ? (m / r + (m % r > 0)) : 2e9;     }     int calc(int o) { return min(1ll * m, s + 1ll * r * o); }   } a[20][100005];   int T[100005 << 2];   long long R[20][100005], sum[20][100005], ans;   int n, Q, t, ql, qr;   void Build(int x, int l, int r, int d) {     T[x] = -2;     if (l == r) {       a[d][l].get();       R[d][l] = R[d][l - 1] + a[d][l].r;       sum[d][l] = sum[d][l - 1] + a[d][l].m;       return;     }     int mid = (l + r) >> 1;     Build(x << 1, l, mid, d + 1);     Build(x << 1 | 1, mid + 1, r, d + 1);     for (int i = l; i <= r; i++) a[d][i] = a[d + 1][i];     sort(a[d] + l, a[d] + r + 1);     for (int i = l; i <= r; i++) R[d][i] = R[d][i - 1] + a[d][i].r;     for (int i = l; i <= r; i++) sum[d][i] = sum[d][i - 1] + a[d][i].m;   }   void Find(int x, int l, int r, int d) {     if (ql <= l && r <= qr && T[x] != -1) {       if (T[x] == -2) {         for (int i = l; i <= r; i++) ans += a[d][i].calc(t);         T[x] = t;         return;       }       data tmp = (data){0, 0, 0, t - T[x]};       int id = upper_bound(a[d] + l, a[d] + r + 1, tmp) - a[d];       ans += 1ll * (R[d][r] - R[d][id - 1]) * (t - T[x]) + sum[d][id - 1] -              sum[d][l - 1];       T[x] = t;       return;     }     if (T[x] >= 0) T[x << 1] = T[x << 1 | 1] = T[x];     int mid = (l + r) >> 1;     if (ql <= mid) Find(x << 1, l, mid, d + 1);     if (qr > mid) Find(x << 1 | 1, mid + 1, r, d + 1);     T[x] = (T[x << 1] == T[x << 1 | 1]) ? T[x << 1] : -1;   }   int main() {     scanf( %d , &n);     Build(1, 1, n, 0);     scanf( %d , &Q);     while (Q--) {       scanf( %d , &t);       scanf( %d , &ql);       scanf( %d , &qr);       ans = 0;       Find(1, 1, n, 0);       printf( %I64d n , ans);     }   }
#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();   }   using namespace std;   int t;   int pri[4001000], pcnt;   bool depri[35001000];   inline void init() {     depri[1] = true;     const int up = 3.5e7;     for (int i = 2; i <= up; ++i) {       if (!depri[i]) pri[++pcnt] = i;       for (int j = 1; j <= pcnt && i * pri[j] <= up; ++j) {         depri[i * pri[j]] = true;         if (i % pri[j] == 0) break;       }     }   }   struct TC {     int id;     long long n, k;     inline bool operator<(const TC &a) const { return k < a.k; }   } tc[10100];   bool ans[10100];   long long p[100];   int ptot;   inline void Div(long long x) {     ptot = 0;     for (int i = 1; 1ll * pri[i] * pri[i] <= x; ++i) {       if (x % pri[i] == 0) {         p[++ptot] = pri[i];         while (x % pri[i] == 0) x /= pri[i];       }     }     if (x != 1) p[++ptot] = x;   }   struct node {     int cur;     long long val;     inline bool operator<(const node &a) const { return val > a.val; }   };   priority_queue<node> q;   long long dis[100100];   bool vis[100100];   inline void Update(long long k) {     Div(k);     if (ptot <= 2) return;     memset(dis, 0x3f, sizeof(dis));     memset(vis, 0, sizeof(vis));     dis[0] = 0;     q.push((node){0, 0});     while (!q.empty()) {       int cur = (q.top()).cur;       q.pop();       if (vis[cur]) continue;       vis[cur] = true;       for (int i = 2; i <= ptot; ++i) {         int to = (cur + p[i]) % p[1];         long long val = (cur + p[i]) / p[1];         if (dis[to] <= dis[cur] + val) continue;         dis[to] = dis[cur] + val;         q.push((node){to, dis[to]});       }     }   }   inline long long quickmul(long long x, long long k, long long P) {     x = (x % P + P) % P;     k = (k % P + P) % P;     long long res = 0;     while (k) {       if (k & 1) res = (res + x) % P;       x = (x + x) % P;       k >>= 1;     }     return res;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1;       y = 0;       return a;     }     long long g = exgcd(b, a % b, x, y);     long long tmp = x;     x = y;     y = tmp - a / b * y;     return g;   }   inline bool get_ans(long long n) {     if (!ptot) return false;     if (ptot == 1) return n % p[1] == 0;     if (ptot == 2) {       long long x = 0, y = 1;       exgcd(p[1], p[2], x, y);       x = quickmul(x, n, p[2]);       if (1.0 * x * p[1] > 2e18) return false;       return n >= x * p[1];     }     if (1.0 * dis[n % p[1]] * p[1] > 2e18) return false;     return dis[n % p[1]] * p[1] + n % p[1] <= n;   }   signed main() {     init();     read(t);     for (int i = 1; i <= t; ++i) {       read(tc[i].n), read(tc[i].k);       tc[i].id = i;     }     sort(tc + 1, tc + 1 + t);     for (int i = 1; i <= t; ++i) {       if (tc[i].k != tc[i - 1].k) Update(tc[i].k);       ans[tc[i].id] = get_ans(tc[i].n);     }     for (int i = 1; i <= t; ++i) puts(ans[i] ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   std::vector<long long> factorial;   void precompute_factorial(int ma) {     factorial.push_back(1);     for (int i = 1; i <= ma; i++)       factorial.push_back((factorial.back() * i) % MOD);   }   long long power(long long base, int e) {     long long result = 1;     while (e) {       if (e & 1) result = (result * base) % MOD;       base = (base * base) % MOD;       e >>= 1;     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     precompute_factorial(n + 1);     vector<long long> inv_factorial(n + 1, 1);     for (int i = 2; i < n + 1; i++)       inv_factorial[i] = power(factorial[i], MOD - 2);     vector<long long> inv(n + 2);     for (int i = 1; i < n + 2; i++) inv[i] = power(i, MOD - 2);     if (k == 0) {       cout << ((factorial[n] - factorial[n - 1] + MOD) % MOD) << endl;       return 0;     }     vector<long long> dp2(n + 1, 1);     vector<long long> xxx(n + 1, 1);     long long sum = 0;     for (int i = 1; i < n + 1; i++) {       sum = (sum + xxx[i - 1]) % MOD;       if (i - 1 - k >= 0) {         sum = (sum + MOD - xxx[i - 1 - k]) % MOD;       }       dp2[i] = (sum * factorial[i - 1]) % MOD;       xxx[i] = (dp2[i] * inv_factorial[i]) % MOD;     }     vector<long long> dp(n + 1, 0);     long long last = 0;     long long total = 0;     for (int i = k + 2; i <= n; i++) {       long long y = i - k - 2;       long long tt = dp2[y];       tt = (tt + MOD) % MOD;       tt = (tt * inv_factorial[y]) % MOD;       tt = (tt * inv[i - 1]) % MOD;       last += tt;       last %= MOD;       total += last;       total %= MOD;       dp[i] = (factorial[i - 1] * total) % MOD;     }     cout << dp.back() << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const int M = 505;   const int MOD = int(1e9) + 7;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-9;   const double PI = acos(-1.0);   const int dx[] = {-1, 1, 0, 0};   const int dy[] = {0, 0, -1, 1};   template <class T>   inline T Min(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T Max(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T Min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T Max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T sqr(T a) {     return a * a;   }   template <class T>   inline T cub(T a) {     return a * a * a;   }   template <class T>   inline T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     return a * b / gcd(a, b);   }   int main() {     int a, b;     while (scanf( %d%d , &a, &b) != EOF) {       int i, tot = (a * (a - 1)) / 2;       if (tot <= b) {         printf( no solution n );       } else {         for (i = 0; i < a; i++) {           printf( %d %d n , 0, i);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int A[600006];   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   map<pair<int, int>, int> M;   int L[600006], R[600006], lst[600006], cn;   struct que {     int l, r, idx;   } Q[600006];   vector<int> bc[600006];   int T[600006];   void ad(int x, int c) {     while (x <= cn) T[x] += c, x += (x & -x);   }   int sum(int x) {     int ret = 0;     while (x > 0) ret += T[x], x -= (x & -x);     return ret;   }   int ans[600006];   void solve() {     cin >> n;     for (int i = (1), iend = (n); i <= iend; ++i) {       int k;       scanf( %d , &k);       L[i] = cn + 1;       int px, py, tx, ty, x, y, sx, sy;       scanf( %d%d , &px, &py);       sx = px, sy = py;       for (int j = (1), jend = (k); j <= jend; ++j) {         if (j != k)           scanf( %d%d , &x, &y);         else           x = sx, y = sy;         tx = x, ty = y;         x -= px, y -= py;         int g = gcd(abs(x), abs(y));         x /= g, y /= g;         ++cn;         lst[cn] = M[make_pair(x, y)];         bc[lst[cn]].push_back(cn);         M[make_pair(x, y)] = cn;         px = tx, py = ty;       }       R[i] = cn;     }     cin >> q;     for (int i = (1), iend = (q); i <= iend; ++i) {       int l, r;       scanf( %d%d , &l, &r);       l = L[l], r = R[r];       Q[i] = (que){l, r, i};     }     sort(Q + 1, Q + 1 + q, [](que a, que b) { return a.l < b.l; });     int cur = 1;     for (int i = (0), iend = (cn); i <= iend; ++i) {       while (cur <= q && Q[cur].l == i) {         ans[Q[cur].idx] = sum(Q[cur].r) - sum(Q[cur].l - 1);         ++cur;       }       for (int x : bc[i]) ad(x, 1);     }     for (int i = (1), iend = (q); i <= iend; ++i) printf( %d n , ans[i]);   }   signed main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const long long remi = 1000000007;   const long long remi2 = 998244353;   const long long inf = 1e18 + 1e17 + 1e16 + 1e15 + 1e14;   long long Pow(long long x, long long y, long long m) {     if (y == 0) return 1;     long long p = Pow(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j, k;     long long n, m;     cin >> n >> m;     vector<long long> v(m);     for (i = 0; i < m; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     bool ans = true;     if (m == 0) {       cout <<  YES ;       exit(0);     }     if (v[0] == 1 or v[m - 1] == n) ans = false;     for (i = 2; i < m; i++) {       long long s0 = v[i - 2];       long long s1 = v[i - 1];       long long s2 = v[i];       if ((s0 == s2 - 2) and (s1 == s2 - 1)) ans = false;     }     if (ans)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;      int main()   {    ios_base::sync_with_stdio(false), cin.tie(0);    int t;    cin >> t;    while (t--) {     map<int, int>L, R;     int bal = 0;     string s;     cin >> s;     for (char &c : s) {      if (c ==  1 ) {       R[bal]++;       bal++;      } else {       L[bal]++;       bal--;      }     }        int cur = 0;     while (L[cur] > 0 || R[cur] > 0) {      if (L[cur] > 0 && R[cur - 1] > 0 || (!R[cur] && !L[cur + 1])) {       L[cur]--;       cur--;       cout << 0;      } else {       R[cur]--;       cur++;       cout << 1;      }     }     cout <<   n ;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tree[100010 << 2];   bool flag;   struct node {     int row, col, pos;     friend bool operator<(node a, node b) {       if (a.row == b.row) return a.col < b.col;       return a.row < b.row;     }   };   node p[100010];   inline void pushUp(int rt) { tree[rt] = min(tree[rt << 1], tree[rt << 1 | 1]); }   void update(int x, int y, int val, int L, int R, int rt) {     if (flag) return;     if (L == R) {       if (tree[rt] == 0) {         flag = true;         tree[rt] = val;       }       return;     } else if (x <= L && R <= y) {       int mid = (L + R) >> 1;       if (tree[rt << 1] == 0)         update(x, y, val, L, mid, rt << 1);       else if (tree[rt << 1 | 1] == 0)         update(x, y, val, mid + 1, R, rt << 1 | 1);     } else {       int mid = (L + R) >> 1;       if (x <= mid) update(x, y, val, L, mid, rt << 1);       if (y > mid) update(x, y, val, mid + 1, R, rt << 1 | 1);     }     pushUp(rt);   }   void out(int L, int R, int rt) {     if (L == R) {       if (tree[rt]) printf( %d  , tree[rt]);     } else {       int mid = (L + R) >> 1;       out(L, mid, rt << 1);       out(mid + 1, R, rt << 1 | 1);     }   }   int main() {     int i;     int n, m, cnt;     while (~scanf( %d%d , &n, &m)) {       memset(tree, 0, sizeof(tree));       for (i = 0; i < m; i++) {         scanf( %d%d , &p[i].row, &p[i].col);         p[i].pos = i + 1;       }       sort(p, p + m);       for (cnt = i = 0; i < m; i++) {         flag = false;         update(n - p[i].col + 1, p[i].row, p[i].pos, 1, n, 1);         if (flag) cnt++;       }       printf( %d n , cnt);       out(1, n, 1);       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n, t, sz[200010], cen;   vector<int> g[200010], v;   bool mark[200010];   int dfs(int pos, int par) {     sz[pos] = (int)mark[pos];     bool ok = true;     for (int i = 0; i < g[pos].size(); i++)       if (g[pos][i] != par) {         sz[pos] += dfs(g[pos][i], pos);         if (sz[g[pos][i]] > t) ok = false;       }     if (ok && sz[pos] >= t) cen = pos;     return sz[pos];   }   void dfs2(int pos, int par) {     if (mark[pos]) v.push_back(pos);     for (int i = 0; i < g[pos].size(); i++)       if (g[pos][i] != par) dfs2(g[pos][i], pos);   }   int main() {     cin >> n >> t;     int x, y;     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 0; i < t + t; i++) {       scanf( %d , &x);       mark[x] = true;     }     dfs(1, 0);     for (int i = 0; i < g[cen].size(); i++) dfs2(g[cen][i], cen);     if (mark[cen]) v.push_back(cen);     cout << 1 << endl << cen << endl;     for (int i = 0; i < t; i++) printf( %d %d %d n , v[i], v[i + t], cen);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int countbit(T n) {     return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));   }   template <class T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const double EPS = 1e-9;   const double PI = acos(-1.0);   int n, k, h;   int ind[100005];   int vel[100005];   int mass[100005];   int ret[100005];   bool can(double mid) {     int cnt = 0;     double step = k;     for (int j = n - 1; j >= 0 && cnt <= k; j--) {       double tempo = step * h / ((double)vel[ind[j]]);       if (tempo < mid - EPS || fabs(tempo - mid) < EPS) cnt++, step--;     }     return cnt >= k;   }   bool cmp(int i, int j) {     if (mass[i] != mass[j]) return mass[i] < mass[j];     return vel[i] < vel[j];   }   int main(void) {     scanf( %d %d %d , &n, &k, &h);     for (int i = (0); i < int(n); i++) scanf( %d , &mass[i]);     for (int i = (0); i < int(n); i++) scanf( %d , &vel[i]);     for (int i = (0); i < int(n); i++) ind[i] = i;     sort(ind, ind + n, cmp);     double l = 0, r = 10E9 + 100;     for (int i = (0); i < int(100); i++) {       double mid = (l + r) / 2;       if (can(mid))         r = mid;       else         l = mid;     }     double mid = r, step = k;     int p = k - 1;     for (int j = n - 1; j >= 0 && p >= 0; j--) {       double tempo = step * h / ((double)vel[ind[j]]);       if (tempo < mid - EPS || fabs(tempo - mid) < EPS) {         step--;         ret[p--] = ind[j] + 1;       }     }     for (int i = (0); i < int(k); i++) {       if (i) printf(   );       printf( %d , ret[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   map<int, int> mym;   void kaisa() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     queue<int> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       mym[x] = 0;       q.push(x);     }     long long res = 0;     vector<int> ans;     while (!q.empty()) {       int x = q.front();       q.pop();       if (mym[x] != 0) {         res += mym[x];         ans.push_back(x);         if (ans.size() == m) break;       }       if (!mym.count(x + 1)) {         mym[x + 1] = mym[x] + 1;         q.push(x + 1);       }       if (!mym.count(x - 1)) {         mym[x - 1] = mym[x] + 1;         q.push(x - 1);       }     }     cout << res <<   n ;     for (int i : ans) {       cout << i <<    ;     }     cout <<   n ;   }   int main() {     kaisa();     return 0;   }