malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int M = 4;   int now[2], dila[2];   int vis[N][4], n, m, cnt, ans_cnt;   char s[4];   long long ans;   int main() {     int i, j, k, *p;     bool lose = false;     scanf( %d%d%d%d%s , &n, &m, &now[0], &now[1], s);     if (s[0] ==  U )       dila[0] = -1;     else       dila[0] = 1;     if (s[1] ==  L )       dila[1] = -1;     else       dila[1] = 1;     if (now[0] == 1) vis[now[1]][0]++, cnt++;     if (now[0] == n) vis[now[1]][2]++, cnt++;     if (now[1] == 1) vis[now[0]][1]++, cnt++;     if (now[1] == m) vis[now[0]][3]++, cnt++;     ans_cnt += (m - (((now[1] - now[0] + 1) % 2 - 2) % 2 + 2)) / 2 + 1;     ans_cnt += (n - (((now[0] - now[1] + 1) % 2 - 2) % 2 + 2)) / 2 + 1;     ans_cnt += (m - (((now[1] + (n - now[0])) % 2 - 2) % 2 + 2)) / 2 + 1;     ans_cnt += (n - (((now[0] + (m - now[1])) % 2 - 2) % 2 + 2)) / 2 + 1;     ans++;     while (cnt < ans_cnt && !lose) {       k = 0x7fffffff;       if (dila[0] == 1)         k = min(k, n - now[0]);       else         k = min(k, now[0] - 1);       if (dila[1] == 1)         k = min(k, m - now[1]);       else         k = min(k, now[1] - 1);       ans += k;       now[0] += dila[0] * k;       now[1] += dila[1] * k;       if (now[0] == 1) {         p = &vis[now[1]][0];         (*p)++;         if (*p == 1) cnt++;         if (*p > M) lose = true;         if (dila[0] == -1) dila[0] = -dila[0];       }       if (now[0] == n) {         p = &vis[now[1]][2];         (*p)++;         if (*p == 1) cnt++;         if (*p > M) lose = true;         if (dila[0] == 1) dila[0] = -dila[0];       }       if (now[1] == 1) {         p = &vis[now[0]][1];         (*p)++;         if (*p == 1) cnt++;         if (*p > M) lose = true;         if (dila[1] == -1) dila[1] = -dila[1];       }       if (now[1] == m) {         p = &vis[now[0]][3];         (*p)++;         if (*p == 1) cnt++;         if (*p > M) lose = true;         if (dila[1] == 1) dila[1] = -dila[1];       }     }     if (lose)       puts( -1 );     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long mx, mi;   int t, head[N], len, k, vis[N];   struct edge {     int v, w, next;   } e[N * 2];   void add(int u, int v, int w) {     e[len].v = v;     e[len].w = w;     e[len].next = head[u];     head[u] = len++;   }   void dfs(int u, int fa) {     vis[u] = 1;     for (int j = head[u]; j; j = e[j].next) {       int v = e[j].v;       int w = e[j].w;       if (v == fa) continue;       dfs(v, u);       if (vis[v] & 1) {         mi += w;       }       mx += (long long)min(k - vis[v], vis[v]) * w;       vis[u] += vis[v];     }   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &k);       int u, v, w;       k <<= 1;       len = 1;       memset(head, 0, sizeof(head));       memset(vis, 0, sizeof(vis));       for (int i = 1; i < k; i++) {         scanf( %d%d%d , &u, &v, &w);         add(u, v, w);         add(v, u, w);       }       mi = 0, mx = 0;       dfs(1, 0);       printf( %lld %lld n , mi, mx);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt = 0;   long long sum = 0;   bool flag = false;   struct Node {     int num;     int pos;   } a[200005];   bool cmp(const Node &a, const Node &b) { return a.num < b.num; }   vector<int> v;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].num;       a[i].pos = i;       sum += a[i].num;     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n - 1; i++) {       if (sum - a[i].num == 2 * a[n].num) {         cnt++;         v.push_back(a[i].pos);       }     }     if (sum - a[n].num == 2 * a[n - 1].num) {       v.push_back(a[n].pos);       cnt++;     }     if (cnt == 0) {       cout << 0 << endl;       return 0;     }     cout << cnt << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string itosm(long long x) {     if (x == 0) return  0 ;     string ans =   ;     while (x > 0) {       ans += ((x % 10) +  0 );       x /= 10;     }     reverse(ans.begin(), ans.end());     return ans;   }   long long stoim(string str) {     long long ans = 0;     long long k = 1;     for (int i = str.length() - 1; i >= 0; i--) {       ans += (str[i] -  0 ) * k;       k *= 10;     }     return ans;   }   const long long infll = 1e18 + 3;   const int inf = 1009000999;   const double eps = 1e-6;   const int maxn = 1e6 + 77;   const int baseint = 1000200013;   const long long basell = 1e18 + 3;   const long double PI = acos(-1.0);   int main() {     srand(228228);     ios_base::sync_with_stdio(0);     ;     string t, s, p =   ;     cin >> t >> s;     int n = s.length();     while (p.length() != n) p +=  0 ;     int cnt = 0;     for (int i = (0); i < (n); i++) {       if (s[i] == t[i])         p[i] = s[i];       else         cnt++;     }     if (cnt % 2) {       cout <<  impossible ;       return 0;     }     cnt = 0;     for (int i = (0); i < (n); i++) {       if (s[i] != t[i]) {         if (cnt <= 0) {           p[i] = s[i];           cnt++;         } else {           p[i] = t[i];           cnt--;         }       }     }     cout << p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   string name, host, sour;   int main() {     ios::sync_with_stdio(false);     cin >> s;     int i = 0;     while (i < s.size() && s[i] !=  @ ) {       name.push_back(s[i]);       i++;     }     i++;     while (i < s.size() && s[i] !=  / ) {       host.push_back(s[i]);       i++;     }     bool exist = 0;     if (s[i] ==  / ) exist = 1;     i++;     if (i != s.size() + 1)       while (i < s.size()) {         sour.push_back(s[i]);         i++;       }     if (sour.size() > 16 || name.size() == 0 || name.size() > 16 ||         host.size() > 32 || host.size() == 0) {       cout <<  NO n ;       return 0;     }     if (exist && sour.size() == 0) {       cout <<  NO n ;       return 0;     }     for (int j = 0; j < name.size(); j++) {       char c = name[j];       if (!isdigit(c) && !isalpha(c) && (c !=  <  && c !=  >  && c !=  _ )) {         cout <<  NO n ;         return 0;       }     }     int cnt = 0;     for (int j = 0; j < host.size(); j++) {       char c = host[j];       if (!isdigit(c) && !isalpha(c) &&           (c !=  <  && c !=  >  && c !=  .  && c !=  _ )) {         cout <<  NO n ;         return 0;       }       if (c ==  . ) {         if (cnt == 0) {           cout <<  NO n ;           return 0;         }         cnt = -1;       }       cnt++;       if (cnt > 16) {         cout <<  NO n ;         return 0;       }     }     if (cnt == 0) {       cout <<  NO n ;       return 0;     }     for (int j = 0; j < sour.size(); j++) {       char c = sour[j];       if (!isalpha(c) && !isdigit(c) && (c !=  <  && c !=  >  && c !=  _ )) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int main() {     int n, len, a[100010], f[100010], dai, max = 0, vitri = 0;     char s[100010];     char si[13][13];     bool kt;     scanf( %s , s);     len = strlen(s);     for (int i = 0; i < len; i++) f[i] = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %s , si[i]);     for (int i = 0; i < len; i++) {       dai = 100;       for (int j = 1; j <= n; j++) {         kt = true;         for (int k = 0; k < strlen(si[j]); k++)           if (si[j][k] != s[i + k]) {             kt = false;             break;           }         if (kt && strlen(si[j]) < dai) dai = strlen(si[j]);       }       a[i] = dai;     }     f[len] = 0;     for (int i = len - 1; i >= 0; i--) {       if (a[i] != 100)         f[i] = min(f[i + 1] + 1, a[i] - 1);       else         f[i] = f[i + 1] + 1;       if (f[i] > max) {         max = f[i];         vitri = i;       }     }     printf( %d %d , max, vitri);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmax(T &x, T y) {     x = x > y ? x : y;   }   template <class T>   void chmin(T &x, T y) {     x = x < y ? x : y;   }   const int maxn = 205;   int n, k;   int d[maxn], ans[maxn], choice[maxn];   int dp[maxn][maxn];   int dist[maxn][maxn];   vector<int> v[maxn];   void predfs(int pos, int fa, int *dis) {     for (int i = 0; i < (int)(v[pos]).size(); i++) {       int to = v[pos][i];       if (to == fa) continue;       dis[to] = dis[pos] + 1;       predfs(to, pos, dis);     }   }   void dfs(int pos, int fa) {     for (int i = 1; i <= n; i++) dp[pos][i] = d[dist[pos][i]] + k;     for (int i = 0; i < (int)(v[pos]).size(); i++) {       int to = v[pos][i];       if (to == fa) continue;       dfs(to, pos);       for (int j = 1; j <= n; j++)         dp[pos][j] += min(dp[to][choice[to]], dp[to][j] - k);     }     choice[pos] = min_element(dp[pos] + 1, dp[pos] + n + 1) - dp[pos];     return;   }   void print(int pos, int fa, int j) {     for (int i = 0, _j; i < (int)(v[pos]).size(); i++) {       int to = v[pos][i];       if (to == fa) continue;       if (dp[to][choice[to]] < dp[to][j] - k) {         _j = choice[to];       } else {         _j = j;       }       ans[to] = _j;       print(to, pos, _j);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n - 1; i++) cin >> d[i];     for (int i = 1; i <= n - 1; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) predfs(i, 0, dist[i]);     dfs(1, 0);     cout << dp[1][choice[1]] << endl;     print(1, 0, choice[1]);     ans[1] = choice[1];     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y;   int a, b;   int diff;   void ask(int mask) {     int sz = 0;     for (int i = 0; i < n; ++i) {       if ((i & mask) > 0) {         ++sz;       }     }     if (sz == 0) {       return;     }     printf( ? %d , sz);     for (int i = 0; i < n; ++i) {       if ((i & mask) > 0) {         printf(  %d , i + 1);       }     }     printf(  n );     fflush(stdout);     int ans = 0;     scanf( %d , &ans);     if (ans != 0 && ans != x) {       diff += mask;     }   }   vector<int> v;   bool f(int sr) {     printf( ? %d , sr + 1);     for (int i = 0; i <= sr; ++i) {       printf(  %d , v[i] + 1);     }     printf(  n );     fflush(stdout);     int ans;     scanf( %d , &ans);     if (ans != 0 && ans != x) {       return true;     }     return false;   }   void input() { scanf( %d%d%d , &n, &x, &y); }   void solve() {     for (int i = 0; i < 10; ++i) {       ask((1 << i));     }     for (int i = 0; i < n; ++i) {       if ((i ^ diff) < i) {         v.push_back(i);       }     }     int l, r, mid;     l = 0;     r = v.size() - 1;     while (l != r) {       int mid = (l + r) / 2;       if (f(mid) == true) {         r = mid;       } else {         l = mid + 1;       }     }     printf( ! %d %d n , (v[l] ^ diff) + 1, v[l] + 1);     fflush(stdout);   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = ~0U >> 1;   const long long INF = (long long)1e18;   const double pi = acos(-1.0);   template <class T>   inline T sqr(T a) {     return a * a;   }   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 void read(T &n) {     char c;     for (c = getchar(); !(c >=  0  && c <=  9 ); c = getchar())       ;     n = c -  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;   }   int pw(int base, int n, int mo) {     if (n == 0) return 1;     if (n == 1) return base;     int tmp = pw(base, n >> 1, mo);     tmp = (long long)tmp * tmp % mo;     if (n & 1) tmp = (long long)tmp * base % mo;     return tmp;   }   const int maxn = 200000;   int N, M, x, y, p[maxn], c[maxn], f[maxn], s[maxn];   long long ans;   bool cmp(const int &a, const int &b) { return c[a] > c[b]; }   vector<int> E[maxn];   int find(int x) {     if (f[x] == x) return x;     int t = find(f[x]);     s[x] += s[f[x]];     return f[x] = t;   }   int main() {     scanf( %d%d , &N, &M);     for (int i = (1); i <= (N); ++i) scanf( %d , &c[i]);     for (int i = (1); i <= (M); ++i) {       scanf( %d%d , &x, &y);       if (c[x] < c[y])         E[x].push_back(y);       else         E[y].push_back(x);     }     for (int i = (1); i <= (N); ++i) p[i] = i;     sort(p + 1, p + N + 1, cmp);     for (int i = (1); i <= (N); ++i) f[i] = i, s[i] = 1;     for (int i = (1); i <= (N); ++i) {       int S = p[i];       for (int j = 0; j < E[S].size(); ++j) {         int x = find(S), y = find(E[S][j]);         if (x != y) {           ans += (long long)c[S] * s[x] * s[y];           f[x] = y;           s[y] += s[x];         }       }     }     double ret = ans * 2. / N / (N - 1);     printf( %.10lf n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n;   string str;   int main() {     cin >> t;     while (t--) {       cin >> n >> str;       int x = n, res = n;       for (int i = 0; i < n; i++)         if (str[i] ==  1 ) {           res = max(res, max(n + 1, 2 * max(i + 1, n - i)));         }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   string grid[105];   int check_bomb(int i, int j) {     if ((i > 0 && grid[i - 1][j] ==  * ) ||         (i < n - 1 && grid[i + 1][j] ==  * ) ||         (j > 0 && grid[i][j - 1] ==  * ) ||         (j < m - 1 && grid[i][j + 1] ==  * ) ||         (i > 0 && j > 0 && grid[i - 1][j - 1] ==  * ) ||         (i > 0 && j < m - 1 && grid[i - 1][j + 1] ==  * ) ||         (i < n - 1 && j > 0 && grid[i + 1][j - 1] ==  * ) ||         (i < n - 1 && j < m - 1 && grid[i + 1][j + 1] ==  * )) {       printf( NO );       return 1;     }     return 0;   }   int count_bomb(int i, int j) {     int k = grid[i][j] - 48;     int cnt = 0;     if (i > 0 && grid[i - 1][j] ==  * ) cnt++;     if (i < n - 1 && grid[i + 1][j] ==  * ) cnt++;     if (j > 0 && grid[i][j - 1] ==  * ) cnt++;     if (j < m - 1 && grid[i][j + 1] ==  * ) cnt++;     if (i > 0 && j > 0 && grid[i - 1][j - 1] ==  * ) cnt++;     if (i > 0 && j < m - 1 && grid[i - 1][j + 1] ==  * ) cnt++;     if (i < n - 1 && j > 0 && grid[i + 1][j - 1] ==  * ) cnt++;     if (i < n - 1 && j < m - 1 && grid[i + 1][j + 1] ==  * ) cnt++;     if (cnt != k) {       printf( NO );       return 1;     }     return 0;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       cin >> grid[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (grid[i][j] ==  . ) {           int check = check_bomb(i, j);           if (check == 1) return 0;         } else if (grid[i][j] >=  1  && grid[i][j] <=  9 ) {           int bomb = count_bomb(i, j);           if (bomb == 1) return 0;         }       }     }     printf( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a, b, T;   char s[500010];   long long pref[500010];   long long suff[500010];   int main() {     cin >> n >> a >> b >> T;     for (int i = 1; i <= n; ++i) {       cin >> s[i];     }     pref[1] = 0;     for (int i = 2; i <= n; ++i) {       pref[i] = a + pref[i - 1] + 1;       if (s[i] ==  w ) {         pref[i] += b;       }     }     suff[n + 1] = 0;     for (int i = n; i >= 2; --i) {       suff[i] = a + 1 + suff[i + 1];       if (s[i] ==  w ) {         suff[i] += b;       }     }     int ans = 0;     long long t = 1;     if (s[1] ==  w ) {       t += b;     }     if (T < t) {       cout << 0;       return 0;     }     T -= t;     ++ans;     for (int i = 2; i <= n; ++i) {       if (pref[i] > T) {         break;       }       ans = max(ans, i);       long long t = T - pref[i] - (i - 1) * a;       if (t < 0) {         continue;       }       int l = i;       int r = n + 1;       while (l + 1 < r) {         int m = (l + r) / 2;         if (suff[m] <= t) {           r = m;         } else {           l = m;         }       }       ans = max(ans, i + n + 1 - r);     }     for (int i = n; i >= 2; --i) {       if (suff[i] > T) {         break;       }       ans = max(n - i + 2, ans);       long long t = T - suff[i] - (n + 1 - i) * a;       if (t < 0) {         continue;       }       int l = 1, r = i;       while (l + 1 < r) {         int m = (l + r) / 2;         if (pref[m] <= t) {           l = m;         } else {           r = m;         }       }       ans = max(ans, n - i + 1 + l);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 60;   const int M = 40010;   const int OFF = 20005;   int n, m;   int lt[N], rt[N];   set<int> cnt;   bitset<N> ll[M], rr[M];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> lt[i];     }     for (int i = 0; i < m; i++) {       cin >> rt[i];       for (int j = 0; j < n; j++) {         cnt.insert(lt[j] + rt[i] + OFF);         ll[lt[j] + rt[i] + OFF].set(j);         rr[lt[j] + rt[i] + OFF].set(i);       }     }     int m1 = 0;     for (auto cc1 : cnt) {       for (auto cc2 : cnt) {         bitset<N> unl = ll[cc1] | ll[cc2];         bitset<N> unr = rr[cc1] | rr[cc2];         m1 = max(m1, int(unl.count() + unr.count()));       }     }     printf( %d n , m1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5;   const long long linf = 1e18 + 5;   class point {    public:     int x, y;     double m;     point() {}     point(int x, int y) {       this->x = x;       this->y = y;       this->m = atan2(y, x);     }     bool operator<(point other) const { return m < other.m; }     bool operator==(point other) const {       return x == other.x and y == other.y and m == other.m;     }   };   int n, c, x, y, sumx, sumy;   pair<int, int> a[5];   set<point> s;   long long ccw(point a, point c, point b) {     pair<int, int> v1 = make_pair(c.x - a.x, c.y - a.y);     pair<int, int> v2 = make_pair(b.x - a.x, b.y - a.y);     return (long long)v1.first * v2.second - (long long)v1.second * v2.first;   }   set<point>::iterator something_stupid_(point x) {     set<point>::iterator it = s.lower_bound(x);     if (it == s.end()) it = s.begin();     return it;   }   set<point>::iterator something_stupid_(set<point>::iterator it) {     it++;     if (it == s.end()) it = s.begin();     return it;   }   set<point>::iterator _something_stupid(set<point>::iterator it) {     if (it == s.begin()) {       it = s.end();       it--;     } else       it--;     return it;   }   int main() {     ios ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= 3; i++) {       cin >> c >> a[i].first >> a[i].second;       sumx += a[i].first;       sumy += a[i].second;     }     pair<int, int> cent = make_pair(sumx, sumy);     for (int i = 1; i <= 3; i++) {       a[i].first *= 3;       a[i].second *= 3;       a[i].first -= cent.first;       a[i].second -= cent.second;       point t(a[i].first, a[i].second);       s.insert(t);     }     for (int i = 4; i <= n; i++) {       cin >> c >> x >> y;       x *= 3;       y *= 3;       x -= cent.first;       y -= cent.second;       point t(x, y);       if (c == 1) {         set<point>::iterator left = something_stupid_(t);         set<point>::iterator right = _something_stupid(left);         if (ccw(*left, *right, t) <= 0) continue;         while (s.size() >= 2 and ccw(t, *left, *something_stupid_(left)) <= 0) {           set<point>::iterator it = left;           left = something_stupid_(left);           s.erase(it);         }         right = _something_stupid(left);         while (s.size() >= 2 and ccw(t, *right, *_something_stupid(right)) >= 0) {           set<point>::iterator it = right;           right = _something_stupid(right);           s.erase(it);         }         s.insert(t);       } else {         set<point>::iterator left = something_stupid_(t);         set<point>::iterator right = _something_stupid(left);         if (ccw(*left, *right, t) <= 0)           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2010];   long long C[2010][2010];   long long A[2010];   bool use[2010];   int n, m, N;   void init() {     memset(use, 0, sizeof(use));     C[0][0] = 1;     for (int i = 1; i <= 2000; ++i) C[i][0] = 1;     for (int i = 1; i <= 2000; ++i)       for (int j = 1; j <= i; ++j)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;     A[0] = 1;     A[1] = 1;     for (int i = 2; i <= 2000; ++i) A[i] = (A[i - 1] * i) % 1000000007;     n = 0;   }   void solve() {     long long Ans = 1;     Ans = A[n];     for (int i = 1; i <= N; ++i)       if (a[i] == -1 && !use[i]) m++;     long long tmp = 0;     for (int i = 1; i <= m; ++i) {       if (i & 1)         tmp = (tmp + (C[m][i] * A[n - i]) % 1000000007) % 1000000007;       else         tmp = (1000000007 + tmp - (C[m][i] * A[n - i]) % 1000000007) % 1000000007;     }     cout << (Ans + 1000000007 - tmp) % 1000000007;   }   int main() {     scanf( %d , &N);     init();     for (int i = 1; i <= N; ++i) {       scanf( %d , &a[i]);       if (a[i] != -1)         use[a[i]] = 1;       else         n++;     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m, ta, tb, k, res = 0;     cin >> n >> m >> ta >> tb >> k;     if (k >= n || k >= m) {       cout << -1;       return 0;     }     vector<long long> a(n), b(m);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     for (int i = 0; i < n && i <= k; i++) {       long long search = a[i] + ta;       long long l = -1;       long long r = m;       long long mid;       while (l != r - 1) {         mid = (l + r) / 2;         if (b[mid] >= search)           r = mid;         else           l = mid;       }       if (r + max(0LL, k - i) >= m) {         cout << -1;         return 0;       }       res = max(res, b[r + max(0LL, k - i)] + tb);     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   int arr[400009];   map<int, int> mp;   vector<int> v;   int sum[400009];   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (mp[arr[i]] == 0) {         v.push_back(arr[i]);       }       mp[arr[i]]++;     }     sort(v.begin(), v.end());     k *= 8;     int ans = 1000000009;     int j = 0;     int num = 0;     int curr = 0;     for (int i = 0; i < v.size(); i++) {       curr += mp[v[i]];     }     for (int i = 0; i < v.size(); i++) {       while (j < v.size() && ceil(log2(j - i + 1)) * n <= k) {         curr -= mp[v[j]];         j++;       }       ans = min(ans, curr);       j = max(i, j);       curr += mp[v[i]];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tt = 120;     int test[6] = {0, 1, 3, 5, 2, 4};     int n = 5;     int p[2001], s[2001];     int p_l[2001], s_l[2001];     int ans = 0;     vector<pair<int, int> > v_ans;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i]);       p_l[p[i]] = i;     }     for (int i = 1; i <= n; i++) s[i] = i;     for (int i = 1; i <= n; i++) {       scanf( %d , &s[i]);       s_l[s[i]] = i;     }     for (int i = 1; i <= n; i++) {       if (p[i] != s[i]) {         int r = p_l[s[i]];         for (int j = i; j <= r; j++) {           int pos_j = s_l[p[j]];           int pos_r = s_l[p[r]];           if ((pos_j >= r && pos_r <= j && pos_j != pos_r)) {             ans += abs(j - r);             v_ans.push_back(make_pair(j, r));             swap(p[j], p[r]);             swap(p_l[p[j]], p_l[p[r]]);             r = j;             j = i - 1;           }         }       }     }     printf( %d n%d n , ans, v_ans.size());     for (int i = 0; i < v_ans.size(); i++)       printf( %d %d n , v_ans[i].first, v_ans[i].second);     return 0;   }