malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, l[3], k[3], z = 0, j;     cin >> n >> m;     char a[n][m];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  * ) {           k[z] = i + 1;           l[z] = j + 1;           z++;         }       }     }     if (k[0] == k[1]) {       cout << k[2] <<    ;     } else if (k[1] == k[2]) {       cout << k[0] <<    ;     }     if (k[0] == k[2]) cout << k[1] <<    ;     if (l[0] == l[1]) {       cout << l[2] <<    ;     }     if (l[1] == l[2]) {       cout << l[0] <<    ;     }     if (l[0] == l[2]) cout << l[1];   }
#include <bits/stdc++.h>   using namespace std;   double a[220005];   double b[220005];   int n;   double check(double x) {     double q1 = 0.0, q2 = 0.0, q3 = 0.0;     for (int i = 1; i <= n; i++) b[i] = a[i] - x;     for (int i = 1; i <= n; i++) q1 = max(b[i], b[i] + q1), q3 = max(q1, q3);     for (int i = 1; i <= n; i++) b[i] = (-1.0) * b[i];     for (int i = 1; i <= n; i++) q2 = max(b[i], b[i] + q2), q3 = max(q3, q2);     return q3;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i]);     double l, r;     l = -30000.0, r = 30000.0;     while (r - l > 1e-11) {       double mid1 = (l + r) / 2.0;       double mid2 = (mid1 + r) / 2.0;       if (check(mid1) >= check(mid2))         l = mid1;       else         r = mid2;     }     printf( %.13lf n , check((l + r) / (2.0)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, Q, l, r;   int a[5000], b[5000][5000], c[5000][5000];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) b[i][i] = c[i][i] = a[i];     for (int L = 1; L < n; L++)       for (int i = 1; i + L <= n; i++) {         int j = i + L;         b[i][j] = b[i + 1][j] ^ b[i][j - 1];         c[i][j] = max(b[i][j], max(c[i + 1][j], c[i][j - 1]));       }     scanf( %d , &Q);     while (Q--) {       scanf( %d%d , &l, &r);       printf( %d n , c[l][r]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 5;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   int seg[2][8 * maxN], lzy[2][8 * maxN];   int lt[maxN], rt[maxN], Q[2][2 * maxN], N;   vector<int> vec;   long long two_to_the_power_of(long long x) {     if (x == 0) return 1;     long long y = two_to_the_power_of(x / 2);     y = y * y % MOD;     if (x & 1) y = y * 2 % MOD;     return y;   }   void apply(bool b, int id, int s, int e, int x) {     seg[b][id] = 1ll * (e - s) * x % MOD;     lzy[b][id] = x;     return;   }   void shift(bool b, int id, int s, int e) {     if (lzy[b][id] == -1) return;     int md = (s + e) / 2;     apply(b, 2 * id, s, md, lzy[b][id]);     apply(b, 2 * id + 1, md, e, lzy[b][id]);     lzy[b][id] = -1;     return;   }   void update(bool b, int l, int r, int x, int id = 1, int s = 0, int e = N) {     if (l <= s && e <= r) {       apply(b, id, s, e, x);       return;     }     if (l >= e || s >= r) return;     shift(b, id, s, e);     int md = (s + e) / 2;     update(b, l, r, x, 2 * id, s, md);     update(b, l, r, x, 2 * id + 1, md, e);     seg[b][id] = (seg[b][2 * id] + seg[b][2 * id + 1]) % MOD;     return;   }   int fetch(bool b, int l, int r, int id = 1, int s = 0, int e = N) {     if (l <= s && e <= r) return seg[b][id];     if (l >= e || s >= r) return 0;     shift(b, id, s, e);     int md = (s + e) / 2;     return (fetch(b, l, r, 2 * id, s, md) + fetch(b, l, r, 2 * id + 1, md, e)) %            MOD;   }   int main() {     time_t START = clock();     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(lzy, -1, sizeof lzy);     int n, m, k;     scanf( %d%d%d , &k, &n, &m);     for (int i = 0; i < n + m; i++) {       scanf( %d%d , lt + i, rt + i);       vec.push_back(lt[i]);       vec.push_back(rt[i]);     }     vec.push_back(0);     vec.push_back(1);     vec.push_back(k);     sort(vec.begin(), vec.end());     vec.resize(unique(vec.begin(), vec.end()) - vec.begin());     N = vec.size();     for (int i = 0; i < n + m; i++) {       lt[i] = lower_bound(vec.begin(), vec.end(), lt[i]) - vec.begin();       rt[i] = lower_bound(vec.begin(), vec.end(), rt[i]) - vec.begin();       Q[i < n][rt[i]] = max(Q[i < n][rt[i]], lt[i]);     }     update(0, 0, 1, 1);     update(1, 0, 1, 1);     for (int i = 1; i < N; i++) {       update(0, 0, Q[1][i], 0);       update(1, 0, Q[0][i], 0);       if (i == N - 1) break;       for (int b = 0; b < 2; b++) {         int tmp = (1ll * fetch(b, 0, i) *                    (two_to_the_power_of(vec[i + 1] - vec[i] - 1) - 1) % MOD) %                   MOD;         tmp = (tmp + 1ll * fetch(1 - b, 0, i) *                          two_to_the_power_of(vec[i + 1] - vec[i] - 1) % MOD) %               MOD;         update(b, i, i + 1, tmp);       }     }     printf( %d n , (seg[0][1] + seg[1][1]) % MOD);     time_t FINISH = clock();     cerr <<  Execution time:            << (long double)(FINISH - START) / CLOCKS_PER_SEC * 1000.0          <<   milliseconds. n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ar[500005 + 5];   int main() {     long long i, j, k, n;     cin >> n;     if (n <= 2)       cout << 1 << endl;     else if (n == 3)       cout << 2 << endl;     else {       long long lo = 1LL, hi = n, ans = 1LL;       while (lo <= hi) {         long long md = (lo + hi) / 2LL;         if (md * 3LL <= n) {           ans = max(ans, md);           lo = md + 1LL;         } else           hi = md - 1LL;       }       if (ans * 3 + 1 <= n) {         cout << (ans * 2) + 1 << endl;       } else         cout << ans * 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = 1e18;   int n, m;   int edges[22][2];   bool used[6][6];   int arr[7];   void init() {}   void input() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> edges[i][0] >> edges[i][1];       edges[i][0]--;       edges[i][1]--;     }   }   int check() {     int now = 0;     for (int i = 1; i <= 6; i++) {       for (int j = 1; j <= 6; j++) {         used[i][j] = false;       }     }     for (int i = 0; i < m; i++) {       int v = edges[i][0], u = edges[i][1];       if (!used[arr[v]][arr[u]]) {         now++;         used[arr[v]][arr[u]] = true;         used[arr[u]][arr[v]] = true;       }     }     return now;   }   void solve() {     int ans = 0;     for (arr[0] = 1; arr[0] < 7; arr[0]++) {       for (arr[1] = 1; arr[1] < 7; arr[1]++) {         for (arr[2] = 1; arr[2] < 7; arr[2]++) {           for (arr[3] = 1; arr[3] < 7; arr[3]++) {             for (arr[4] = 1; arr[4] < 7; arr[4]++) {               for (arr[5] = 1; arr[5] < 7; arr[5]++) {                 for (arr[6] = 1; arr[6] < 7; arr[6]++) {                   ans = max(ans, check());                 }               }             }           }         }       }     }     cout << ans << endl;   }   void output() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int number_of_testcases = 1;     while (number_of_testcases--) {       init();       input();       solve();       output();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, t, n;     double x, y;     cin >> t;     while (t--) {       cin >> n;       switch (n) {         case 1:           j = 0;           break;         case 2:           j = 1;           break;         case 3:           j = 2;           break;         default:           x = double(n);           y = sqrt(x);           i = int(y);           if (n == (i * i)) {             j = (i - 1) + (i - 1);           } else {             n = n - (i * i);             if ((n % i) == 0) {               j = (i - 1) + (n / i) + (i - 1);             } else {               j = i + (n / i) + (i - 1);             }           }       }       cout << j << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > edge;   int flo[120][120], flo2[120][120], dp[120][120], menda[120][120], com;   int st[120], en[120];   vector<int> vc[120];   void sho(int n) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         flo[i][j] = 1e7;       }     }     for (int i = 0; i < edge.size(); i++) {       flo[edge[i].first][edge[i].second] = 1;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           flo[i][j] = min(flo[i][k] + flo[k][j], flo[i][j]);         }       }     }   }   void sho2(int n, int stop) {     memset(flo2, 0, sizeof flo2);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j && i != stop) continue;         flo2[i][j] = 1e7;       }     }     for (int i = 0; i < edge.size(); i++) {       if (edge[i].first == stop || edge[i].second == stop) continue;       flo2[edge[i].first][edge[i].second] = 1;     }     for (int k = 1; k <= n; k++) {       if (k == stop) continue;       for (int i = 1; i <= n; i++) {         if (i == stop) continue;         for (int j = 1; j <= n; j++) {           if (j == stop) continue;           flo2[i][j] = min(flo2[i][k] + flo2[k][j], flo2[i][j]);         }       }     }   }   void dp_func(int v, int bus, int x, int y) {     int f = -1;     for (int i = 0; i < vc[v].size(); i++) {       int w = vc[v][i];       if (flo[v][y] == flo[w][y] + 1) f = max(f, dp[w][bus]);     }     if (f == -1) f = 1e7;     for (int i = 1; i <= com; i++) {       if (bus == i) continue;       int c = st[i], d = en[i];       if (flo[c][d] == 1e7) continue;       if (menda[i][v] == 0) continue;       f = min(f, dp[v][i] + 1);     }     dp[v][bus] = min(f, dp[v][bus]);   }   int main() {     int i, j, k, l, n, m, a, b;     scanf( %d%d%d%d , &n, &m, &a, &b);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &l, &k);       edge.push_back(make_pair(l, k));       vc[l].push_back(k);     }     sho(n);     if (flo[a][b] == 1e7) {       cout <<  -1 ;       return 0;     }     scanf( %d , &com);     for (int i = 1; i <= com; i++) {       scanf( %d%d , &st[i], &en[i]);     }     for (int i = 1; i <= n; i++) {       sho2(n, i);       for (int j = 1; j <= com; j++) {         int x = st[j], y = en[j];         if (flo[x][y] < flo2[x][y]) menda[j][i] = 1;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= com; j++) dp[i][j] = 1e7;     }     for (int j = 1; j <= com; j++) {       if (flo[st[j]][en[j]] == 1e7) continue;       if (menda[j][b]) dp[b][j] = 0;     }     for (int ite = 1; ite <= n; ite++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= com; j++) {           int x = st[j], y = en[j];           if (flo[x][y] == 1e7) continue;           dp_func(i, j, x, y);         }       }     }     int ans = 1e7;     for (int j = 1; j <= com; j++) {       if (!menda[j][a]) continue;       ans = min(ans, dp[a][j]);     }     if (ans == 1e7)       ans = -1;     else       ans++;     cout << ans << endl;   }
#include <bits/stdc++.h>   const size_t Size = 1e5 + 5;   const size_t SqrtS = 775 + 5;   int f[Size];   int sum[Size];   int cost[Size];   std::vector<int> d[Size];   int n, k;   int main(void) {     std::scanf( %d%d , &n, &k);     for (int i = 1, x, y; i <= k; ++i) {       std::scanf( %d%d , &x, &y);       d[y].push_back(n - x + 1);     }     int sqrtK = SqrtS;     std::memset(f, -0x3f, sizeof f);     for (int i = 1, lim; i <= n; ++i) {       std::memset(sum, 0, sizeof sum);       lim = std::min(n + 1 - i, sqrtK);       for (int j = d[i].size() - 1; j >= 0; --j)         if (d[i][j] <= lim) sum[d[i][j]] = 1;       for (int j = 1; j <= lim + 1; ++j) sum[j] += sum[j - 1];       cost[0] = std::max(0, f[0]);       for (int j = 1; j <= lim; ++j) cost[j] = std::max(cost[j - 1], f[j]);       f[0] = std::max(cost[0], std::max(f[1], cost[0] - 3) + 3 * sum[1]);       for (int j = 1; j <= lim; ++j)         f[j] = std::max(f[j + 1], cost[j] - (j + 2) * (j + 1) / 2 - 2) +                3 * sum[j + 1];     }     std::printf( %d n , k * 3 - f[0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long small = 1298173;   int n, m, a = 1, b = 2;   void step() {     if (a == 1 and b == n - 1) {       a++;       b = a + 1;     } else if (b < n) {       b++;     } else {       a++;       b = a + 1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cin >> n >> m;     if (m == 1) {       cout <<  2 2 n ;       cout <<  1   << n <<   2 n ;       return 0;     }     cout << 2 <<     << small <<   n ;     cout << 1 <<     << n <<   2  <<   n ;     small -= 2;     int counter = n - 2;     while (counter > 1) {       cout << a <<     << b <<     << 10 <<   n ;       small -= 10;       step();       counter--;     }     cout << a <<     << b <<     << small <<   n ;     step();     m -= (n - 1);     while (m > 0) {       cout << a <<     << b <<     << 1298183 <<   n ;       step();       m--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000 + 10];   int b[100000 + 10];   int main() {     int n, x, m, y;     scanf( %d%d%d%d , &n, &m, &x, &y);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);     }     printf( %s , a[x] < b[m - y + 1] ?  YES  :  NO );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unordered_map<int, int> nums;     int n;     cin >> n;     while (n--) {       int dummy;       cin >> dummy;       nums[dummy]++;     }     int res = 0;     for (auto p : nums) res = max(res, p.second);     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;                               const int N=2e5+7;      int n;   int x=-1,y=-1,z=-1;          int a[N], t[N*4];   vector<int> suff(N), pref(N);       void build(int v=1, int tl=1, int tr=n){     if(tl==tr) t[v]=a[tl];     else {       int tm = (tl+tr)/ 2;       build(v*2, tl, tm);       build(v*2+1,tm+1,tr);       t[v]=min(t[v*2], t[v*2+1]);     }   }   int get(int v, int tl, int tr, int l, int r){     if(l<=tl and tr<=r) return t[v];     if(r < tl || tr< l) return INT_MAX;     int tm=(tl + tr)>>1;     return min(get(v*2, tl, tm, l, r), get(v*2+1, tm+1,tr,l,r));   }   void calc(){     pref[1]=a[1];     for(int i=2;i<=n;i++) pref[i]=max(pref[i-1], a[i]);     suff[n]=a[n];     for(int i=n-1;i>=1;i--) suff[i]=max(suff[i+1], a[i]);   }   int main(){     ios_base::sync_with_stdio(false);     cin.tie(0);     int tt;     cin>>tt;     while(tt--){            cin>>n;                        for(int i = 1; i <= n; i++) cin>>a[i];       build();      calc();      bool flag=false;      int x, y, z;      for(int i=n;i>=3;i--){       int value = suff[i];       auto j1 = lower_bound(pref.begin(), pref.begin()+i-1, value);        int start = j1 - pref.begin();          auto j2 = upper_bound(pref.begin(), pref.begin()+i-1, value);       int end = j2 - pref.begin();       //cout<<start<<     <<end<<   ;       if(start >= end) continue;              int low= start, high=end;       while(high - low > 1) {         int mid = (low + high) / 2;         if (get(1,1,n,mid, i-1)<value) {           low=mid;         } else {           high=mid;         }       }       //cout<<     << high <<   n ;       if (high < i and get(1,1,n,high,i-1) == value and pref[high-1] == value) {        x = high-1;        y = i-high;        z = n-i+1;         flag=true;       }      }      if(!flag)       cout<< NO n ;      else       cout<< YES n <<x<<     << y <<     << z <<  n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int x;     cin >> x;     if (x % 4 == 0)       printf( 1 A );     else if (x % 4 == 1)       printf( 0 A );     else if (x % 4 == 2)       printf( 1 B );     else if (x % 4 == 3)       printf( 2 A );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, a, b, flag = 0, check = 1;     cin >> n >> a >> x >> b >> y;     for (int i = a, j = b; check != 0; i++, j--) {       if (i == n + 1) {         i = 1;       }       if (j == 0) {         j = n;       }       if (i == j) {         flag = 1;         break;       }       if (i == x || j == y) {         check = 0;       }     }     if (flag == 1) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1005][10];   int main() {     int n, s = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int c = 0;       for (int j = 0; j < 3; j++) {         cin >> a[i][j];         if (a[i][j]) c++;       }       if (c >= 2) s++;     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n = 5e5, f[N], s[N];   vector<int> v[N];   int q, a[N], c[N];   int main() {     int i, j, t;     long long ans;     for (i = 1; i <= n; i = i + 1) {       if (i == 1) f[i] = 1;       for (j = i; j <= n; j = j + i) {         v[j].push_back(i);         if (j > i) f[j] -= f[i];       }     }     scanf( %d%d , &n, &q);     for (i = 1; i <= n; i = i + 1) scanf( %d , a + i);     ans = 0;     while (q--) {       scanf( %d , &i);       t = v[a[i]].size();       if (c[i]) {         c[i] = 0;         i = a[i];         for (j = 0; j < t; j = j + 1) ans -= f[v[i][j]] * (--s[v[i][j]]);       } else {         c[i] = 1;         i = a[i];         for (j = 0; j < t; j = j + 1) ans += f[v[i][j]] * (s[v[i][j]]++);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Line {     double kx;     double b;     double x1;     double x2;   };   double CONST = pow(10, 12);   long long n, k, ai;   double bi;   vector<double> pre, summ, resumm;   vector<double> data;   double intersec(Line f, Line s) { return (s.b - f.b) / (f.kx - s.kx); }   long long bs(double number, vector<Line> &v) {     long long l = 0;     long long r = v.size();     while (r - l > 1) {       long long m = (l + r) / 2;       if (v[m].x1 <= number)         l = m;       else         r = m;     }     return l;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     double s1 = 0, s2 = 0, s3 = 0;     for (long long i = 0; i < n; i++) {       cin >> ai;       bi = ai;       s1 += bi;       s2 += s1 / bi;       s3 += 1 / bi;       data.push_back(bi);       pre.push_back(s2);       summ.push_back(s1);       resumm.push_back(s3);     }     vector<double> answers;     for (long long i = 0; i < n; i++) {       answers.push_back(pre[i]);     }     for (long long p = 1; p < k; p++) {       vector<Line> st;       vector<double> na;       for (long long i = 0; i < answers.size() - 1; i++) {         Line ll;         ll.kx = -summ[i + p - 1];         ll.b = summ[i + p - 1] * resumm[i + p - 1] + answers[i] - pre[i + p - 1];         while (st.size() > 0) {           double t = intersec(ll, st.back());           if (t <= st.back().x1) {             st.pop_back();           } else {             st.back().x2 = t;             break;           }         }         ll.x2 = CONST;         if (st.size() == 0)           ll.x1 = 0;         else           ll.x1 = st.back().x2;         st.push_back(ll);         long long ind = bs(resumm[i + p], st);         double an = pre[i + p] + st[ind].kx * resumm[i + p] + st[ind].b;         na.push_back(an);       }       answers = na;     }     cout.precision(30);     cout << answers.back() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int x, y, z;     cin >> x >> y >> z;     if (x > 0) {       cout <<  0 ;       for (int i = 1; i <= x; i++) cout <<  0 ;     }     if (y > 0) {       if (x == 0) cout <<  0 ;       cout <<  1 ;       y--;     } else if (z > 0 && y == 0 && x == 0) {       cout <<  1 ;     }     for (int i = 1; i <= z; i++) cout <<  1 ;     int m = 0;     while (y > 0) {       cout << m;       if (m == 0)         m = 1;       else         m = 0;       y--;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t > 0) {       solve();       t -= 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   const int oo = maxn;   int n;   int a[maxn], b[maxn], c[maxn], it[maxn * 8], itmin[maxn * 8];   int findit(int u, int v, int l, int r, int i) {     if (r < u || v < l) return oo;     if (u <= l && r <= v) {       return (itmin[i]);     }     int mid = (l + r) >> 1;     return (         min(findit(u, v, l, mid, i * 2), findit(u, v, mid + 1, r, i * 2 + 1)));   }   void updateit(int u, int w, int l, int r, int i) {     if (r < u || u < l) return;     if (u == l && u == r) {       it[i] += w;       if (it[i] == 0)         itmin[i] = oo;       else         itmin[i] = u;       return;     }     int mid = (l + r) >> 1;     updateit(u, w, l, mid, i * 2);     updateit(u, w, mid + 1, r, i * 2 + 1);     if (it[i * 2] == 0) {       it[i] = it[i * 2 + 1];       itmin[i] = itmin[i * 2 + 1];       return;     }     if (it[i * 2 + 1] == 0) {       it[i] = it[i * 2];       itmin[i] = itmin[i * 2];       return;     }     it[i] = it[i * 2] + it[i * 2 + 1];     itmin[i] = min(itmin[i * 2], itmin[i * 2 + 1]);   }   void nhap() {     cin >> n;     for (int i = 1; i <= n; i++) {       updateit(i, 0, 1, n, 1);     }     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] %= n;     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       b[i] %= n;       updateit(b[i] + 1, 1, 1, n, 1);     }   }   void xuli() {     for (int i = 1; i <= n; i++) c[i] = -1;     for (int i = 1; i <= n; i++) {       int x = n - a[i];       int j = findit(x + 1, n, 1, n, 1);       if (j != oo) {         c[i] = (a[i] + j - 1) % n;         updateit(j, -1, 1, n, 1);         continue;       } else {         j = findit(1, n, 1, n, 1);         c[i] = (a[i] + j - 1) % n;         updateit(j, -1, 1, n, 1);         continue;       }     }     for (int i = 1; i <= n; i++) {       cout << c[i] <<    ;     }   }   int main() {     nhap();     xuli();   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int neg = 1, num = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) neg = -1;     for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c -  0 ;     return neg * num;   }   struct node {     int x, y;   } p[6000010];   int n, m, cnt, a[2010], b[2010], c[2010], d[2010], suf[6000010];   int ans = 2147483647;   bool cmp(node f, node g) { return f.x == g.x ? f.y < g.y : f.x < g.x; }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++)       a[i] = read(), b[i] = read(), p[i].x = 0, p[i].y = 0;     for (int i = 1; i <= m; i++) c[i] = read(), d[i] = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         p[++cnt].x = max(0, c[j] - a[i] + 1);         p[cnt].y = max(0, d[j] - b[i] + 1);       }     sort(p + 1, p + cnt + 1, cmp);     suf[cnt] = p[cnt].y;     for (int i = cnt - 1; i >= 1; i--) suf[i] = max(suf[i + 1], p[i].y);     int pos = 0;     for (int i = 0; i <= 1e6; i++) {       while (p[pos + 1].x <= i && pos < cnt) pos++;       ans = min(ans, i + suf[pos + 1]);     }     cout << ans << endl;     return 0;   }