malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int pre[N];   int find(int x) {     if (!pre[x]) return x;     return pre[x] = find(pre[x]);   }   int d[510][510];   struct point {     int x, y, z;     void read() { scanf( %d%d%d , &x, &y, &z); }   } a[N];   int type[N];   int main() {     int n, m, r, x, y;     scanf( %d%d%d , &n, &m, &r);     int t = 0;     for (int i = 1; i <= r; i++) {       scanf( %d , &x);       while (x--) type[++t] = i;     }     for (int i = 1; i <= m; i++) {       a[i].read();       if (a[i].z == 0) {         x = find(a[i].x);         y = find(a[i].y);         if (x != y) pre[x] = y;       }     }     for (int i = 2; i <= n; i++)       if (type[i] == type[i - 1] && find(i) != find(i - 1)) {         cout <<  No  << endl;         return 0;       }     memset(d, -1, sizeof(d));     for (int i = 1; i <= m; i++) {       x = type[a[i].x], y = type[a[i].y];       if (d[x][y] == -1)         d[y][x] = d[x][y] = a[i].z;       else         d[y][x] = d[x][y] = min(d[x][y], a[i].z);     }     for (int i = 1; i <= r; i++) d[i][i] = 0;     for (int k = 1; k <= r; k++)       for (int i = 1; i <= r; i++)         for (int j = 1; j <= r; j++)           if (d[i][k] != -1 && d[k][j] != -1)             if (d[i][j] == -1)               d[i][j] = d[i][k] + d[k][j];             else               d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     cout <<  Yes  << endl;     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= r; j++) {         printf( %d  , d[i][j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, n, x, y;     cin >> a >> b >> c >> d >> n;     if (c < d) swap(a, b), swap(c, d);     cout << max(0, n - (c - 1) * a - (d - 1) * b) <<    ;     if (b * d >= n) {       cout << n / d;       return 0;     }     cout << b + (n - b * d) / c;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int lim = sqrt(n) + 1;     if (!(n & 1)) {       cout << n / 2 << endl;       return 0;     }     for (long long int i = 3; i <= lim + 1; i++) {       if (n % i == 0) {         cout << (n - i) / 2 + 1 << endl;         return 0;       }     }     puts( 1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char g[10][10];   int ax[10 * 10], n;   bool use[10 * 10];   int q[2][100], ct[2], vst[8][8];   int dx[9] = {0, 0, 0, 1, -1, 1, 1, -1, -1};   int dy[9] = {0, 1, -1, 0, 0, -1, 1, -1, 1};   bool check(int x, int y) {     if (x < 0 || y < 0 || x >= 8 || y >= 8) return 0;     if (vst[x][y]) return 0;     for (int i = 0; i < n; i++)       if (ax[i] % 8 == y && (ax[i] / 8 == x || ax[i] / 8 == x - 1)) return 0;     return 1;   }   int bfs() {     q[0][0] = 7 * 8;     ct[0] = 1;     for (int i = 0; i < 10; i++) {       int id = i & 1, nid = id ^ 1;       ct[nid] = 0;       memset(vst, 0, sizeof(vst));       for (int j = 0; j < ct[id]; j++) {         int u = q[id][j];         int x = u / 8, y = u % 8;         for (int d = 0; d < 9; d++) {           int nx = x + dx[d], ny = y + dy[d];           if (check(nx, ny)) q[nid][ct[nid]++] = nx * 8 + ny, vst[nx][ny] = 1;           if (nx == 0 && ny == 7) return 1;         }       }       for (int j = 0; j < n; j++) ax[j] = (ax[j] / 8 + 1) * 8 + ax[j] % 8;     }     if (ct[0]) return 1;     return 0;   }   int main() {     n = 0;     for (int i = 0; i < 8; i++) {       scanf( %s , g[i]);       for (int j = 0; j < 8; j++)         if (g[i][j] ==  S ) ax[n++] = i * 8 + j;     }     if (bfs())       puts( WIN );     else       puts( LOSE );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   bool conn[8][8];   int a, b;   int v[8];   int cur;   bool used[8][8];   int best, cur2, cur3, cur4, ans;   int main() {     cin >> N >> M;     for (int i = 0; i < M; i++) {       cin >> a >> b;       conn[a][b] = conn[b][a] = true;     }     for (int i = 0; i < 279936; i++) {       cur = i;       for (int j = 0; j < 6; j++) {         for (int k = 0; k < 6; k++) {           used[j][k] = false;         }       }       for (int j = 0; j < 7; j++) {         v[j] = cur % 6;         cur /= 6;       }       cur2 = 0;       for (int j = 1; j <= N; j++) {         for (int k = j + 1; k <= N; k++) {           if (conn[j][k]) {             cur3 = v[j];             cur4 = v[k];             if (cur3 > cur4) {               swap(cur3, cur4);             }             if (!used[cur3][cur4]) {               ++cur2;               used[cur3][cur4] = true;             }           }         }       }       ans = max(ans, cur2);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long int lar(long long int a, long long int b) {     return ((a >= b) ? a : b);   }   long long int les(long long int a, long long int b) {     return ((a <= b) ? a : b);   }   int main() {     string s;     cin >> s;     vector<string> v;     long long int a = 0, b = 0;     for (long long int i = 0; i < s.size(); i++) {       if (s[i] ==  4 )         a++;       else if (s[i] ==  7 )         b++;     }     if (a == 0 && b == 0) {       cout << -1 << endl;       return 0;     }     if (a >= b)       cout <<  4  << endl;     else       cout <<  7  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[200005];   bool can(long long val, long long n, long long k) {     int m = (n + 1) / 2;     long long sum = 0;     for (int i = m; i <= n; i++) {       if (val > arr[i])         sum += val - arr[i];       else         break;     }     if (sum <= k)       return true;     else       return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     sort(arr + 1, arr + n + 1);     long long l = arr[(n + 1) / 2];     long long h = 3000000001;     while (l < h - 1) {       long long m = (l + h) / 2;       if (can(m, n, k)) {         l = m;       } else {         h = m;       }     }     if (can(h, n, k)) l = h;     cout << l <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int num = 0;     int n;     cin >> n;     int d;     int sh[n];     cin >> d;     for (int i = 0; i < n; i++) cin >> sh[i];     for (int i = 0; i < n; i++) {       for (int k = i + 1; k < n; k++) {         if (abs(sh[i] - sh[k]) <= d) num += 2;       }     }     cout << num;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> Map;   int n, m, i, j;   long long ans;   string s;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s;       m = s.size();       bool cnt[30];       for (j = 0; j < 26; j++) cnt[j] = 0;       for (j = 0; j < m; j++) cnt[s[j] -  a ] ^= 1;       int aux1 = 0;       for (j = 0; j < 26; j++) {         aux1 <<= 1;         aux1 |= cnt[j];       }       for (j = 0; j < 26; j++) ans += Map[aux1 ^ (1 << j)];       ans += Map[aux1];       Map[aux1]++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   int main() {     long long int n;     scanf( %lld , &n);     printf( %lld n , n / 2 + 1);     long long int count1 = 0;     long long int count2 = 1;     for (int i = 1; i <= n; i++) {       if (i % 2 == 0) {         count2++;       } else {         count1++;       }       printf( %lld %lld n , count1, count2);     }     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-4, pi = acos(-1.0);   const int maxS = 1e3 + 13;   const int maxT = 20;   const long long MOD = 1e9 + 7;   using namespace std;   struct point {     int x, y;   };   struct rs {     int x, y, z;   };   int n, m, i, j, k, x, y, z, S, T, ii, s, t, l, r, pos, len;   int tot = 0, ans = 0, res = 0, kase = 0, cnt = 0;   bool chk[maxS][maxS], flag = true;   string s1, s2;   char ch[maxS][maxS];   vector<rs> v;   point dr[5] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {0, 0}};   bool fk(int x, int y, int len) {     if (x - len < 0 || y - len < 0 || x + len >= n || y + len >= m) return false;     int i;     for (i = x - len; i <= x + len; i++)       if (ch[i][y] ==  . ) return false;     for (i = y - len; i <= y + len; i++)       if (ch[x][i] ==  . ) return false;     for (i = x - len; i <= x + len; i++) chk[i][y] = false;     for (i = y - len; i <= y + len; i++) chk[x][i] = false;     v.push_back({x, y, len});     return true;   }   bool ok(int x, int y) {     int i, j, k, len;     for (k = 0; k < 5; k++) {       for (i = 1; i < max(n, m); i++)         if (fk(x + dr[k].x * i, y + dr[k].y * i, i)) return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         cin >> ch[i][j];         if (ch[i][j] ==  * ) chk[i][j] = true;       }     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (flag && chk[i][j] && !ok(i, j)) flag = false;     if (!flag)       cout << -1 << endl;     else {       cout << v.size() << endl;       for (auto t : v) cout << t.x + 1 <<     << t.y + 1 <<     << t.z << endl;     }     return 0;   }
#include <bits/stdc++.h>      #define int long long   using namespace std;      const int MAX = 505;   int n, MOD, fact[MAX], C[MAX][MAX], f[2][MAX * MAX];      int getMaxInv(int x) {       return (x - 1) * x / 2;   }      int32_t main() {   #ifdef ACM       freopen( input ,  r , stdin);   #endif       cin >> n >> MOD;       fact[0] = 1;       for (int i = 1; i <= n; i++)           fact[i] = fact[i - 1] * i % MOD;       C[0][0] = 1;       for (int i = 1; i <= n; i++) {           C[i][0] = C[i][i] = 1;           for (int j = 1; j < n; j++)               C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       }       int rs = 0;       for (int i = 0; i < n; i++) {           for (int j = 1; j <= getMaxInv(n - 1); j++)               f[i % 2][j] = 0;           f[i % 2][0] = 1;           for (int inv = 1; inv <= getMaxInv(i); inv++) {               int l = inv - min(i, inv + 1) + 1, r = inv;               f[i % 2][inv] = (f[1 - i % 2][r] - (l == 0 ? 0 : f[1 - i % 2][l - 1]) + MOD) % MOD;           }           for (int j = 1; j <= getMaxInv(n - 1); j++)               f[i % 2][j] = (f[i % 2][j] + f[i % 2][j - 1]) % MOD;           for (int inv = 2; inv <= getMaxInv(i); inv++) {               int t1 = (f[i % 2][inv] - f[i % 2][inv - 1] + MOD) % MOD;               for (int t = 1; t <= min(i, inv - 1); t++) {                   int t2 = f[i % 2][inv - t - 1];                   int pickCnt = i - t + 1;                   rs = (rs + t1 * t2 % MOD * pickCnt % MOD * fact[n - i - 1] % MOD * C[n][i + 1]) % MOD;               }           }       }       cout << rs;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> s[300005];   int main() {     int n, a, b, c, d, start, len;     scanf( %d %d %d %d %d %d %d , &n, &a, &b, &c, &d, &start, &len);     for (int i = 0; i < n; i++) scanf( %d %d , &s[i].first, &s[i].second);     long long sum = 0, res = 0, ans = start;     int j = 0;     for (int i = 0; i < n; i++) {       while (j < n && s[j].first - s[i].first < len) {         sum += (s[j].second ? c : -d);         res = min(res, sum);         j++;       }       if (ans + res >= 0) {         if (!i)           printf( %d n , 0);         else           printf( %d n , s[i - 1].first + 1);         return 0;       }       ans += (s[i].second == 0 ? -b : a);       sum -= (s[i].second == 0 ? -d : c);       res -= (s[i].second == 0 ? -d : c);       if (ans < 0) {         printf( -1 n );         return 0;       }     }     printf( %d n , s[n - 1].first + 1);   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int x1, y1, x2, y2;     scanf( %d%d%d%d , &x1, &y1, &x2, &y2);     int res = abs(x1 - x2) + 1 + (x1 == x2);     res += abs(y1 - y2) + 1 + (y1 == y2);     printf( %d n , res * 2);   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   long long int tc, cnt = 0, number, many, total = 0, query, require;   int rmove[8] = {1, 0, -1, 0, -1, 1, -1, 1};   int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1};   long long int modpow(long long int x, long long int y, long long int m) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % m;       x = (x * x) % m;       y >>= 1;     }     return res;   }   long long int dist[305][305], path[305][305];   void FloydWarshall() {     for (int i = 0; i < many; i++) {       for (int j = 0; j < many; j++) {         for (int k = 0; k < many; k++) {           if (dist[j][i] + dist[i][k] < dist[j][k]) {             dist[j][k] = dist[j][i] + dist[i][k];             path[j][k] = path[i][k];           }         }       }     }   }   vector<int> answer;   void printPath(int a, int b) {     if (path[a][b] == a) return;     printPath(a, path[a][b]);     answer.push_back(path[a][b]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> many;     for (int i = 0; i < many; i++) {       for (int j = 0; j < many; j++) {         dist[i][j] = 1e18;         path[i][j] = i;       }       dist[i][i] = 0;       path[i][i] = -1;     }     for (int i = 0; i < many - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       dist[a][b] = 1;       dist[b][a] = 1;     }     for (int i = 1; i < many; i++) {       int sum = 0;       for (int j = 0; j < many; j++) {         if (i == j) continue;         if (dist[i][j] == 1) sum++;       }       if (sum == 1) number++;     }     vector<int> vec;     vec.resize(number);     for (int i = 0; i < number; i++) {       cin >> vec[i];       vec[i]--;     }     FloydWarshall();     int now = 0;     answer.push_back(now);     for (int i = 0; i < number; i++) {       printPath(now, vec[i]);       answer.push_back(vec[i]);       now = vec[i];     }     printPath(now, 0);     answer.push_back(0);     if (answer.size() == 2 * many - 1) {       for (int i = 0; i < answer.size(); i++) cout << answer[i] + 1 <<    ;     } else       cout << -1;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s, k;   int arr[51];   char color[51];   int mem[51][2501];   int solve(int i, char last, int num, int sum) {     if (sum >= k) {       return 0;     }     if (~mem[i][sum]) return mem[i][sum];     int ch1 = 1e9;     for (int j = 0; j < n; j++) {       if (arr[j] > num && last != color[j])         ch1 = min(ch1, solve(j, color[j], arr[j], sum + arr[j]) + abs(i - j));     }     return mem[i][sum] = ch1;   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     srand(time(NULL));     cin >> n >> s >> k;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       cin >> color[i];     }     memset(mem, -1, sizeof mem);     int ans = 1e9;     for (int i = 0; i < n; i++) {       ans = min(solve(i, color[i], arr[i], arr[i]) + abs(s - 1 - i), ans);     }     if (ans != 1e9)       cout << ans <<   n ;     else       cout << -1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int calc(int n) {     for (int i = 1; i <= 10; ++i) {       int tmp = n - i, cnt = 0;       for (; tmp; ++cnt, tmp /= 10)         ;       if (cnt == i) return n - i;     }   }   char s[1000050], ss[1000050];   int ans[1000050], a[1000050], n, m;   char f[4][1000050], res[1000050];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; ++i) a[s[i] -  0 ]++;     if (n == 1) {       puts( 0 );       return 0;     }     int len = calc(n);     for (int j = len; j; j /= 10) a[j % 10]--;     scanf( %s , ss + 1);     m = strlen(ss + 1);     for (int i = 1; i <= m; ++i) a[ss[i] -  0 ]--;     ans[0] = 0x3f3f3f3f;     for (int i = 1; i < 10; ++i) {       if (a[i] > 0) {         a[i]--;         ans[0] = i;         break;       }     }     for (int i = 1; i < len - m; ++i) {       for (int j = 0; j < 10; ++j) {         if (a[j] > 0) {           ans[i] = j;           a[j]--;           break;         }       }     }     if (ans[0] == 0x3f3f3f3f) {       printf( %s , ss + 1);       for (int i = 1; i <= len - m; ++i) printf( %d , ans[i]);       puts(  );       return 0;     }     if (ss[1] ==  0 )       for (int i = 0; i < len; ++i) f[0][i] =  A ;     else {       int i, j;       for (i = 0, j = 1; j <= m; ++i, ++j) f[0][i] = ss[j];       for (j = 0; j < len - m; ++j) a[ans[j]]++;       for (j = 0; j < 10; ++j)         for (int k = 0; k < a[j]; ++k) f[0][i++] = j +  0 ;     }     f[0][len] =   0 ;     int ok = 0, cnt = 1;     f[1][0] = ans[0] +  0 ;     for (int i = 1; i < len - m; ++i) {       if (!ok && ans[i] >= (ss[1] -  0 )) {         for (int j = 1; j <= m; ++j) f[1][cnt++] = ss[j];         ok = 1;       }       f[1][cnt++] = ans[i] +  0 ;     }     if (!ok)       for (int j = 1; j <= m; ++j) f[1][cnt++] = ss[j];     f[1][len] =   0 ;     ok = 0, cnt = 1;     f[2][0] = ans[0] +  0 ;     for (int i = 1; i < len - m; ++i) {       if (!ok && ans[i] > (ss[1] -  0 )) {         for (int j = 1; j <= m; ++j) f[2][cnt++] = ss[j];         ok = 1;       }       f[2][cnt++] = ans[i] +  0 ;     }     if (!ok)       for (int j = 1; j <= m; ++j) f[2][cnt++] = ss[j];     f[2][len] =   0 ;     strcpy(res, f[0]);     if (strcmp(res, f[1]) > 0) strcpy(res, f[1]);     if (strcmp(res, f[2]) > 0) strcpy(res, f[2]);     printf( %s n , res);     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   const long long N = 1e6 + 17, mo = 1e9 + 7;   long long f[N][2], n, h[N];   inline long long min(long long x, long long y) { return x > y ? y : x; }   inline long long quickmod(long long x) { return x >= mo ? x - mo : x; }   signed main() {     std::ios::sync_with_stdio(0);     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> h[i];       --h[i];     }     f[1][0] = h[1];     f[1][1] = min(h[1], h[2]);     long long ans = f[1][0];     for (long long i = 2; i <= n; ++i) {       f[i][0] = quickmod(h[i] + min(h[i], h[i - 1]) * f[i - 1][1] % mo);       f[i][1] = quickmod(min(h[i], h[i + 1]) +                          min(min(h[i], h[i - 1]), h[i + 1]) * f[i - 1][1] % mo);       ans = quickmod(ans + f[i][0]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<set<int> > arr;   long long res = 0;   void dfs(int vertex, int prev, int level) {     for (int v : arr[vertex]) {       if (v == prev) {         continue;       }       if (level == 2) {         res++;         continue;       } else {         dfs(v, vertex, level + 1);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     arr = vector<set<int> >(n + 1);     for (int i = 0; i < n; ++i) {       int a, b;       cin >> a >> b;       arr[a].insert(b);       arr[b].insert(a);     }     for (int i = 1; i <= n; ++i) {       dfs(i, -1, 1);     }     cout << res / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 51123987;   long long C[151][151];   int dp[2][3][51][51][51] = {};   int main() {     int n;     string s;     cin >> n >> s;     auto cur = dp[0];     auto nex = dp[1];     int u = (n - 1) / 3 + 1;     int t[3] = {};     for (int i = 0; i < n; i++) {       memset(nex, 0, sizeof(dp) / 2);       t[s[i] -  a ]++;       for (int j = 0; j < 3; j++) {         bool col = s[i] -  a  == j;         int c[3];         for (c[0] = 0; c[0] <= t[0] && c[0] <= u; c[0]++) {           for (c[1] = 0; c[1] <= t[1] && c[1] <= u; c[1]++) {             for (c[2] = 0; c[2] <= t[2] && c[2] <= u; c[2]++) {               long long v = 0;               if (col) {                 if (c[j]) {                   if (c[0] + c[1] + c[2] == 1) {                     v = 1;                   }                   int p[3] = {c[0], c[1], c[2]};                   p[j]--;                   for (int k = 1; k <= 2; k++) {                     v += cur[(j + k) % 3][p[0]][p[1]][p[2]];                     v %= M;                   }                 }               } else {                 v = cur[j][c[0]][c[1]][c[2]];               }               nex[j][c[0]][c[1]][c[2]] = v;             }           }         }       }       swap(nex, cur);     }     for (int i = 0; i <= u; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++) {         C[i][j] = C[i - 1][j - 1] + C[i - 1][j];         C[i][j] %= M;       }     }     long long ret = 0;     for (int i = max(0, u - 1); i <= u; i++) {       for (int j = max(0, u - 1); j <= u; j++) {         for (int k = max(0, u - 1); k <= u; k++) {           if (i + j + k != n) continue;           for (int p = min(i, 1); p <= i; p++) {             for (int q = min(j, 1); q <= j; q++) {               for (int r = min(k, 1); r <= k; r++) {                 long long s = 0;                 for (int v = 0; v < 3; v++) {                   s += cur[v][p][q][r];                   s %= M;                 }                 if (i != p) {                   s *= C[i - 1][p - 1];                   s %= M;                 }                 if (j != q) {                   s *= C[j - 1][q - 1];                   s %= M;                 }                 if (k != r) {                   s *= C[k - 1][r - 1];                   s %= M;                 }                 ret += s;                 ret %= M;               }             }           }         }       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int arr[1001] = {0};     int n, i, others, temp;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &temp);       arr[temp]++;     }     for (i = 0; i < 1001; i++) {       if (!arr[i]) continue;       others = n - arr[i];       if (arr[i] - others > 1) {         puts( NO );         getchar();         getchar();         return 0;       }     }     puts( YES );     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k, ans = 1, p, temp;     cin >> n >> k;     if (n == k) {       cout << 1;       return 0;     }     if (k == 1) {       cout << n;       return 0;     }     long long s, e, m;     s = 1, e = (n - 1) / 2;     while (s <= e) {       m = (s + e) / 2;       p = log2((n + 1) / (2 * m + 2)) + 1;       temp = 2 * ((1LL << p) - 1) + max(1 + n - (1LL << p) * 2 * m, 0LL);       if (temp >= k) {         s = m + 1;         ans = max(ans, 2 * m);       } else         e = m - 1;     }     s = 0, e = (n - 3) / 4;     while (s <= e) {       m = (s + e) / 2;       p = log2((n + 1) / (4 * m + 4)) + 1;       temp = 1 + 2 * ((1LL << p) - 1) +              max(1 + n - (1LL << (p + 1)) * (2 * m + 1), 0LL);       if (temp >= k) {         s = m + 1;         ans = max(ans, 2 * m + 1);       } else         e = m - 1;     }     cout << ans;     return 0;   }