malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double INF = 1e18;   const int MAX_N = 100100;   const int IT = 100;   const double PI = acos(-1.0);   int x[MAX_N];   int y[MAX_N];   long long dist(int a, int b) {     long long dx = x[a] - x[b];     long long dy = y[a] - y[b];     return dx * dx + dy * dy;   }   double dist1(double xx, double yy) {     xx -= x[0];     yy -= y[0];     return xx * xx + yy * yy;   }   double fun(int a, int b) {     double l = 0.0, r = 1.0;     for (int i = 0; i < IT; i++) {       double ml = l + (r - l) / 3.0;       double mr = r - (r - l) / 3.0;       double x1 = x[a] * ml + (1.0 - ml) * x[b];       double y1 = y[a] * ml + (1.0 - ml) * y[b];       double x2 = x[a] * mr + (1.0 - mr) * x[b];       double y2 = y[a] * mr + (1.0 - mr) * y[b];       if (dist1(x1, y1) > dist1(x2, y2)) {         l = ml;       } else {         r = mr;       }     }     double xx = x[a] * l + (1.0 - l) * x[b];     double yy = y[a] * l + (1.0 - l) * y[b];     return dist1(xx, yy);   }   void solve() {     int n;     scanf( %d%d%d , &n, &x[0], &y[0]);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);     }     double mn = INF;     double mx = 0;     for (int i = 1; i <= n; i++) {       int j = (i == n ? 1 : i + 1);       mx = max(mx, (double)dist(0, i));       mx = max(mx, (double)dist(0, i));       mn = min(mn, fun(i, j));     }     double answer = PI * (mx - mn);     printf( %.18lf n , answer);   }   int main() {     int cases;     cases = 1;     for (int i = 0; i < cases; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a.begin(), a.end());     for (auto i : a) {       if (i != a[0]) {         printf( %d , i);         return 0;       }     }     printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[20];   long long b[20][10][10];   long long c[20][10][10];   long long dp(long long n, int p) {     long long n0 = n;     long long ans = 0;     while (n >= 10) {       long long m = n;       long long e = 0;       while ((m + 10) % (a[e] * 10) < 10) e++;       if (e == 1 || a[e] >= n) {         long long m = n;         int k = 0;         while (m != 0) {           if (m % 10 >= k) k = m % 10;           m = m / 10;         }         ans += 1;         if (p < k)           n -= k;         else           n -= p;         continue;       }       int i = 0;       int k = 0;       for (i; m != 0; i++) {         if (i >= e && m % 10 >= k) k = m % 10;         m = m / 10;       }       if (k < p) k = p;       if (b[e][(n + 10) % a[e]][k] == -1) {         dp(n % a[e], k);       }       ans += b[e][(n + 10) % a[e]][k];       n = n / a[e] * a[e] + c[e][(n + 10) % a[e]][k];     }     long long e = 0;     while ((n0 + 10) % (a[e] * 10) < 10) e++;     if (a[e] > n0) {       b[e][(n0 + 10) % a[e]][p] = ans;       c[e][(n0 + 10) % a[e]][p] = n;     }     return ans;   }   int main() {     a[0] = 1;     for (int i = 1; i <= 18; i++) a[i] = a[i - 1] * 10;     for (int i = 0; i < 20; i++)       for (int j = 0; j < 10; j++)         for (int k = 0; k < 10; k++) {           b[i][j][k] = -1;           c[i][j][k] = -1;         }     long long n;     cin >> n;     if (n == 0) {       cout << 0 << endl;       return 0;     }     cout << dp(n, 0) + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int dp[maxn], ans;   const int inf = 1e9;   int a1, a2, adfds, fd;   vector<int> edge[maxn];   int n, m, d, num[maxn], fuck;   void dfs1(int u, int fa) {     int i;     for (i = 0; i < (int)edge[u].size(); i++) {       int v = edge[u][i];       if (v == fa) continue;       dfs1(v, u);       dp[u] = max(dp[u], dp[v] + 1);     }     if (num[u]) dp[u] = max(dp[u], 0);   }   void dfs2(int u, int fa, int fv) {     int flag = 0, i, j, k;     if (fv + 1 > d) flag = 1;     int l1 = -inf, id1 = 0, l2 = -inf, id2 = 0;     for (i = 0; i < (int)edge[u].size(); i++) {       int v = edge[u][i];       if (v == fa) continue;       if (dp[v] + 1 > d) flag = 1;       if (dp[v] >= l1) {         l2 = l1, id2 = id1;         l1 = dp[v], id1 = v;       } else if (dp[v] > l2) {         l2 = dp[v], id2 = v;       }     }     if (!flag) ans++;     for (i = 0; i < (int)edge[u].size(); i++) {       int v = edge[u][i];       if (v == fa) continue;       int fvv = fv;       if (v == id1)         fvv = max(fvv, l2);       else         fvv = max(fvv, l1);       if (num[u]) fvv = max(fvv, -1);       dfs2(v, u, fvv + 1);     }   }   int main() {     int i, j, k, a, b, c;     ans = 0;     scanf( %d%d%d , &n, &m, &d);     for (i = 0; i <= n; i++) {       dp[i] = -inf;       edge[i].clear();     }     for (i = 1; i <= m; i++) {       scanf( %d , &a);       num[a] = 1;     }     for (i = 1; i < n; i++) {       scanf( %d%d , &a, &b);       edge[a].push_back(b);       edge[b].push_back(a);     }     dfs1(1, 0);     dfs2(1, 0, -inf);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const double eps = 1e-9;   int n, t;   char A[N], B[N];   int main() {     scanf( %d %d n , &n, &t);     gets(A);     gets(B);     int sameCnt = 0;     for (int i = 0; i < n; ++i) {       if (A[i] == B[i]) ++sameCnt;     }     int dif = n - sameCnt;     if (dif / 2 + dif % 2 <= t) {       int wic = 0;       int have = 0;       t -= dif / 2 + dif % 2;       have = dif % 2;       if (t > sameCnt) {         have += 2 * (t - sameCnt);         t = sameCnt;       }       if (n == 1000) {       }       for (int i = 0; i < n; ++i) {         if (have && A[i] != B[i]) {           char tempval =  a ;           for (int j = 0; j < 26; ++j) {             if (tempval + j != A[i] && tempval + j != B[i]) {               printf( %c , tempval + j);               break;             }           }           have--;           continue;         }         if (A[i] != B[i]) {           if (wic)             printf( %c , A[i]);           else             printf( %c , B[i]);           wic = 1 - wic;           continue;         }         if (t > 0 && A[i] == B[i]) {           t--;           char temp = A[i] + 1;           if (A[i] ==  z ) temp =  y ;           printf( %c , temp);         } else {           printf( %c , A[i]);         }       }       printf(  n );     } else {       cout <<  -1  << endl;     }     return 0;   }
#include <bits/stdc++.h>      using namespace std;   const int c=200002, k=20;   int n, q, p[c], szint[c], fel[c][k], f[c], db[c];   long long aa[c], bb[c], dist[c], val[c], sum;   bool v[c];   set<int> s;   int lca(int a, int b) {       if (szint[a]<szint[b]) {           swap(a, b);       }       for (int i=k-1; i>=0; i--) {           if (szint[fel[a][i]]>=szint[b]) {               a=fel[a][i];           }       }       if (a==b) {           return a;       }       for (int i=k-1; i>=0; i--) {           if (fel[a][i]!=fel[b][i]) {               a=fel[a][i], b=fel[b][i];           }       }       return f[a];   }   long long tav(int a, int b) {       int koz=lca(a, b);       return dist[a]+dist[b]-2*dist[koz];   }   void keres(int a, int &l, int &r) {       auto it=s.find(a);       --it;       l=*it;       ++it, ++it;       if (it!=s.end()) {           r=*it;       }   }   void add(int a) {       s.insert(a);       int l=0, r=0;       keres(a, l, r);       sum+=tav(l, a)+tav(a, r)-tav(l, r);   }   void cl(int a) {       int l=0, r=0;       keres(a, l, r);       sum-=tav(l, a)+tav(a, r)-tav(l, r);       s.erase(a);   }   int main()   {       ios_base::sync_with_stdio(false);       cin >> n >> q;       p[0]=n+1;       for (int i=1; i<=n; i++) {           cin >> p[i];           f[i]=i-1;           while (p[i]>p[f[i]]) {               f[i]=f[f[i]];           }           szint[i]=szint[f[i]]+1;           fel[i][0]=f[i];           for (int j=1; j<k; j++) {               fel[i][j]=fel[fel[i][j-1]][j-1];           }       }       for (int i=1; i<=n; i++) {           cin >> aa[i];           val[i]+=aa[i];       }       for (int i=1; i<=n; i++) {           cin >> bb[i];           val[i]-=bb[i];           val[f[i]]+=bb[i];       }       for (int i=n; i>=1; i--) {           if (val[i]<0) {               val[f[i]]+=val[i];               val[i]=0;           }       }       for (int i=1; i<=n; i++) {           dist[i]=dist[f[i]]+val[i];       }       db[0]=1;       s.insert(0);       for (int i=1; i<=q; i++) {           int x; cin >> x;           if (!v[x]) {               v[x]=1;               if (++db[f[x]]==1) {                   add(f[x]);               }           } else {               v[x]=0;               if (--db[f[x]]==0) {                   cl(f[x]);               }           }           cout << sum/2+val[0] <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   map<int, int> H;   int n, m, p, l, r, s, tot, T, a[N], b[N], c[N], ans[N];   int get() {     int v;     scanf( %d , &v);     if (!H[v]) H[v] = ++tot;     return H[v];   }   void add(int x) {     if (c[x]++ < 0)       --s;     else       ++s;   }   void del(int x) {     if (c[x]-- > 0)       --s;     else       ++s;   }   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 0; i < n; ++i) a[i] = get();     for (int i = 0; i < m; ++i) b[i] = get(), --c[b[i]];     for (int i = 0; i < p; ++i) {       l = i, r = i, s = m;       for (int j = 0; j < m - 1; ++j) {         add(a[r]), r += p;         if (r >= n) break;       }       while (r <= n) {         add(a[r]), r += p;         if (!s) ans[T++] = l;         del(a[l]), l += p;       }       while (l <= n) del(a[l]), l += p;     }     printf( %d n , T);     sort(ans, ans + T);     for (int i = 0; i < T; ++i) printf( %d  , ans[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e9;   struct comparator {     bool operator()(const pair<int, int> &a, const pair<int, int> &b) {       return a.first > b.first;     }   } cmp;   int main() {     char in;     vector<pair<int, int> > white, black;     int board[8][8];     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         board[i][j] = 0;       }     }     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> in;         if (in ==  W ) {           white.push_back(pair<int, int>(i, j));           board[i][j] = 1;         }         if (in ==  B ) {           black.push_back(pair<int, int>(i, j));           board[i][j] = 2;         }       }     }     sort(white.begin(), white.end());     sort(black.begin(), black.end(), cmp);     int i = 0, j = 0, x;     if (white[i].first == 0) {       cout <<  A  << endl;       return 0;     }     int pos_A = white[i].first;     int pos_B = black[j].first;     if (pos_A - 1 == 0 && board[pos_A - 1][white[i].second] == 0) {       cout <<  A  << endl;       return 0;     }     while (pos_A != 0) {       pos_A--;       if (board[pos_A][white[i].second] != 0) {         i++;         pos_A = white[i].first;         continue;       }     }     while (pos_B != 7) {       pos_B++;       if (board[pos_B][black[j].second] != 0) {         j++;         pos_B = black[j].first;         continue;       }     }     pos_A = white[i].first;     pos_B = black[j].first;     if (pos_A - (7 - pos_B) <= 0) {       cout <<  A  << endl;     } else {       cout <<  B  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, n;     string s, s1, b;     cin >> n >> k >> s;     b = s;     for (i = k; i < n; i++) b[i] = b[i - k];     if (b >= s)       cout << n << endl << b << endl;     else {       for (i = k - 1; i >= 0; i--) {         if (b[i] ==  9 )           b[i] =  0 ;         else {           b[i]++;           break;         }       }       for (i = k; i < n; i++) b[i] = b[i - k];       cout << n << endl << b << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(int u, int y) { return u > y; }   int main() {     int i, j;     int n, m, x;     int a[100009], b[100009];     int cnt;     while (scanf( %d %d , &n, &x) != EOF) {       for (i = 0; i < n; i++) scanf( %d , &a[i]);       sort(a, a + n, cmp);       for (i = 0; i < n; i++) scanf( %d , &b[i]);       sort(b, b + n);       cnt = 0;       int k = 0;       for (i = 0; i < n; i++) {         for (j = k; j < n; j++) {           if (a[i] != -0x3fffffff && b[j] != -0x3fffffff) {             if (a[i] + b[j] >= x) {               a[i] = -0x3fffffff;               b[j] = -0x3fffffff;               cnt++;               k = j;               break;             }           }         }       }       printf( 1 %d n , cnt);     }   }
#include <bits/stdc++.h>   using namespace std;   int find(string s, string sub, int begin, int end) {     for (int i = begin; i < end - 1; i++)       if (s[i] == sub[0] && s[i + 1] == sub[1]) return i;     return -1;   }   int main() {     string s, sub;     cin >> s;     int size = s.size();     int index1, index2, index3, index4;     index1 = find(s,  AB , 0, size);     index2 = find(s,  BA , 0, size);     index3 = find(s,  BA , index1 + 2, size);     index4 = find(s,  AB , index2 + 2, size);     if ((index1 + 1 && index3 + 1) || (index2 + 1 && index4 + 1))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     std::ios::sync_with_stdio(false);     string a;     cin >> a;     for (int i = 0; i < a.size(); i++) {       if (((int)(a[i]) >= 48 && (int)(a[i]) <= 57) ||           ((int)(a[i]) >= 97 && (int)(a[i]) <= 122) || (int)(a[i]) == 95 ||           (int)(a[i]) == 64 || (int)(a[i]) == 46 || (int)(a[i]) == 47 ||           ((int)(a[i]) >= 65 && (int)(a[i]) <= 90)) {         continue;       } else {         cout <<  NO ;         return 0;       }     }     string d =   ;     int ans1 = -1;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  @ ) {         ans1 = i;         break;       }       d += a[i];     }     if (ans1 == 0 || ans1 == -1) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < d.size(); i++) {       if (d[i] ==  .  || d[i] ==  / ) {         cout <<  NO ;         return 0;       }     }     string e =   ;     int ans2 = -1;     for (int i = ans1 + 1; i < a.size(); i++) {       if (a[i] ==  / ) {         ans2 = i;         break;       }       e += a[i];     }     if (e.size() == 0) {       cout <<  NO ;       return 0;     }     if (ans2 - ans1 == 1) {       cout <<  NO ;       return 0;     }     int ans3 = 0;     for (int i = 0; i < e.size(); i++) {       if (e[i] ==  @ ) {         cout <<  NO ;         return 0;       }       if (e[i] ==  . ) {         ans3++;       }     }     if (e[e.size() - 1] ==  .  || e[0] ==  . ) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < e.size() - 1; i++) {       if (e[i] ==  .  && e[i + 1] ==  . ) {         cout <<  NO ;         return 0;       }     }     if (ans2 == -1) {       cout <<  YES ;       return 0;     }     string r =   ;     for (int i = ans2 + 1; i < a.size(); i++) {       if (a[i] ==  /  || a[i] ==  .  || a[i] ==  @ ) {         cout <<  NO ;         return 0;       }     }     if (ans2 == a.size() - 1) {       cout <<  NO ;       return 0;     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int M = 1e9 + 7;   void madd(int& a, int b) {     a += b;     if (a >= M) a -= M;   }   int mult(int a, int b) { return (1LL * a * b) % M; }   int modexp(int a, int b) {     int res = 1;     while (b > 0) {       if (b & 1) res = mult(res, a);       a = mult(a, a);       b >>= 1;     }     return res;   }   int inverse(int x) { return modexp(x, M - 2); }   const int maxn = 1e5 + 5;   int n, a[maxn];   int cnt[maxn];   int mu[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       cnt[a[i]]++;     }     mu[1] = 1;     for (int i = 1; i < maxn; i++) {       for (int j = 2 * i; j < maxn; j += i) {         mu[j] -= mu[i];         cnt[i] += cnt[j];       }     }     int ans = 0;     for (int d = 1; d <= 100000; d++) {       madd(ans, mult((mu[d] + M) % M, modexp(2, cnt[d]) - 1));     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, d, nxt = 1, arr[10001] = {0}, pos = 0;     cin >> x >> d;     for (int j = 30; j >= 0; j--)       if (x >= (((long long int)1 << j))) {         x -= ((long long int)1 << j);         for (int i = 1; i <= j; i++) arr[pos++] = nxt;         nxt += d;         arr[pos++] = nxt;         nxt += d;       }     if (x == 0) {       cout << pos << endl;       for (int j = 0; j < pos; j++) cout << arr[j] <<    ;       cout << endl;     } else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     int v, f;     Edge *next, *rest;   };   int n, m, b, x[100], k[100], p[100];   long long dp[1048576];   long long ans = 0x3FFFFFFFFFFFFFFFLL;   int main() {     scanf( %d%d%d , &n, &m, &b);     for (int i = 0, len; i < n; i++) {       scanf( %d%d%d , &x[i], &k[i], &len);       for (int j = 0, t; j < len; j++) scanf( %d , &t), p[i] |= 1 << (t - 1);       p[i] ^= (1 << m) - 1;     }     for (int i = 0; i < n; i++) {       for (int j = n - 1; j > i; j--) {         if (k[j - 1] > k[j])           swap(k[j - 1], k[j]), swap(x[j - 1], x[j]), swap(p[j - 1], p[j]);       }     }     for (int i = 1; i < 1 << m; i++) dp[i] = 0x3FFFFFFFFFFFFFFFLL;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 1 << m; j++) dp[j] = min(dp[j], dp[j & p[i]] + x[i]);       if (dp[(1 << m) - 1] < 0x3FFFFFFFFFFFFFFFLL)         ans = min(ans, dp[(1 << m) - 1] + (long long)k[i] * b);     }     printf( %I64d , ans == 0x3FFFFFFFFFFFFFFFLL ? -1 : ans);     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[300005] = {0};   int c1 = 0, c2 = 0, p1 = 0, p2 = 0;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int maxn = -1;     for (int i = 1; i <= n; i++) {       if (c1 == 0) {         p1 = i;         c1 = a[i];       } else if (c2 == 0 && a[i] != c1) {         p2 = i;         c2 = a[i];         maxn = max(maxn, p2 - p1);       } else if (a[i] == c1 && p2 != 0) {         maxn = max(maxn, i - p2);       } else if (a[i] == c2) {         maxn = max(maxn, i - p1);       } else if (a[i] != c1 && a[i] != c2) {         maxn = max(maxn, i - p1);       }     }     cout << maxn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   inline bool read(T &x) {     int c = getchar();     int sgn = 1;     while (~c && c <  0  || c >  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   const int INF = 2000000009;   const int MX = 200005;   const double EPS = 1e-9;   const int MOD = 1000000007;   long long a[MX];   vector<long long> sq, nsq;   int n, p, q;   long long solve1() {     vector<long long> cost;     for (int i = 0; i < q; i++) {       long long t = sqrt(nsq[i]);       cost.push_back(min(nsq[i] - t * t, (t + 1) * (t + 1) - nsq[i]));     }     sort(cost.begin(), cost.end());     long long ret = 0;     int t = (n / 2) - p;     for (int i = 0; i < t; i++) ret += cost[i];     return ret;   }   long long solve2() {     long long ret = 0;     vector<long long> cost;     for (int i = 0; i < p; i++) {       if (sq[i] == 0)         cost.push_back(2LL);       else         cost.push_back(1LL);     }     sort(cost.begin(), cost.end());     int t = (n / 2) - q;     for (int i = 0; i < t; i++) ret += cost[i];     return ret;   }   int main() {     n = ({       int a;       read(a);       a;     });     for (int i = 0; i < n; i++) {       a[i] = ({         long long a;         read(a);         a;       });       long long t = sqrt(a[i]);       if (t * t == a[i])         sq.push_back(a[i]);       else         nsq.push_back(a[i]);     }     p = (int)sq.size();     q = (int)nsq.size();     if (p == q) {       printf( 0 n );       return 0;     }     if (q > p) {       printf( %lld n , solve1());     } else {       printf( %lld n , solve2());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<int> E[200020], V;   int dis[2][200020];   void solve() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       V.push_back(x);     }     for (int i = 0; i < (m); i++) {       int x, y;       scanf( %d%d , &x, &y);       E[x].push_back(y);       E[y].push_back(x);     }     for (int v = 0; v < (2); v++) {       int st = (v == 0 ? 1 : n);       vector<int> q;       auto D = dis[v];       for (int i = 1; i <= n; i++) D[i] = -1;       D[st] = 0;       q.push_back(st);       for (int i = 0; i < ((int)(q).size()); i++) {         int t = q[i];         for (int e : E[t])           if (D[e] == -1) {             D[e] = D[t] + 1;             q.push_back(e);           }       }     }     sort((V).begin(), (V).end(),          [&](int x, int y) { return dis[0][x] > dis[0][y]; });     int mx = -1e9, ans = 0;     for (int i = 0; i + 1 < (int)(V).size(); i++) {       if (dis[0][V[i]] == dis[0][V[i + 1]]) {         printf( %d n , dis[0][n]);         return;       }     }     for (int i = 0; i < ((int)(V).size()); i++) {       int u = V[i];       int val = min({dis[0][n], dis[0][u] + dis[1][u], dis[0][u] + 1 + mx});       ans = max(ans, val);       mx = max(mx, dis[1][u]);     }     printf( %d n , ans);   }   int main() {     int T = 1;     for (int t = 1; t <= T; t++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int n;   int b[MAXN];   set<pair<int, int>, greater<pair<int, int> > > s;   int ans[MAXN];   int main() {     scanf( %d , &n);     for (auto i = 0; i != n; i++) scanf( %d , &b[i]);     for (auto i = 0; i != n; i++) {       int j = (i + 1) % n;       int delta = abs(n - b[i] - b[j]);       s.insert(make_pair(delta, i));     }     int l = 0, r = n - 1;     while (!s.empty()) {       int pos = s.begin()->second;       s.erase(s.begin());       int j = (pos + 1) % n;       if (n - b[pos] > b[j]) {         ans[pos] = l++;       } else {         ans[pos] = r--;       }     }     for (auto i = 0; i != n; i++) printf( %d  , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N = 0;     cin >> N;     for (int i = 0; i < N; i++) {       int length, height;       cin >> length >> height;       int pixL, pixH;       cin >> pixL >> pixH;       int ans = max(max(height - pixH - 1, pixH) * length,                     max(length - pixL - 1, pixL) * height);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > p, pt;   int n, m;   void getanswer(int l, int r) {     if (l >= r) return;     getanswer(l, (l + r) / 2);     getanswer(1 + ((l + r) / 2), r);     for (int i = int(l); i <= int(r); ++i) {       m++;       pt.push_back(make_pair(p[(l + r) / 2].first, p[i].second));     }   }   int main() {     scanf( %I32d , &n);     p.resize(n);     pt.resize(n);     for (int i = 0; i < int(n); i++)       scanf( %I32d%I32d , &p[i].first, &p[i].second);     stable_sort(p.begin(), p.end());     for (int i = 0; i < int(n); i++) pt[i] = p[i];     m = n;     getanswer(0, n - 1);     stable_sort(pt.begin(), pt.end());     p.clear();     for (int i = 0; i < int(m); i++)       if ((i == 0) || (pt[i] != pt[i - 1])) p.push_back(pt[i]);     printf( %I32d n , (int)p.size());     for (int i = 0; i < int(p.size()); i++)       printf( %I32d %I32d n , p[i].first, p[i].second);     return 0;   }