malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int a[201][3];   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     vector<string> a;     for (int i = 0; i < n; i++) {       string r;       cin >> r;       a.push_back(r);     }     int count = 0, ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < a[i].size(); j++) {         if (a[i][j] ==  4  || a[i][j] ==  7 ) count++;         if (count > k) break;       }       if (count <= k) ans++;       count = 0;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int to, cost;   };   vector<edge> G[500005];   int q, n, k;   long long f[500005], g[500005];   vector<long long> weights[500005];   void add_edge(int u, int v, int cost) {     G[u].push_back((edge){v, cost});     G[v].push_back((edge){u, cost});   }   void dfs(int v, int p) {     f[v] = g[v] = 0;     for (auto e : G[v]) {       if (e.to == p) continue;       dfs(e.to, v);       f[v] += f[e.to];       g[v] += f[e.to];       weights[v].push_back(e.cost + g[e.to] - f[e.to]);     }     sort(weights[v].begin(), weights[v].end(), greater<long long>());     long long sum1 = 0, sum2 = 0;     for (int i = 0; i < (int)weights[v].size(); i++) {       if (weights[v][i] <= 0) break;       if (i < k - 1) sum1 += weights[v][i];       if (i < k) sum2 += weights[v][i];     }     f[v] += sum2;     g[v] += sum1;   }   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; i++) G[i].clear(), weights[i].clear();       for (int i = 0; i < n - 1; i++) {         int u, v, cost;         scanf( %d%d%d , &u, &v, &cost);         add_edge(u, v, cost);       }       dfs(1, 0);       printf( %lld n , f[1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 ran(time(0));   long long mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long Bpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) {         ans *= a;         ans %= mod;       }       a = a * a % mod;       b >>= 1;     }     return ans;   }   const long long MX = 1 << 19;   long long t1[2 * MX];   long long t2[2 * MX];   void upd(long long x) {     x += MX;     for (; x > 0; x >>= 1) {       t1[x]++;     }   }   void upd2(long long l, long long r, long long x) {     for (l += MX, r += MX; l <= r; l >>= 1, r >>= 1) {       if (l & 1) {         t2[l++] -= x;       }       if (~r & 1) t2[r--] -= x;     }   }   long long get1(long long l, long long r) {     long long ans = 0;     for (l += MX, r += MX; l <= r; l >>= 1, r >>= 1) {       if (l & 1) ans += t1[l++];       if (~r & 1) ans += t1[r--];     }     return ans;   }   long long get2(long long x) {     x += MX;     long long ans = 0;     while (x > 0) {       ans += t2[x];       x >>= 1;     }     return ans;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 0;     vector<long long> h(MX + 1);     long long sum = 0;     for (long long i = 0; i < n; i++) {       ans += sum + i * a[i];       long long now = a[i];       while (now < MX) {         long long v = get1(now, MX - 1);         upd2(now + (a[i] == now), MX - 1, a[i]);         ans -= a[i] * v;         now += a[i];       }       ans += get2(a[i]);       upd(a[i]);       h[a[i]]++;       sum += a[i];       cout << ans <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 * 1000 + 23, D = 1000 * 1000 * 1000 + 7, MXLN = 17 + 3;   int mul() { return 1; }   template <typename... T>   int mul(int x, T... a) {     return 1ll * x * mul(a...) % D;   }   int add() { return 0; }   template <typename... T>   int add(int x, T... a) {     return (x + add(a...)) % D;   }   int n, e[MAXN], w[MAXN], sum[MAXN], sum2[MAXN], up[MAXN], up2[MAXN], sz[MAXN],       h[MAXN], par[MXLN][MAXN], dis[MAXN], q;   vector<int> g[MAXN];   void dfs(int v = 0, int p = -1) {     for (auto i : g[v]) {       int u = v ^ e[i];       if (u == p) continue;       h[u] = h[v] + 1;       dis[u] = add(dis[v], w[i]);       par[0][u] = v;       dfs(u, v);       sz[v] += sz[u];       sum[v] = add(sum[v], sum[u], mul(sz[u], w[i]));       sum2[v] =           add(sum2[v], mul(w[i], w[i], sz[u]), sum2[u], mul(2, w[i], sum[u]));     }     sz[v]++;   }   void ufs(int v = 0, int p = -1) {     int tmp = up[v], tmp2 = up2[v];     for (auto i : g[v]) {       int u = v ^ e[i];       if (u == p) continue;       tmp = add(tmp, sum[u], mul(sz[u], w[i]));       tmp2 = add(tmp2, mul(w[i], w[i], sz[u]), sum2[u], mul(2, w[i], sum[u]));     }     for (auto i : g[v]) {       int u = v ^ e[i];       if (u == p) continue;       up[u] = add(tmp, D - sum[u], D - mul(sz[u], w[i]), mul(w[i], (n - sz[u])));       up2[u] = add(tmp2, D - mul(w[i], w[i], sz[u]), D - sum2[u],                    D - mul(2, w[i], sum[u]), mul(w[i], w[i], n - sz[u]),                    mul(2, w[i], add(tmp, D - sum[u], D - mul(sz[u], w[i]))));       ufs(u, v);     }   }   int lca(int u, int v) {     if (h[u] < h[v]) swap(u, v);     for (int i = MXLN - 1; ~i; i--)       if (h[par[i][u]] >= h[v]) u = par[i][u];     if (u == v) return v;     for (int i = MXLN - 1; ~i; i--)       if (par[i][u] != par[i][v]) {         u = par[i][u];         v = par[i][v];       }     return par[0][v];   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       g[--a].push_back(i), g[--b].push_back(i);       e[i] = a ^ b;       w[i] = c;     }     dfs(), ufs();     for (int i = 1; i < MXLN; i++)       for (int j = 0; j < n; j++) par[i][j] = par[i - 1][par[i - 1][j]];     cin >> q;     while (q--) {       int u, v;       cin >> u >> v;       int x = lca(--u, --v);       if (x == v) {         int fas = add(dis[u], D - dis[v]),             tmp = D - add(up2[v], mul(fas, fas, (n - sz[v])), mul(2, fas, up[v]));         cout << add(sum2[u], up2[u], tmp, tmp) <<   n ;       } else {         int fas = ((x == u) ? add(dis[v], D - dis[u])                             : add(dis[u], dis[v], D - dis[x], D - dis[x])),             tmp = add(mul(fas, fas, sz[v]), sum2[v], mul(2, fas, sum[v]));         cout << add(tmp, D - sum2[u], D - up2[u], tmp) <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int z[201010];   int cost[201010], acc[201010];   string s, aux, text, text2, patt;   pair<int, int> dp[201010];   void build() {     text = aux;     text2 = aux;     int n = (int)aux.size();     for (int i = 0; i < n; i++) {       cost[i] = -1;       acc[i] = 0;       if (aux[i] ==  ? ) {         text[i] =  a ;         text2[i] =  b ;         if (i % 2 == 0) swap(text[i], text2[i]);         acc[i] = 1;       }       if (i) acc[i] += acc[i - 1];     }   }   int getCost(int l, int r) { return acc[r] - (l ? acc[l - 1] : 0); }   void Z() {     int l = 0, r = 0, n = (int)s.size();     z[0] = 0;     for (int i = 1; i < n; i++) {       z[i] = 0;       if (i <= r) z[i] = min(z[i - l], r - i + 1);       while (i + z[i] < n && s[z[i]] == s[z[i] + i]) z[i]++;       if (i + z[i] - 1 >= r) {         l = i;         r = i + z[i] - 1;       }       if (z[i] == (int)patt.size())         cost[i - 2] = getCost(i - (int)patt.size() - 1, i - 2);     }   }   pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> maxx(pair<int, int> a, pair<int, int> b) {     if (a.first > b.first) return a;     if (a.first < b.first) return b;     return make_pair(a.first, min(a.second, b.second));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int m, n;     cin >> n;     cin >> aux;     cin >> m;     patt =   ;     for (int i = 0; i < m; i++) {       if (i % 2 == 0)         patt +=  a ;       else         patt +=  b ;     }     build();     s = patt +  $  + text;     Z();     s = patt +  $  + text2;     Z();     for (int i = 0; i < n; i++) {       dp[i] = i ? dp[i - 1] : make_pair(0, 0);       if (cost[i] != -1) {         dp[i] = maxx(dp[i], dp[i - m] + make_pair(1, cost[i]));       }     }     cout << dp[n - 1].second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 5005;   int dp[mxn][mxn], ans, n, a[mxn];   int md7[8], pos[114514];   inline void ckmax(int& x, int y) {     if (x < y) x = y;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 0; i <= n; ++i) {       for (int j = 0; j <= n; ++j) {         if (i < j)           dp[i][j] =               max({md7[a[j] % 7], pos[a[j] - 1], pos[a[j] + 1], dp[0][i]}) + 1;         else           dp[i][j] = dp[j][i];         ckmax(ans, dp[i][j]);         ckmax(md7[a[j] % 7], dp[i][j]);         ckmax(pos[a[j]], dp[i][j]);       }       memset(md7, 0, sizeof(md7));       memset(pos, 0, sizeof(pos));     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long value(const vector<long long>& a, long long b) {     long long result = 0;     for (int i = 0; i < a.size(); ++i) {       result += min(b, a[i]);     }     return result;   }   int main() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     long long sum = 0;     long long max_a = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];       max_a = max(max_a, a[i]);     }     if (sum < k) {       cout << -1;       return 0;     }     int l = 0;     int r = max_a;     while (r - l > 1) {       if (value(a, (l + r) / 2) > k) {         r = (l + r) / 2;       } else {         l = (l + r) / 2;       }     }     if (k >= value(a, r)) {       l = r;     }     k -= value(a, l);     queue<pair<int, int> > q;     for (int i = 0; i < n; ++i) {       if (a[i] > l) {         q.push(make_pair(a[i] - l, i));       }     }     while (k > 0) {       --k;       pair<int, int> t = q.front();       q.pop();       --t.first;       if (t.first > 0) {         q.push(t);       }     }     while (!q.empty()) {       cout << q.front().second + 1 <<    ;       q.pop();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 2e2 + 10;   vector<string> v[N];   int nex[N];   int flag[N];   int main() {     int n;     cin >> n;     map<char, int> mc;     memset((nex), (-1), sizeof(nex));     while (n--) {       string str;       cin >> str;       int o = 0;       for (auto &c : str) {         mc[c] = 1;         if (flag[c] == 0) flag[c] = 1;         if (o >> (c -  0 ) & 1) {           puts( NO );           return 0;         }         o |= 1 << (c -  0 );       }       for (int i = 0; i + 1 < str.length(); i++) {         if (nex[str[i]] == -1) {           nex[str[i]] = str[i + 1];           flag[str[i + 1]] = 2;         }         if (nex[str[i]] != str[i + 1]) {           puts( NO );           return 0;         }       }     }     string ans;     for (int i =  a ; i <=  z ; i++) {       if (flag[i] != 1) continue;       int c = i;       while (c != -1 && ans.length() <= mc.size()) {         ans.push_back(c);         c = nex[c];       }     }     if (ans.length() != mc.size()) {       puts( NO );     } else       puts(ans.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using v2d = vector<vector<T> >;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   const int maxN = 2e5 + 10;   int n, q;   vector<int> adj[maxN];   int t[maxN], in[maxN], out[maxN], f[maxN * 4], lazy[maxN * 4], mp[maxN];   int L, R;   void dfs(int u) {     in[u] = ++in[0];     mp[in[u]] = u;     for (auto &v : adj[u]) {       dfs(v);     }     out[u] = in[0];   }   void build(int x, int lo, int hi) {     if (lo == hi) {       f[x] = t[mp[lo]];       return;     }     int mid = (lo + hi) / 2;     build(x * 2, lo, mid);     build(x * 2 + 1, mid + 1, hi);     f[x] = f[x * 2] + f[x * 2 + 1];   }   void down(int x, int lo, int hi) {     int t = lazy[x];     lazy[x] = 0;     if (t & 1) {       int mid = (lo + hi) / 2;       ++lazy[x * 2];       f[x * 2] = mid - lo + 1 - f[x * 2];       ++lazy[x * 2 + 1];       f[x * 2 + 1] = hi - mid - f[x * 2 + 1];     }   }   void update(int x, int lo, int hi) {     if (lo > R || hi < L) {       return;     }     if (lo >= L && hi <= R) {       f[x] = hi - lo + 1 - f[x];       ++lazy[x];       return;     }     down(x, lo, hi);     int mid = (lo + hi) / 2;     update(x * 2, lo, mid);     update(x * 2 + 1, mid + 1, hi);     f[x] = f[x * 2] + f[x * 2 + 1];   }   int query(int x, int lo, int hi) {     if (lo > R || hi < L) {       return 0;     }     if (lo >= L && hi <= R) {       return f[x];     }     int mid = (lo + hi) / 2;     down(x, lo, hi);     return query(x * 2, lo, mid) + query(x * 2 + 1, mid + 1, hi);   }   void solve() {     cin >> n;     for (int i = (int)(2); i <= (int)(n); ++i) {       int p;       cin >> p;       adj[p].emplace_back(i);     }     for (int i = 1; i <= (int)(n); ++i) {       cin >> t[i];     }     dfs(1);     build(1, 1, n);     cin >> q;     while (q--) {       string task;       int v;       cin >> task >> v;       if (task ==  get ) {         L = in[v], R = out[v];         cout << query(1, 1, n) <<   n ;       } else {         L = in[v], R = out[v];         update(1, 1, n);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1234567], ans[1234567];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int in = 0;     for (int i = 0; i < n; i++)       if (!a[i]) {         in = i;         break;       }     for (int i = 0; i <= in; i++) ans[i] = in - i;     for (int i = in + 1; i < n; i++) {       if (!a[i]) in = i;       ans[i] = abs(i - in);     }     for (int i = n - 1; i >= 0; i--)       if (!a[i]) {         in = i;         break;       }     for (int i = n - 1; i >= 0; i--) {       if (!a[i]) in = i;       ans[i] = min(ans[i], abs(i - in));     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, s = 0, a;   int sg(int x) {     if (x == 0 || x == 1) return x;     if (k % 2 == 0) {       if (x == 2) return 2;       if (x % 2 == 0)         return 1;       else         return 0;     } else {       if (x == 2) return 0;       if (x == 3) return 1;       if (x == 4) return 2;       if (x % 2 == 0) {         int cnt = 0;         while (x % 2 == 0) x /= 2, cnt++;         if (x == 3) cnt++;         if (cnt % 2)           return 1;         else           return 2;       } else         return 0;     }   }   int main(void) {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a;       s ^= sg(a);     }     if (s == 0)       cout <<  Nicky n ;     else       cout <<  Kevin n ;   }
#include <bits/stdc++.h>   using namespace std;   const int mn = 2e5 + 10;   int bit[mn];   void update(int a, int b) {     for (; a < mn; a += a & -a) bit[a] += b;   }   int query(int a) {     int b = 0;     for (; a; a -= a & -a) b += bit[a];     return b;   }   int a[mn], v[mn], n;   void go() {     int i;     for (i = 0; i < n; i++) scanf( %d , a + i), a[i]++;     for (i = 1; i <= n; i++) update(i, 1);     for (i = 0; i < n; i++) {       v[i] += query(a[i]) - 1;       update(a[i], -1);     }   }   int main() {     int i;     scanf( %d , &n);     go();     go();     for (i = n - 1; i; i--) {       if (v[i] >= n - i) v[i] -= n - i, v[i - 1]++;     }     v[0] %= n;     for (i = 1; i <= n; i++) update(i, 1);     for (i = 0; i < n; i++) {       int cur = 0, tot = 0;       for (int j = 1 << 17; j; j >>= 1) {         if (cur + j > n) continue;         if (tot + bit[cur + j] < v[i] + 1) cur += j, tot += bit[cur];       }       printf( %d  , cur);       update(cur + 1, -1);     }   }
#include <bits/stdc++.h>   using namespace std;   void reverseQueue(queue<long long int>& q) {     if (q.empty()) return;     long long int data = q.front();     q.pop();     reverseQueue(q);     q.push(data);   }   int main() {     ios_base::sync_with_stdio(0);     int n, k;     cin >> n >> k;     vector<long long int> friends;     queue<long long int> q;     map<long long int, int> check;     for (int i = 0, temp; i < n; i++) {       cin >> temp;       friends.emplace_back(temp);       if (i < k) {         if (check.find(friends[i]) == check.end() || check[friends[i]] == 0) {           q.push(temp);           check[temp] = 1;         }       }     }     for (int i = k; i < n; i++) {       if (check.find(friends[i]) == check.end() || check[friends[i]] == 0) {         if (q.size() == k) {           check[q.front()] = 0;           q.pop();         }         q.push(friends[i]);         check[friends[i]] = 1;       }     }     reverseQueue(q);     cout << q.size() << endl;     while (!q.empty()) {       cout << q.front() <<    ;       q.pop();     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int n, m;     char g[1000][1000];     int min_row = 1000, max_row = -1;     int min_col = 1000, max_col = -1;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf(  %c , &g[i][j]);         if (g[i][j] ==  B ) {           min_row = std::min(min_row, i);           max_row = std::max(max_row, i);           min_col = std::min(min_col, j);           max_col = std::max(max_col, j);         }       }     }     if (max_row == -1) {       puts( 1 );     } else {       int missing_from_rect = 0;       for (int i = min_row; i <= max_row; i++) {         for (int j = min_col; j <= max_col; j++) {           missing_from_rect += (g[i][j] ==  W );         }       }       const int n_rows = (max_row - min_row + 1);       const int n_cols = (max_col - min_col + 1);       bool feasible = true;       int additional = 0;       if (n_rows > n_cols) {         const int needed = n_rows - n_cols;         if (n_cols + needed > m) {           feasible = false;         } else {           additional = needed * n_rows;         }       } else if (n_rows < n_cols) {         const int needed = n_cols - n_rows;         if (n_rows + needed > n) {           feasible = false;         } else {           additional = needed * n_cols;         }       }       if (feasible) {         printf( %d n , missing_from_rect + additional);       } else {         puts( -1 );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct qq {     char c;     long long dis;   } a[500050], b[500050], c[500050], d[500050], e[500050], f[500050], g[500050],       h[500050];   int cmp(qq a, qq b) { return a.dis < b.dis; }   int main() {     int n;     cin >> n;     int x, y;     cin >> x >> y;     int fa = 0, fb = 0, fc = 0, fd = 0, fe = 0, ff = 0, fg = 0, fh = 0;     for (int i = 0; i < n; i++) {       int xx, yy;       char cc;       getchar();       scanf( %c%d%d , &cc, &xx, &yy);       xx -= x;       yy -= y;       if (xx == 0) {         if (yy < 0)           a[fa].c = cc, a[fa++].dis = -yy;         else           b[fb].c = cc, b[fb++].dis = yy;       }       if (yy == 0) {         if (xx < 0)           c[fc].c = cc, c[fc++].dis = -xx;         else           d[fd].c = cc, d[fd++].dis = xx;       }       if (xx == yy) {         if (yy < 0) {           e[fe].c = cc, e[fe++].dis = -xx;         } else {           f[ff].c = cc, f[ff++].dis = xx;         }       }       if (xx == -yy) {         if (yy < 0) {           g[fg].c = cc, g[fg++].dis = xx;         } else {           h[fh].c = cc, h[fh++].dis = -xx;         }       }     }     sort(a, a + fa, cmp);     sort(b, b + fb, cmp);     sort(c, c + fc, cmp);     sort(d, d + fd, cmp);     sort(e, e + fe, cmp);     sort(f, f + ff, cmp);     sort(g, g + fg, cmp);     sort(h, h + fh, cmp);     if (a[0].c ==  R  || a[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (b[0].c ==  R  || b[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (c[0].c ==  R  || c[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (d[0].c ==  R  || d[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (e[0].c ==  B  || e[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (f[0].c ==  B  || f[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (g[0].c ==  B  || g[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (h[0].c ==  B  || h[0].c ==  Q ) {       printf( YES n );       return 0;     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool ok[100010];   int a[100010];   int b[100010];   int c[100010];   vector<int> ans;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     memset(ok, false, sizeof(ok));     long long now, min_value;     for (int i = 1; i <= n; i++) c[i] = a[i] - b[i];     now = 0;     min_value = 0;     for (int i = 1; i <= n; i++) {       now += c[i];       min_value = min(min_value, now);     }     for (int i = 1; i <= n; i++) {       if (min_value == 0) ok[i] = true;       min_value -= c[i];       min_value = min((long long)0, min_value);     }     c[n] = a[1] - b[n];     for (int i = n; i >= 2; i--) c[n - i + 1] = a[i] - b[i - 1];     now = 0;     min_value = 0;     for (int i = 1; i <= n; i++) {       now += c[i];       min_value = min(min_value, now);     }     for (int i = 1; i <= n; i++) {       if (min_value == 0) ok[n - i + 1] = true;       min_value -= c[i];       min_value = min((long long)0, min_value);     }     ans.clear();     for (int i = 1; i <= n; i++)       if (ok[i]) ans.push_back(i);     int len = ans.size();     printf( %d n , len);     for (int i = 0; i < len; i++) {       printf( %d , ans[i]);       if (i == len - 1)         printf(  n );       else         printf(   );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, p;   int bin[32] = {0};   bool check(int x) {     int m = n - x * p;     int res = 0;     if (m < x) return 0;     for (int i = 0; i <= 31; i++)       if (m & bin[i]) {         x--;         if (x < 0) return 0;       }     return 1;   }   int main() {     bin[0] = 1;     for (int i = 1; i <= 31; i++) bin[i] = bin[i - 1] << 1;     n = read();     p = read();     for (int i = 1; i <= 100; i++)       if (check(i)) {         cout << i << endl;         return 0;       }     puts( -1 );     return 0;   }