malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int MAXN = 1e5 + 5;   std::unordered_map<int, int> cnt;   int a[MAXN]{};   int m = 1e9, n;   int main() {     scanf( %d , &n);     cnt.reserve(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       ++cnt[a[i]];     }     std::sort(a, a + n);     int bank = cnt.at(a[0]), ret = 0;     for (int i = 1; i < n; ++i)       if (a[i] != a[i - 1]) {         int diff = std::min(bank, cnt.at(a[i]));         bank += cnt.at(a[i]) - diff;         ret += diff;       }     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[4000], n;   string s;   int main() {     cin >> n;     cin >> s;     for (int i = 1; i <= n; i++) ans[i] = 1;     for (int i = 0; i < n - 1; i++) {       if (s[i] ==  = ) {         ans[i + 2] = ans[i + 1];       }       if (s[i] ==  R ) ans[i + 2] = ans[i + 1] + 1;       if (s[i] ==  L ) {         ans[i + 2] = 1;         int j = i;         while (j >= 0) {           if (s[j] ==  L  && ans[j + 1] <= ans[j + 2])             ans[j + 1] = ans[j + 2] + 1;           if (s[j] ==  =  && ans[j + 1] < ans[j + 2]) ans[j + 1] = ans[j + 2];           j--;         }       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[100100];   bool vis[100100];   vector<long long> v;   int main() {     long long n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[n - 1] >= a[n - 2] + a[n - 3]) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     for (int i = n - 1; i >= 0; i -= 2) {       vis[i] = true;       v.push_back(a[i]);     }     for (int i = 0; i < n; i++) {       if (!vis[i]) v.push_back(a[i]);     }     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> g;   long long from, to;   void recurse(long long n) {     if (n > to) return;     if (n >= from && n <= to) {       g.push_back(n);     }     recurse(n * 10 + 4);     recurse(n * 10 + 7);   }   long long get(long long f, long long t, long long ff, long long tt) {     if (ff > t || tt < f) return 0;     ff = max(ff, f);     tt = min(t, tt);     return tt - ff + 1;   }   int main() {     long long pl, pr, vl, vr, k;     cin >> pl >> pr >> vl >> vr >> k;     from = min(pl, vl), to = max(pr, vr);     recurse(4);     recurse(7);     sort(g.begin(), g.end());     double res = 0.0;     if ((int)g.size() < k) {       puts( 0.0 );       return 0;     }     long long total = 0;     long long x, y, p, q, r, s;     long long denom;     denom = (pr - pl + 1) * (vr - vl + 1);     int i, j, sz = g.size();     i = 0;     j = i + k - 1;     while (1) {       if (i == 0)         p = from;       else         p = g[i - 1] + 1;       q = g[i];       r = g[j];       if (j + 1 < (int)g.size())         s = g[j + 1] - 1;       else         s = to;       x = get(pl, pr, p, q);       y = get(vl, vr, r, s);       total = x * y;       x = get(pl, pr, r, s);       y = get(vl, vr, p, q);       total += x * y;       int chk = 0;       if (g[i] >= max(pl, p)) chk++;       if (g[i] <= max(pr, q)) chk++;       if (g[i] >= max(vl, r)) chk++;       if (g[i] <= max(vr, s)) chk++;       if (g[i] >= max(pl, r)) chk++;       if (g[i] <= max(pr, s)) chk++;       if (g[i] >= max(vl, p)) chk++;       if (g[i] <= max(vr, q)) chk++;       if (chk == 8) {         total--;       }       res += (total * 1.0 / denom);       i++;       j = i + k - 1;       if (i >= sz || j >= sz) break;     }     printf( %.12lf n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k, count, x, y, sum;     cin >> n >> k;     count = 2;     x = (n - 1) / k;     y = (n - 1) % k;     if (y == 0) {       sum = 2 * x;     } else if (y == 1) {       sum = 2 * x + 1;     } else {       sum = 2 * (x + 1);     }     cout << sum << endl;     for (int i = 0; i < k; i++) {       cout << 1 <<     << count << endl;       count++;     }     while (count <= n) {       cout << count - k <<     << count << endl;       count++;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n, k;     cin >> t;     while (t--) {       cin >> n >> k;       if (k % 2) {         if (n % 2) {           n -= k - 1;           if (n > 0) {             cout <<  YES n ;             for (int i = (0); i < (k - 1); ++i) {               cout <<  1  ;             }             cout << n <<   n ;           } else {             cout <<  NO n ;           }         } else {           n -= (k - 1) * 2;           if (n > 0) {             cout <<  YES n ;             for (int i = (0); i < (k - 1); ++i) {               cout <<  2  ;             }             cout << n <<   n ;           } else {             cout <<  NO n ;           }         }       } else {         if (n % 2) {           cout <<  NO n ;         } else {           n -= (k - 1);           if (n > 0) {             cout <<  YES n ;             for (int i = (0); i < (k - 1); ++i) {               cout <<  1  ;             }             cout << n <<   n ;           } else {             cout <<  NO n ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int M = 3600 + 10;   int w, h, mx, n, r[M], c[M], cntx, cnty;   long long int fac[M], inv[M], g[M][M], f[M][M], ans;   long long int qpow(long long int a, long long int b) {     long long int y = 1;     for (; b; a = a * a % mod, b >>= 1)       if (b & 1) y = y * a % mod;     return y;   }   long long int C(int a, int b) {     return fac[a] * inv[b] % mod * inv[a - b] % mod;   }   long long int cal(int a, int b) {     return g[w][a] * C(w - cnty - 2 * a, b) % mod * f[h][b] % mod *            C(h - cntx - 2 * b, a) % mod * fac[a] % mod * fac[b] % mod;   }   int main(int argc, char const *argv[]) {     scanf( %d%d%d , &h, &w, &n);     for (int i = 1; i <= n; i++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       r[x1] = r[x2] = c[y1] = c[y2] = 1;     }     mx = max(h, w);     fac[0] = 1;     for (int i = 1; i <= mx; i++) fac[i] = fac[i - 1] * i % mod;     inv[mx] = qpow(fac[mx], mod - 2);     for (int i = mx; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;     for (int i = 1; i <= h; i++) cntx += r[i];     for (int i = 1; i <= w; i++) cnty += c[i];     for (int i = 0; i <= h; i++) f[i][0] = 1;     for (int i = 2; i <= h; i++)       for (int j = 1; 2 * j <= i; j++)         if (r[i] || r[i - 1])           f[i][j] = f[i - 1][j];         else           f[i][j] = (f[i - 1][j] + f[i - 2][j - 1]) % mod;     for (int i = 0; i <= w; i++) g[i][0] = 1;     for (int i = 2; i <= w; i++)       for (int j = 1; 2 * j <= i; j++)         if (c[i] || c[i - 1])           g[i][j] = g[i - 1][j];         else           g[i][j] = (g[i - 1][j] + g[i - 2][j - 1]) % mod;     for (int i = 0; i <= h && 2 * i <= w; i++)       for (int j = 0; j <= w && 2 * j <= h; j++)         if (2 * i + j <= w - cnty && i + 2 * j <= h - cntx)           ans = (ans + cal(i, j)) % mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int MAX = 1000000;   int MIN = -1000000;   int INF = 1000000000;   int x4[4] = {0, 1, 0, -1};   int y4[4] = {1, 0, -1, 0};   int x8[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int y8[8] = {1, 1, 0, -1, -1, -1, 0, 1};   int i, j, k;   int main() {     string str;     cin >> str;     str.push_back( 0 );     reverse(str.begin(), str.end());     str.push_back( 0 );     int indx = 1, ans = 1;     while (indx < str.size()) {       if (str[indx] ==  1  && str[indx + 1] ==  1 ) {         str[indx - 1] =  1 ;         for (i = indx; str[i] ==  1 ; i++) str[i] =  0 ;         str[i] =  1 ;         indx = i;       } else         indx++;     }     int satu = 0;     for (i = (0); i < (str.size()); i++) satu += (str[i] ==  1 );     cout << satu << endl;     {       fflush(stdin);       getchar();     };     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2 )   #pragma GCC optimize( unroll-loops )   #define rep(i,a,b) for(int i=(a);i<=(b);++i)   #define req(i,a,b) for(int i=(a);i>=(b);--i)   #define rep_(i,a,b) for(int i=(a);i<(b).size();++i)   #define F(a) rep(a,1,n)   #define M(a,b) memset(a,b,sizeof a)   #define DC int T;cin>>T;while(T--)   #define ll long long   #define Z(a,b) sort(a+1,a+b+1)   using namespace std;   const unsigned _mod=998244353;   const unsigned mod=1e9+7;   const ll infi=0x3f3f3f3f3f3f3fll;   const int inf=0x3f3f3f3f;   void rd(ll &x){x=0;int f=1;char ch=getchar();while(ch<48||ch>57){if(ch==45)f=-1;ch=getchar();}while(ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();x*=f;}   ll ksm(ll x,ll y=mod-2,ll m=mod){ll ret=1;while(y){if(y&1)ret=ret*x%m;y>>=1ll;x=x*x%m;}return ret;}   ll qpow(ll x,ll y=2){ll ret=1;while(y>0){if(y&1ll)ret=ret*x;y>>=1ll;x=x*x;}return ret;}   /*       [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]       [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]       [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]   */   ll fac[1000010],inv[1000010];   ll C(ll n,ll m){if(m>n||m<0)return 0;return fac[n]*inv[m]%mod*inv[n-m]%mod;}   int n,l,r,ans;   int chk(int x)   {       if (x<=0) return 0;       int a=max(x+l-1,0),b=max(n-r+x,0);       if (a+b>n) return 0;       if (n&1) return C(n-a-b,n/2-a)+C(n-a-b,n/2-a+1);       return C(n-a-b,n/2-a);   }   int chk2()   {       if (n&1) return C(n,n/2)+C(n,n/2+1);       return C(n,n/2);   }   int main()   {       *fac=*inv=1;       rep(i,1,1000000) fac[i]=fac[i-1]*i%mod;       rep(i,1,1000000) inv[i]=ksm(fac[i]);    DC       {           ans=0;           cin>>n>>l>>r;           rep(i,min(-l,r-n),min(n-l,r)) (ans+=chk(i))%=mod;           (ans+=1ll*max(min(-l,r-n)-1,0)*chk2()%mod)%=mod;           cout<<ans<<  n ;       }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e9 + 7;   const long long int mod = 998244353;   long long int mini(long long int a, long long int b) {     if (a >= b) return b;     return a;   }   long long int maxi(long long int a, long long int b) {     if (a >= b) return a;     return b;   }   const long long int MAXN = 300002;   long long int factorial[MAXN + 1], inverse[MAXN + 1];   long long int binpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b % 2 == 1) {         res = (res * a) % mod;       }       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long int nCk(long long int n, long long int k) {     if (k < 0 || k > n) {       return 0;     }     long long int ans = factorial[n];     ans = (ans * inverse[n - k]) % mod;     ans = (ans * inverse[k]) % mod;     return ans;   }   void preCompute() {     long long int fact = 1;     factorial[0] = 1;     inverse[0] = 1;     for (long long int i = 1; i <= MAXN; i++) {       fact = (fact * i) % mod;       factorial[i] = fact;       inverse[i] = binpow(factorial[i], mod - 2);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     preCompute();     long long int n;     cin >> n;     long long int sumr = 0, suml = 0;     vector<long long int> A(2 * n);     for (long long int i = 0; i <= 2 * n - 1; i++) cin >> A[i];     sort(A.begin(), A.end());     for (long long int i = 0; i <= n - 1; i++) suml += A[i], suml %= mod;     for (long long int i = n; i <= 2 * n - 1; i++) sumr += A[i], sumr %= mod;     long long int tot = (mod + sumr - suml) % mod;     long long int a = nCk(2 * n, n);     long long int ans = (a * tot) % mod;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, pos, l, r, ans = 0;     cin >> n >> pos >> l >> r;     if (abs(pos - l) > abs(pos - r)) {       ans += abs(pos - r) + 1;       if (n == r) ans -= abs(pos - r) + 1;       n == r ? 0 : pos = r;       ans += abs(pos - l) + 1;       if (1 == l) ans -= abs(pos - l) + 1;     } else {       ans += abs(pos - l) + 1;       if (1 == l) ans -= abs(pos - l) + 1;       1 == l ? 0 : pos = l;       ans += abs(pos - r) + 1;       if (n == r) ans -= abs(pos - r) + 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, y, t, neg = 0, pos = 0;     cin >> t;     while (t--) {       cin >> x >> y;       if (x < 0)         neg++;       else         pos++;     }     if (neg <= 1 || pos <= 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long maxn = (long long)2 * 1e5 + 10;   const double EPS = 1e-9;   const long long INF = 1e18 + 18;   const long long mod = (long long)10;   long long n, done[maxn], level[maxn], cnt = 0, parent[maxn];   vector<long long> graph[maxn];   set<pair<long long, long long> > seti;   void bfs(long long root) {     queue<long long> Q;     Q.push(root);     done[root] = 1, level[root] = 0;     while (!Q.empty()) {       long long top = Q.front();       Q.pop();       for (long long nb : graph[top]) {         if (done[nb]) continue;         done[nb] = 1;         level[nb] = 1 + level[top];         if (level[nb] > 2) seti.insert({-level[nb], nb});         parent[nb] = top;         Q.push(nb);       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     bfs(1);     while (!seti.empty()) {       pair<long long, long long> top = *seti.begin();       long long tlevel = -top.first, tv = top.second;       for (long long nb : graph[parent[tv]]) {         auto it = seti.find({-level[nb], nb});         if (it != seti.end()) seti.erase(seti.find({-level[nb], nb}));       }       auto it = seti.find({-level[parent[tv]], parent[tv]});       if (it != seti.end())         seti.erase(seti.find({-level[parent[tv]], parent[tv]}));       cnt++;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( -O2 )   const int LIM = 5e5 + 5, MOD = 1e9 + 7;   int t, n, m, k, x, y;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tests;     cin >> tests;     cout << setprecision(10) << fixed;     while (tests--) {       long double d;       cin >> d;       long long v = d * d - 4 * d;       if (v < -1e-9) {         cout <<  N n ;       } else {         long double a, b, c;         c = sqrt(v);         a = (d + c) / 2;         b = (d - c) / 2;         cout <<  Y   << a <<     << b <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> scs(const string& s) {     int n = s.size();     vector<int> p(n), c(s.begin(), s.end());     vector<vector<int>> g(max(n, 256));     for (int i = 0; i < n; i++) g[c[i]].push_back(i);     int b = 0;     for (auto& gr : g) {       for (int x : gr) p[b++] = x;       gr.clear();     }     for (int h = 1; h < n; h <<= 1) {       vector<int> p2(n), c2(n);       for (int j : p) {         int jp = (j + n - h) % n;         g[c[jp]].push_back(jp);       }       b = 0;       for (auto& gr : g) {         for (int x : gr) p2[b++] = x;         gr.clear();       }       b = 0;       c2[p2[0]] = 0;       for (int i = 1; i < n; i++) {         int x = p2[i];         int y = p2[i - 1];         if (c[x] == c[y] && c[(x + h) % n] == c[(y + h) % n])           c2[x] = b;         else           c2[x] = ++b;       }       swap(c, c2);       swap(p, p2);     }     return p;   }   struct stvar {     int a, b;     stvar(int x = 0) : a(x), b(min(0, x)) {}     stvar(int p, int q) : a(p), b(q) {}     stvar operator+(const stvar& o) const {       return stvar(a + o.a, min(b, a + o.b));     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     string s;     cin >> s;     int n = s.size();     vector<int> p = scs(s);     vector<stvar> pref(n + 1), suff(n + 1);     for (int i = 0; i < n; i++)       pref[i + 1] = pref[i] + stvar(s[i] ==  (  ? 1 : -1);     for (int i = n - 1; i >= 0; i--)       suff[i] = stvar(s[i] ==  (  ? 1 : -1) + suff[i + 1];     for (int j : p) {       auto t = suff[j] + pref[j];       if (t.a < 0) {         if (t.a == t.b) {           cout << string(-t.a,  ( ) << s.substr(j) << s.substr(0, j) <<   n ;           return 0;         }       } else {         if (t.b == 0) {           cout << s.substr(j) << s.substr(0, j) << string(t.a,  ) ) <<   n ;           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, tot;   bool ok(int i, int j) {     if (i < 0 or i >= n or j < 0 or j >= m) return 0;     return 1;   }   long long int c[20][20] = {0};   void matcpy(long long int a[20][20], long long int b[20][20]) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         a[i][j] = b[i][j];       }     }   }   void mul(long long int a[20][20], long long int b[20][20]) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         c[i][j] = 0;         for (int k = 0; k < tot; k++) {           c[i][j] += (a[i][k] * b[k][j]) % 1000000007;           c[i][j] %= 1000000007;         }       }     }     matcpy(a, c);   }   long long int id[20][20] = {0};   int cat[20][20] = {0};   void bpow(long long int a[20][20], int k) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         if (i == j)           id[i][j] = 1;         else           id[i][j] = 0;       }     }     while (k > 0) {       if (k & 1) mul(id, a);       mul(a, a);       k /= 2;     }     matcpy(a, id);   }   long long int mat[20][20] = {0};   long long int T[20][20] = {0};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q, x, y, t, tp;     cin >> n >> m >> q;     tot = n * m;     int prev = 1;     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         if (i == j)           mat[i][j] = 1;         else           mat[i][j] = 0;       }     }     while (q--) {       cin >> tp >> x >> y >> t;       x--;       y--;       for (int i1 = 0; i1 < n; i1++) {         for (int j1 = 0; j1 < m; j1++) {           for (int i2 = 0; i2 < n; i2++) {             for (int j2 = 0; j2 < m; j2++) {               if (!cat[i1][j1] and !cat[i2][j2] and                   abs(i1 - i2) + abs(j1 - j2) <= 1) {                 T[m * i1 + j1][m * i2 + j2] = 1;               } else {                 T[m * i1 + j1][m * i2 + j2] = 0;               }             }           }         }       }       bpow(T, t - prev);       prev = t;       mul(mat, T);       if (tp == 1) {         cout << mat[0][m * x + y] <<   n ;       } else if (tp == 2) {         cat[x][y] = 1;       } else {         cat[x][y] = 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, b[100] = {0}, g[100] = {0}, t, k, c = 0;     cin >> n >> m;     cin >> t;     while (t--) {       cin >> k;       b[k] += 1;       c += 1;     }     cin >> k;     while (k--) {       cin >> t;       g[t] += 1;       c += 1;     }     for (int i = 0; i < 100 * max(n, m); i++) {       if (b[i % n] + g[i % m] == 1) {         b[i % n] = g[i % m] = 1;         c += 1;       }     }     if (c == n + m)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n & 1) {       cout <<  1  ;       for (int i = 2; i < n + 1; i++) {         cout << i + 1 <<     << i <<    ;         i += 1;       }       cout << endl;     } else {       for (int i = 1; i < n + 1; i++) {         cout << i + 1 <<     << i <<    ;         i += 1;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300050;   int a[maxn << 2];   int ll[maxn], rr[maxn], x[maxn], N, M;   void getdown(int cur) {     a[cur << 1] = a[cur];     a[(cur << 1) | 1] = a[cur];     a[cur] = 0;   }   void Insert(int cur, int L, int R, int l, int r, int u) {     int mid = (L + R) >> 1;     if (l <= L && R <= r) {       a[cur] = u;       return;     }     if (a[cur]) getdown(cur);     if (l <= mid) Insert(((cur) << 1), L, mid, l, r, u);     if (r > mid) Insert((((cur) << 1) | 1), (mid + 1), R, l, r, u);   }   int Query(int cur, int L, int R, int p) {     int mid = (L + R) >> 1;     if (a[cur]) return a[cur];     if (L == R) return a[cur];     if (p <= mid)       return Query(((cur) << 1), L, mid, p);     else       return Query((((cur) << 1) | 1), (mid + 1), R, p);   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= M; i++) {       scanf( %d%d%d , &ll[i], &rr[i], &x[i]);     }     for (int i = M; i >= 1; i--) {       if (ll[i] < x[i]) Insert(1, 1, N, ll[i], x[i] - 1, x[i]);       if (x[i] < rr[i]) Insert(1, 1, N, x[i] + 1, rr[i], x[i]);     }     printf( %d , Query(1, 1, N, 1));     for (int i = 2; i <= N; i++) printf(  %d , Query(1, 1, N, i));     printf(  n );     return 0;   }
#include <bits/stdc++.h>   int len, rest;   int space[10][110] = {0};   int num = 0;   int ans[21000][3] = {0};   void Check() {     for (int i = 1; i <= len; i++)       if (space[1][i] != 0 && space[1][i] == space[2][i]) {         num++;         rest--;         ans[num][0] = space[2][i];         ans[num][1] = 1;         ans[num][2] = i;         space[2][i] = 0;       }     for (int i = 1; i <= len; i++)       if (space[4][i] != 0 && space[3][i] == space[4][i]) {         num++;         rest--;         ans[num][0] = space[3][i];         ans[num][1] = 4;         ans[num][2] = i;         space[3][i] = 0;       }     return;   }   void Rotate() {     int px = 0, py = 0;     for (int k = 2; k <= 3 && !px; k++)       for (int i = 1; i <= len && !px; i++)         if (space[k][i] == 0) {           px = k;           py = i;         }     for (int time = 1; time < len * 2; time++) {       int nx, ny;       if (px == 2)         if (py < len) {           nx = 2;           ny = py + 1;         } else {           nx = 3;           ny = len;         }       else if (py > 1) {         nx = 3;         ny = py - 1;       } else {         nx = 2;         ny = 1;       }       if (space[nx][ny] != 0) {         num++;         ans[num][0] = space[nx][ny];         ans[num][1] = px;         ans[num][2] = py;         space[px][py] = space[nx][ny];         space[nx][ny] = 0;       }       px = nx;       py = ny;     }     return;   }   int main() {     int num_car;     scanf( %d%d , &len, &num_car);     rest = num_car;     for (int k = 1; k <= 4; k++)       for (int i = 1; i <= len; i++) scanf( %d , &space[k][i]);     Check();     if (rest == num_car && num_car == len * 2) {       printf( -1 n );       return 0;     }     while (rest) {       Rotate();       Check();     }     printf( %d n , num);     for (int i = 1; i <= num; i++)       printf( %d %d %d n , ans[i][0], ans[i][1], ans[i][2]);     return 0;   }