malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   const int N = (int)1e5 + 10;   struct qq {     int l, r, i, w;   };   int t[4 * N], ans[2 * N];   pair<int, int> p[2 * N];   vector<qq> qx[N], qy[N];   void upd(int pos, int val, int v = 1, int l = 1, int r = N - 10) {     if (l == r) {       t[v] = val;       return;     }     int m = (l + r) >> 1;     if (pos <= m) {       upd(pos, val, v + v, l, m);     } else {       upd(pos, val, v + v + 1, m + 1, r);     }     t[v] = min(t[v + v], t[v + v + 1]);   }   int get(int l, int r, int v = 1, int tl = 1, int tr = N - 10) {     if (l > r || tr < l || tl > r) {       return inf;     }     if (l <= tl && tr <= r) {       return t[v];     }     int tm = (tl + tr) >> 1;     return min(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));   }   inline bool cmp(pair<int, int> f, pair<int, int> s) {     return f.second < s.second || (f.second == s.second && f.first < s.first);   }   int main() {     int n, m, k, q;     scanf( %d %d %d %d , &n, &m, &k, &q);     for (int i = 1; i <= k; i++) {       int x, y;       scanf( %d %d , &x, &y);       p[i] = {x, y};     }     for (int i = 1; i <= q; i++) {       int ax, ay, bx, by;       scanf( %d %d %d %d , &ax, &ay, &bx, &by);       qx[bx].emplace_back(qq({ay, by, i, ax}));       qy[by].emplace_back(qq({ax, bx, i, ay}));     }     sort(p + 1, p + k + 1);     int ptr = 1;     for (int i = 1; i < N; i++) {       while (ptr <= k && p[ptr].first == i) {         upd(p[ptr].second, i);         ptr++;       }       for (auto j : qx[i]) {         ans[j.i] |= ((get(j.l, j.r) >= j.w) ? 1 : 0);       }     }     memset(t, 0, sizeof(t));     ptr = 1;     sort(p + 1, p + k + 1, cmp);     for (int i = 1; i < N; i++) {       while (ptr <= k && p[ptr].second == i) {         upd(p[ptr].first, i);         ptr++;       }       for (auto j : qy[i]) {         ans[j.i] |= ((get(j.l, j.r) >= j.w) ? 1 : 0);       }     }     for (int i = 1; i <= q; i++) {       if (ans[i] == 1)         puts( YES );       else         puts( NO );     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 3e5 + 10, N2 = 2e5, delta = 10499, mod = 1e9 + 7,                       oo = 1e18, LOG = 20, SQ = 300;   const long double PI = 3.141592653589793;   pair<pair<long long int, long long int>, long long int> p[N];   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       for (long long int i = 0; i < 2 * n - 1; i++) {         long long int x, y;         cin >> x >> y;         p[i] = {{x, y}, i};       }       cout <<  YES n ;       sort(p, p + 2 * n - 1);       for (long long int i = 0; i < 2 * n - 2; i += 2) {         if (p[i].first.second < p[i + 1].first.second)           cout << p[i + 1].second + 1 <<    ;         else           cout << p[i].second + 1 <<    ;       }       cout << p[2 * n - 2].second + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     fixed(cout);     cout << setprecision(10);     ;     long long int n, h;     cin >> n >> h;     for (int i = 1; i <= n - 1; i++) {       double x = (h * h * i) / double(n);       x = sqrt(x);       if (i == n) break;       cout << x <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int tipo[100000 + 5];   int main() {     int n, x, y, z, m;     cin >> n >> m;     memset(tipo, -1, sizeof(tipo));     for (int i = 0; i < m; ++i) {       cin >> x >> y >> z;       x--, y--, z--;       bool enc = 0;       if (tipo[x] != -1) {         enc = 1;         tipo[y] = (tipo[x] + 1) % 3;         tipo[z] = (tipo[x] + 2) % 3;       } else if (tipo[y] != -1) {         enc = 1;         tipo[x] = (tipo[y] + 1) % 3;         tipo[z] = (tipo[y] + 2) % 3;       } else if (tipo[z] != -1) {         enc = 1;         tipo[x] = (tipo[z] + 1) % 3;         tipo[y] = (tipo[z] + 2) % 3;       }       if (enc == 0) {         tipo[x] = 0, tipo[y] = 1, tipo[z] = 2;       }     }     for (int i = 0; i < n; ++i) {       if (i == 0)         cout << tipo[i] + 1;       else         cout <<     << tipo[i] + 1;     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int vis[10] = {0};   int main() {     int c = 0, n = 0, i, flag = 0;     long long ans = 1;     string s;     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  ? ) {         if (i == 0) flag = 1;         c++;       }       if (s[i] >=  A  && s[i] <=  J ) {         if (i == 0) flag = 1;         vis[s[i] -  A ] = 1;       }     }     for (i = 0; i < 10; i++)       if (vis[i]) n++;     for (i = 0; i < n; i++) ans *= 10 - i;     if (flag) {       ans *= 9;       if (ans % 10 == 0) {         ans /= 10;         flag = 0;       }     }     cout << ans;     for (i = flag; i < c; i++) cout << 0;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     c_p_c();     long long t;     cin >> t;     while (t--) {       long long n, r;       cin >> n >> r;       long long k = r;       r = min(n - 1, r);       long long ans = r * (r + 1) / 2;       if (k > r) ans++;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   const int inf = 0x3f3f3f3f;   vector<int> ve[maxn];   int a[maxn], c[maxn];   struct node {     int pos, val;   } nod[maxn];   bool cmp(node a, node b) { return a.val < b.val; }   bool cmp1(int x, int y) { return nod[a[x]].val > nod[a[y]].val; }   int main() {     int n, q, k, x, y;     scanf( %d , &n);     for (int i = 0; i <= n; i++) {       ve[i].clear();       nod[i].val = 0;       nod[i].pos = 0;     }     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       ve[x].push_back(y);       nod[x].pos = x;       nod[x].val = max(nod[x].val, y);     }     sort(nod + 1, nod + 1 + n, cmp);     for (int i = 1; i <= n; i++) a[nod[i].pos] = i;     scanf( %d , &q);     int ans, res;     while (q--) {       int max1 = nod[n].val, pos1 = nod[n].pos;       int max2 = nod[n - 1].val, pos2 = nod[n - 1].pos, s, j = n - 2;       scanf( %d , &k);       for (int i = 0; i < k; i++) scanf( %d , &c[i]);       sort(c, c + k, cmp1);       for (int i = 0; i < k; i++) {         if (c[i] == pos1) {           max1 = max2;           pos1 = pos2;           max2 = nod[j].val;           pos2 = nod[j--].pos;         } else if (c[i] == pos2) {           max2 = nod[j].val;           pos2 = nod[j--].pos;         }       }       if (max1 == 0)         ans = 0, res = 0;       else {         int l = 0, r = ve[pos1].size(), mid;         while (l < r) {           mid = l + (r - l) / 2;           if (max2 <= ve[pos1][mid])             r = mid;           else             l = mid + 1;         }         ans = pos1;         res = ve[pos1][l];       }       printf( %d %d n , ans, res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod_expo(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int main() {     long long int t;     cin >> t;     while (t--) {       map<long long int, long long int> right;       long long int n;       cin >> n;       long long int ar[2 * n + 4];       long long int dp[2 * n + 3];       for (long long int i = 0; i < 2 * n; i++) {         cin >> ar[i];       }       long long int count = 0;       for (long long int i = 0; i < n; i++) {         if (ar[i] == 1)           count++;         else {           count--;         }         dp[i] = count;       }       count = 0;       for (long long int i = 2 * n - 1; i >= n; i--) {         if (ar[i] == 1)           count--;         else {           count++;         }         dp[i] = count;         right[count] = i;       }       long long int mini = 2 * n;       for (long long int i = 0; i < 2 * n; i++) {         if (dp[i] == 0) {           if (i < n && mini > (2 * n - i - 1))             mini = 2 * n - i - 1;           else if (i >= n && mini > (i))             mini = i;         }       }       for (long long int i = n - 1; i >= 0; i--) {         long long int p = dp[i];         long long int k = right[p];         if (k > 0 && mini > (k - i - 1)) mini = k - i - 1;       }       cout << mini << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long A, B;     cin >> A >> B;     if (A < B) {       puts( -1 );       return 0;     }     if ((A - B) % 2 != 0) {       puts( -1 );       return 0;     }     unsigned long long C = (A - B) / 2;     unsigned long long X = 0, Y = 0;     for (unsigned long long bit = 1ULL << 63; bit >= 1; bit >>= 1) {       bool dif = (B & bit);       bool allHas = (C & bit);       if (allHas && dif) {         puts( -1 );         return 0;       }       if (allHas) {         X |= bit;         Y |= bit;       }       if (dif) {         Y |= bit;       }     }     cout << X <<     << Y << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)1e4 + 10;   int n, w, b, x;   long long dp[1005][maxN];   int c[maxN];   int cost[maxN];   int main() {     cin >> n >> w >> b >> x;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n; i++) cin >> cost[i];     memset(dp, -1, sizeof dp);     dp[0][0] = w;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < maxN; j++) {         long long cur_bal = dp[i - 1][j];         if (cur_bal == -1) continue;         for (int k = 0; k <= c[i]; k++) {           if (1LL * k * cost[i] > cur_bal) continue;           dp[i][j + k] = max(min(cur_bal - (1LL * k * cost[i]) + x,                                  1LL * w + (1LL * b * (j + k))),                              dp[i][j + k]);         }       }     }     for (int i = maxN - 1; i >= 0; i--) {       if (dp[n][i] != -1) {         cout << i;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, n, b[100010], mp[100010], hah[100010];   struct qwq {     int v, id;   } a[100010];   bool cmp(qwq x, qwq y) { return x.v < y.v; }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++)         scanf( %d , &a[i].v), mp[a[i].v] = i, b[i] = a[i].v, hah[i] = 0;       sort(a + 1, a + n + 1, cmp);       bool flag = true;       for (int i = 1; i <= n;) {         int now = mp[i], js = i;         hah[now] = 1;         for (int j = now + 1; j <= n; j++) {           if (hah[j]) {             break;           }           if (b[j] != b[j - 1] + 1) {             flag = false;             break;           } else {             hah[j] = 1;             js++;           }         }         if (!flag) {           break;         }         i = js + 1;       }       if (flag)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int p = 1000003;   const int n = 10;   int inv[1000005], a[15][15], ans[15];   int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int calc(int x) {     int res = 0;     for (int i = n; i >= 0; i--) res = (1LL * res * x + ans[i]) % p;     return res;   }   int main() {     inv[1] = 1;     for (int i = 2; i < p; i++) inv[i] = 1LL * (p - p / i) * inv[p % i] % p;     printf( ? 0 n );     fflush(stdout);     ans[0] = read();     for (int i = 1; i <= n; i++) {       printf( ? %d n , i);       fflush(stdout);       a[i][0] = 1;       for (int j = 1; j <= n; j++) a[i][j] = a[i][j - 1] * i % p;       a[i][n + 1] = (read() + p - ans[0]) % p;     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int t = 1LL * a[j][i] * inv[a[i][i]] % p;         for (int k = i + 1; k <= n + 1; k++)           a[j][k] = (a[j][k] + p - 1LL * a[i][k] * t % p) % p;         a[j][i] = 0;       }     }     for (int i = n; i >= 1; i--) {       int res = a[i][n + 1];       for (int j = i + 1; j <= n; j++)         res = (res + p - 1LL * a[i][j] * ans[j] % p) % p;       ans[i] = 1LL * res * inv[a[i][i]] % p;     }     for (int i = 0; i < p; i++) {       if (calc(i) == 0) {         printf( ! %d n , i);         fflush(stdout);         exit(0);       }     }     printf( ! -1 n );     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 10;   int n, d[MAXN], id[MAXN];   bool b[MAXN][MAXN];   bool cmp(int a, int b) {     if (d[a] > d[b]) return true;     if (d[a] < d[b]) return false;     return a < b;   }   int main() {     scanf( %d , &n);     if (n == 4) puts( -1 ), exit(0);     b[3][1] = b[1][2] = b[2][3] = 1;     d[1] = d[2] = d[3] = 1;     for (int i = 4; i <= n; ++i) {       for (int j = 1; j < i; ++j) id[j] = j;       sort(id + 1, id + i, cmp);       for (int j = 1; j <= i / 2; ++j) b[id[j]][i] = 1, ++d[i];       for (int j = i / 2 + 1; j < i; ++j) b[i][id[j]] = 1, ++d[id[j]];     }     for (int i = 1; i <= n; ++i, puts(  ))       for (int j = 1; j <= n; ++j) printf( %d  , b[i][j]);     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   int q, t, l, r, x, last;   std::map<int, int> dsu, val;   int root(int x) {     int cur = dsu[x];     if (cur < 0)       return x;     else {       dsu[x] = root(dsu[x]);       val[x] ^= val[cur];       return dsu[x];     }   }   void connect(int x, int y, int v) {     int a = root(x), b = root(y);     if (a != b) {       if (dsu[a] > dsu[b]) std::swap(a, b);       dsu[a] += dsu[b];       dsu[b] = a;       val[b] = v ^ val[x] ^ val[y];     }   }   int main() {     std::cin >> q;     while (q--) {       std::cin >> t >> l >> r;       if ((l ^= last) > (r ^= last)) std::swap(l, r);       if (!dsu.count(l)) dsu[l] = -1;       if (!dsu.count(++r)) dsu[r] = -1;       if (t == 1) {         std::cin >> x;         connect(l, r, x ^= last);       } else if (root(l) == root(r))         std::cout << (last = val[l] ^ val[r]) <<   n ;       else         std::cout << -(last = 1) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long pl, pr, vl, vr;   int k;   long long Inter(long long x1, long long x2, long long y1, long long y2) {     long long a = max(x1, y1);     long long b = min(x2, y2);     if (a > b)       return 0.0;     else       return b - a + 1;   }   long long GetProb(long long x1, long long x2, long long y1, long long y2) {     return Inter(x1, x2, pl, pr) * Inter(y1, y2, vl, vr) +            Inter(x1, x2, vl, vr) * Inter(y1, y2, pl, pr);   }   int main() {     cin >> pl >> pr >> vl >> vr >> k;     vector<long long> numbers;     numbers.push_back(0);     int a = 0;     for (int i = 0; i < 9; i++) {       int b = numbers.size();       for (int j = a; j < b; j++) {         numbers.push_back(numbers[j] * 10 + 4);         numbers.push_back(numbers[j] * 10 + 7);       }       a = b;     }     numbers.push_back(1000000000);     long long P = (pr - pl + 1) * (vr - vl + 1);     long long gP = 0;     int l = 1;     int r = k;     while (1) {       gP +=           GetProb(numbers[l - 1] + 1, numbers[l], numbers[r], numbers[r + 1] - 1);       l++;       r++;       if (r + 1 >= numbers.size()) break;     }     l = 1;     r = k + 1;     while (1) {       l++;       r++;       if (r + 1 >= numbers.size()) break;     }     l = 1;     if (k == 1)       while (1) {         gP -= GetProb(numbers[l], numbers[l], numbers[l], numbers[l]) / 2;         l++;         if (l + 1 >= numbers.size()) break;       }     printf( %.15f , (long double)gP / P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 205;   int a[maxn];   int main() {     ios::sync_with_stdio(false);     int n, k;     scanf( %d %d , &n, &k);     int m = n + n + 1;     for (int i = 0; i < m; ++i) scanf( %d , &a[i]);     for (int i = 1; k && i < m; i += 2) {       if (a[i] > max(a[i - 1], a[i + 1]) + 1) {         --a[i];         --k;       }     }     for (int i = 0; i < m; ++i) printf( %d  , a[i]);     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[10][300];   int s[10][10];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < int(n); ++i)       for (int j = 0; j < int(m); ++j) cin >> s[i][j];     int *cur = dp[0], *next = dp[1];     for (int i = n - 1; i >= 0; --i) {       for (int j = m - 1; j >= 0; --j) {         for (int used = 0; used < int(1 << m); ++used) {           if (used & (1 << j)) {             next[used] = cur[used & ~(1 << j)];           } else {             int best = 0;             if (j + 1 < m && !(used & (1 << (j + 1))))               best = max(best,                          cur[used | (1 << (j + 1))] + (s[i][j] == s[i][j + 1]));             if (i + 1 < n)               best = max(best, cur[used | (1 << j)] + (s[i][j] == s[i + 1][j]));             next[used] = best;           }         }         swap(cur, next);       }     }     cout << n * m / 2 - cur[0] << endl;   }
#include <bits/stdc++.h>   int main() {     int ele, n, x[110], y[110], p, q, e = 0, f = 0, i, e1 = 0, e2 = 0, o1 = 0,                                       o2 = 0;     char s1[300], s2[300];     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]);     for (i = 1; i <= n; i++) {       if (x[i] % 2 == 0) e1++;       if (x[i] % 2 != 0) {         o1++;         p = i;         s2[f++] = (char)(i + 0);       }       if (y[i] % 2 == 0) e2++;       if (y[i] % 2 != 0) {         o2++;         q = i;         s1[e++] = (char)(i + 0);       }     }     s2[f] =   0 ;     s1[e] =   0 ;     ele = strcmp(s1, s2);     if (o1 % 2 == 0 && o2 % 2 == 0) {       printf( 0 );       goto label;     }     if (o1 % 2 != 0 && o2 % 2 == 0) {       printf( -1 );       goto label;     }     if (o1 % 2 == 0 && o2 % 2 != 0) {       printf( -1 );       goto label;     }     if (o1 % 2 != 0 && o2 % 2 != 0) {       if (o1 > 1 || o2 > 1) {         if (ele == 0)           printf( -1 );         else           printf( 1 );       } else if (p == q)         printf( -1 );       else         printf( 1 );     } else       printf( 0 );   label:     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100001], flag[100001];   vector<pair<long long, long long> > ans;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, sum = 0;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sum /= n / 2;     for (long long i = 0; i < n; i++) {       if (flag[i] == 0)         for (long long j = i + 1; j < n; j++) {           if (flag[j] == 0 && ((a[i] + a[j]) == sum)) {             flag[j] = 1;             flag[i] = 1;             ans.push_back(make_pair(i + 1, j + 1));             break;           }         }     }     for (auto i : ans) {       cout << i.first <<     << i.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long f(const string& s) {     long long res = 0;     for (int i = 0; i + 1 < s.size(); ++i) {       if (s[i] != s[i + 1]) {         res += (m - 1) * (n - i - 1);       }     }     return res;   }   long long g(const string& s) {     long long res = 0;     for (int i = 0; i + 1 < s.size(); ++i)       if (s[i] != s[i + 1]) {         int j = i + 1;         while (j + 1 < s.size() && s[j + 1] == s[j - 1]) ++j;         long long l = j - i + 1;         res += l * (l - 1) / 2;         i = j - 1;       }     return res;   }   int main() {     string s;     cin >> n >> m >> s;     long long res = n * (m - 1) + f(s);     reverse(s.begin(), s.end());     res += f(s) - g(s);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using std::bitset;   using std::cerr;   using std::cin;   using std::complex;   using std::cout;   using std::deque;   using std::endl;   using std::ios_base;   using std::iterator;   using std::map;   using std::max;   using std::max_element;   using std::min;   using std::min_element;   using std::multimap;   using std::multiset;   using std::pair;   using std::queue;   using std::reverse;   using std::set;   using std::sort;   using std::stable_sort;   using std::stack;   using std::string;   using std::swap;   using std::unique;   using std::vector;   namespace MySpace {   struct Small_Segment_Tree {     vector<int> a;     int l, r;       private:     int __summ(int L, int R, int l, int r, int v) {       if (L <= l && r <= R) return a[v];       if (R <= l || r <= L) return 0;       int m = (l + r) / 2;       return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);     }     void __set(int P, int l, int r, int v, int V) {       if (l + 1 == r) {         a[v] = V;         return;       }       int m = (l + r) / 2;       if (P < m) {         __set(P, l, m, 2 * v + 1, V);         a[v] = a[2 * v + 1] + a[2 * v + 2];       } else {         __set(P, m, r, 2 * v + 2, V);         a[v] = a[2 * v + 1] + a[2 * v + 2];       }     }       public:     int Summ(int L, int R) {       if (R < L) return 0;       return __summ(L, R + 1, l, r, 0);     }     void Set(int P, int V) { __set(P, l, r, 0, V); }     Small_Segment_Tree(int _n) {       a.resize(4 * _n);       l = 0, r = _n;     }   };   long long inq(long long x, long long q, long long MOD) {     if (q == 0) return 1;     long long l = inq(x, q / 2, MOD);     if (q % 2) return l * l % MOD * x % MOD;     return l * l % MOD;   }   };  // namespace MySpace   using namespace MySpace;   long long n, m;   long long a[500000];   int main() {     ios_base::sync_with_stdio();     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = n; i < 2 * n; i++) cin >> a[i];     sort(a, a + 2 * n);     long long s1 = 0, s2 = 0;     for (int i = 0; i < n; i++) s1 += a[i];     for (int i = n; i < 2 * n; i++) s2 += a[i];     if (s1 == s2) {       cout << -1;       return 0;     }     for (int i = 0; i < 2 * n; i++) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   struct event {     int t, time, L, R, idx;     event() {}     event(int t, int time, int L, int R, int idx)         : t(t), time(time), L(L), R(R), idx(idx) {}     bool operator<(const event& a) const {       return (time < a.time || (time == a.time && t < a.t));     }   } e[200005 * 23];   int n, m, i, j, ai, place[200005], L, R, en, idx, ans[200005], fw[200005];   void modify(int j) {     for (; j <= n; j = (j | (j - 1)) + 1) ++fw[j];   }   int query(int j) {     int rt = 0;     for (; j; j &= (j - 1)) rt += fw[j];     return rt;   }   int main(int argc, char* const argv[]) {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %d , &ai);       place[ai] = i;     }     for (i = 1; i <= m; i++) {       scanf( %d%d , &L, &R);       e[++en] = event(2, R, L, R, i);       e[++en] = event(2, L - 1, L, R, -i);     }     for (i = 1; i <= n; i++) {       j = i;       while (j <= n) {         e[++en] = event(1, place[i], place[j], 0, 0);         j += i;       }     }     std::sort(e + 1, e + en + 1);     for (i = 1; i <= en; i++)       if (e[i].t == 1)         modify(e[i].L);       else {         idx = abs(e[i].idx);         ans[idx] += (query(e[i].R) - query(e[i].L - 1)) * (e[i].idx / idx);       }     for (i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }