malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000 + 9;   const long long MOD = 1000 * 1000 * 1000 + 7;   const double EPS = 1e-9;   const int di[] = {-1, 0, 1, 0};   const int dj[] = {0, -1, 0, 1};   const int N = 505;   int n, k;   int a[N][N];   int b[N][N];   int s[N][N];   int q;   int f[N * N];   int g[N * N];   int ans;   int mod;   void dfs(int x, int y, int c) {     b[x][y] = c;     g[c]++;     for (int i = 0; i < 4; ++i) {       int xx = x + di[i];       int yy = y + dj[i];       if (a[xx][yy] && !b[xx][yy]) {         dfs(xx, yy, c);       }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         char c;         scanf(  %c , &c);         a[i + 1][j + 1] = c ==  . ;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (a[i][j] && !b[i][j]) {           dfs(i, j, ++q);         }       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];       }     }     for (int i = 1; i + k - 1 <= n; ++i) {       for (int r = 0; r <= q; ++r) {         f[r] = 0;       }       mod = 0;       for (int u = i - 1; u <= i + k; ++u) {         for (int v = 0; v <= k + 1; ++v) {           if ((u == i - 1 || u == i + k) && (v == 0 || v == k + 1)) {             continue;           }           if (f[b[u][v]] == 0) {             mod += g[b[u][v]];           }           f[b[u][v]]++;         }       }       for (int j = 1; j + k - 1 <= n; ++j) {         ans = max(ans,                   mod + (k * k - (s[i + k - 1][j + k - 1] - s[i - 1][j + k - 1] -                                   s[i + k - 1][j - 1] + s[i - 1][j - 1])));         if (j + k - 1 < n) {           for (int u = i - 1; u <= i + k; ++u) {             int x = b[u][j - 1 + (u == i - 1 || u == i + k)];             --f[x];             if (f[x] == 0) {               mod -= g[x];             }           }           for (int u = i - 1; u <= i + k; ++u) {             int x = b[u][j + k + 1 - (u == i - 1 || u == i + k)];             if (f[x] == 0) {               mod += g[x];             }             ++f[x];           }         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using i3 = pair<int, ii>;   using li = pair<ll, int>;   using lii = pair<ll, ii>;   using vi = vector<int>;   using vl = vector<ll>;   using vli = vector<li>;   using vii = vector<ii>;   using vi3 = vector<i3>;   using vlii = vector<lii>;   const int N = 1e5 + 5;   const int INF = 1e9 + 7;   const double eps = 1e-12, PI = acos(-1);   int n, m;   char s[N];   int mem[N][5];   int dp(int i, int rem) {     if (i == n) {       return rem == 0 ? 0 : INF;     }     int &ret = mem[i][rem];     if (ret != -1) return ret;     return ret = min(1 + dp(i + 1, rem),                      dp(i + 1, (rem * 10 + int(s[i] -  0 )) % 3));   }   vi ans;   void path(int i, int rem) {     if (i == n) return;     if (dp(i + 1, (rem * 10 + int(s[i] -  0 )) % 3) == dp(i, rem)) {       ans.push_back(s[i] -  0 );       path(i + 1, (rem * 10 + int(s[i] -  0 )) % 3);       return;     }     path(i + 1, rem);   }   void solve(int cs) {     scanf( %s , s);     n = strlen(s);     int mn = INF, idx = INF;     bool isZero = 0;     memset(mem, -1, sizeof mem);     for (int i = 0; s[i]; i++) {       if (s[i] ==  0 ) {         isZero = 1;         continue;       }       int curr = dp(i + 1, int(s[i] -  0 ) % 3) + i;       if (curr < mn) {         mn = curr;         idx = i;       }     }     if (idx == INF) {       printf( %d n , isZero ? 0 : -1);       return;     }     path(idx + 1, int(s[idx] -  0 ) % 3);     printf( %c , s[idx]);     for (int A : ans) printf( %d , A);     printf(  n );   }   int main() {     int t = 1;     for (int cs = 1; t--; cs++) {       solve(cs);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void seive(bool a[], long long int n) {     for (int i = 2; i * i <= n; i++) {       if (a[i] == true) {         for (int j = i * i; j <= n; j += i) a[j] = false;       }     }   }   int np(bool a[], long long int ppr, long long int n) {     ppr++;     while (ppr <= n) {       if (a[ppr] == true) return ppr;       ppr++;     }     return -1;   }   int main() {     long long int n, i, n_1 = 0, n_2 = 0, sum = 0, s;     int t;     cin >> n;     for (i = 0; i < n; i++) {       cin >> t;       if (t == 1)         n_1++;       else         n_2++;       sum += t;     }     bool a[sum + 1];     memset(a, true, sizeof(a));     seive(a, sum);     s = 0;     a[1] = false;     long long int ppr = 0, pr;     while (s <= sum && pr != -1) {       pr = np(a, ppr, sum);       if (pr - ppr >= 2 && pr != -1) {         s = pr;         int m = min(n_2, (pr - ppr) / 2);         n_2 -= m;         for (i = 0; i < m; i++) cout << 2 <<    ;         m = min(n_1, 2 * ((pr - ppr) / 2 - m));         n_1 -= m;         for (i = 0; i < m; i++) cout << 1 <<    ;         ppr = pr;       } else if (pr != -1) {         n_1--;         if (n_1 < 0) {           for (i = 0; i < n_1; i++) cout << 1 <<    ;           for (i = 0; i < n_2; i++) cout << 2 <<    ;           pr = -1;         } else {           cout << 1 <<    ;         }         ppr = pr;       } else {         for (i = 0; i < n_1; i++) cout << 1 <<    ;         for (i = 0; i < n_2; i++) cout << 2 <<    ;       }       if (n_1 <= 0 && n_2 <= 0) break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, z, p, i, j, k, ans, t, a[105], b[105], d[105], f[105][10005];   bool cmp(int x, int y) { return x > y; }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]), z += a[i];     for (i = 1; i <= n; i++) scanf( %d , &b[i]), d[i] = b[i];     sort(d + 1, d + n + 1, cmp);     memset(f, 0x80, sizeof(f));     f[0][0] = 0;     for (i = 1; i <= n; i++) {       p += d[i];       if (p >= z) {         ans = i;         break;       }     }     for (i = 1; i <= n; i++)       for (j = p; j >= b[i]; j--)         for (k = 1; k <= ans; k++)           f[k][j] = max(f[k][j], f[k - 1][j - b[i]] + a[i]);     for (i = z; i <= p; i++) t = max(t, f[ans][i]);     printf( %d %d , ans, z - t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m[100002];   int main() {     memset(m, 255, sizeof m);     int runs;     scanf( %d , &runs);     for (int j = 0; j < runs; j++) {       int x, y, ret = 0;       scanf( %d%d , &x, &y);       for (int i = 1; i * i <= x; i++)         if (x % i == 0) {           if (m[i] < j - y) ret++;           if (i * i < x && m[x / i] < j - y) ret++;           m[i] = j;           m[x / i] = j;         }       printf( %d n , ret);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N_MAX = 1e5;   bool in[N_MAX + 1];   int t, n, a[N_MAX], m[N_MAX], pr[N_MAX + 1];   vector<int> inc;   vector<vector<int>> sol;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       int k = 1, rem = n;       while ((k + 1) * (k + 2) <= 2 * n) k++;       for (int i = 1; i <= n; i++) in[i] = true;       sol.clear();       while (0 < rem) {         inc.clear();         for (int i = 0; i < n; i++) {           if (!in[a[i]]) continue;           if (inc.empty() || a[i] > inc.back()) {             pr[a[i]] = (inc.empty() ? -1 : inc.back());             inc.push_back(a[i]);           } else {             auto it = upper_bound(inc.begin(), inc.end(), a[i]);             *it = a[i];             pr[a[i]] = (it == inc.begin() ? -1 : *(it - 1));           }         }         if (inc.size() <= k) {           int first = sol.size();           sol.push_back(vector<int>());           m[first] = n + 1;           for (int i = 0; i < n; i++) {             if (!in[a[i]]) continue;             if (m[(int)sol.size() - 1] < a[i]) {               m[sol.size()] = a[i];               sol.push_back(vector<int>());               sol.back().push_back(a[i]);               continue;             }             int l = first, r = (int)sol.size() - 1;             while (l < r) {               int mid = (l + r) / 2;               if (m[mid] > a[i])                 r = mid;               else                 l = mid + 1;             }             sol[l].push_back(a[i]);             m[l] = a[i];           }           break;         }         stack<int> st;         int act = inc.back();         while (act != -1) {           st.push(act);           act = pr[act];         }         sol.push_back(vector<int>());         while (!st.empty()) {           sol.back().push_back(st.top());           st.pop();         }         for (int i : sol.back()) in[i] = false;         rem -= inc.size();         while (2 * rem < k * (k + 1)) k--;       }       cout << sol.size() <<   n ;       for (int i = 0; i < sol.size(); i++) {         cout << sol[i].size();         for (int s : sol[i]) cout <<     << s;         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i1;   long long cont = 0;   int main() {     cin >> n;     for (long long i = 0; i < n; ++i) {       long long x, y;       cin >> x >> y;       if (x - y != 1) {         cout <<  NO  << endl;       } else {         long long p = x + y, s = 0;         for (long long j = 2; j <= sqrt(p); ++j) {           if (p % j == 0) {             s = 1;             break;           }         }         if (s == 0) {           cout <<  YES  << endl;         } else {           cout <<  NO  << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   bool Max(T1& a, T2 b) {     return a < b ? a = b, 1 : 0;   }   template <typename T1, typename T2>   bool Min(T1& a, T2 b) {     return a > b ? a = b, 1 : 0;   }   const int N = 200002, inf = 1e9 + 1;   int s[N], g[N], ans[N];   bool vi[N];   vector<int> cap[N * 10];   void solve() {     int n, m;     cin >> n;     int mncap = N * 10;     for (int i = 0; i < (n); ++i) {       cin >> s[i] >> g[i];       g[i] += s[i];       ans[i] = g[i];     }     int mn = inf;     for (int i = 0; i < (n); ++i) {       mn++;       Min(mn, g[i]);       Min(ans[i], mn);     }     mn = inf;     for (int i = n - 1; i >= (0); --i) {       mn++;       Min(mn, g[i]);       Min(ans[i], mn);     }     long long ret = 0;     for (int i = 0; i < (n); ++i) {       if (ans[i] < s[i]) {         cout << -1 <<   n ;         return;       }       ret += ans[i] - s[i];     }     cout << ret <<   n ;     for (int i = 0; i < (n); ++i) cout << ans[i] <<    ;     cout <<   n ;   }   void init() {}   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     init();     int TC = 1;     for (int TI = 1; TI <= (TC); ++TI) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   const int N = 1000005;   long long frac[N + 5], inv[N + 5];   int n, a[N], y[N], Max;   long long ans;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   long long power(long long a, long long b) {     long long res = 1;     for (; b; b >>= 1) {       if (b & 1) res = res * a % Mod;       a = a * a % Mod;     }     return res;   }   long long C(int m, int n) { return frac[n] * inv[m] % Mod * inv[n - m] % Mod; }   int main() {     n = read();     frac[1] = 1;     frac[0] = 1;     for (int i = 2; i <= n + 2; i++) frac[i] = frac[i - 1] * i % Mod;     inv[n + 2] = power(frac[n + 2], Mod - 2);     for (int i = n + 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % Mod;     inv[0] = 1;     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + n + 1);     a[0] = -1;     for (int i = 1; i <= n; i++) {       Max = max(Max, a[i]);       if (a[i] == a[i - 1]) {         y[i] = y[i - 1];         continue;       }       for (int j = i; j >= 0; j--) {         if (a[j] != a[i]) {           y[i] = n - j;           break;         }       }       --y[i];     }     for (int i = 1; i <= n; i++) {       if (a[i] == Max) continue;       ans = (ans + (a[i] * frac[y[i]] % Mod * frac[n - y[i] - 1] % Mod *                     C(y[i] + 1, n) % Mod)) %             Mod;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int blacks(int *pos, int n);   int whites(int *pos, int n);   int main() {     int n;     cin >> n;     int board[100];     for (int i = 0; i < n; i++) {       board[i] = 0;     }     for (int i = 0; i < n / 2; i++) {       int temp;       cin >> temp;       board[temp - 1] = 1;     }     cout << min(blacks(board, n), whites(board, n));   }   int blacks(int *pos, int n) {     int i = 0;     int label = 0;     int result = 0;     while (i < n) {       if (pos[i] == 1) {         result += abs(i - label);         label += 2;       }       i++;     }     return result;   }   int whites(int *pos, int n) {     int i = 0;     int label = 1;     int result = 0;     while (i < n) {       if (pos[i] == 1) {         result += abs(i - label);         label += 2;       }       i++;     }     return result;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int i, n, f = 0;       cin >> n;       vector<int> v(n);       vector<int> use(n + 1, 0);       for (i = 0; i < n; i++) {         cin >> v[i];         if (v[i] < (i + 1)) {           f = 1;         }       }       if (f) {         cout <<  -1  << endl;         continue;       }       vector<int> a(n, 0);       for (i = 0; i < n; i++) {         if (!use[v[i]]) {           a[i] = v[i];           use[v[i]] = 1;         }       }       queue<int> q;       for (i = 1; i <= n; i++) {         if (!use[i]) {           q.push(i);         }       }       for (i = 0; i < n; i++) {         if (a[i] != 0) {           cout << a[i] <<    ;         } else {           cout << q.front() <<    ;           q.pop();         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1), eps = 1e-6;   const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};   const int N = 1e6 + 5, M = 2e6 + 5, mod = 1e9 + 7;   int n;   int p[N], c[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n;       bool success = true;       for (int i = 1, d = 0; i <= n; i++) {         cin >> p[i] >> c[i];         if (p[i] < c[i] || p[i] < p[i - 1] || c[i] < c[i - 1] || p[i] - c[i] < d)           success = false;         d = p[i] - c[i];       }       cout << (success ?  YES  :  NO ) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 2e5 + 100;   int n, val[maxn];   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , val + i);     set<int> s;     for (int i = 0; i < n; i++) s.insert((((i + val[i]) % n) + n) % n);     puts((s.size() == n) ?  YES  :  NO );   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[2][2];   string s;   int main() {     ios_base::sync_with_stdio(0);     cin >> s;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         cnt[i][j] = 0;       }     }     for (int i = 0; i < s.length(); i++) {       cnt[i & 1][s[i] -  a ]++;     }     long long ans = 0;     for (int i = 0; i < 2; i++) {       ans += (long long)cnt[0][i] * cnt[1][i];     }     cout << ans <<    ;     ans = 0;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         ans += (long long)cnt[i][j] * (cnt[i][j] + 1) / 2;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const double pi = 3.14159265358979323846;   const long long mxN = 2e5 + 2;   void _print(long long t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(double t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   vector<long long> adj[27];   long long degree[27];   bool visited[27];   vector<long long> hold;   void dfs(long long src) {     visited[src] = true;     hold.push_back(src);     for (auto edge : adj[src]) {       if (!visited[edge]) dfs(edge);     }   }   void solve() {     string s;     cin >> s;     long long n = s.length();     memset(degree, 0, sizeof(degree));     memset(visited, false, sizeof(visited));     hold.clear();     vector<vector<long long>> hehe(26, vector<long long>(26, 0));     for (long long i = 0; i <= 25; i++) adj[i].clear();     for (long long i = 0; i < n - 1; i++) {       if (s[i] != s[i + 1] && hehe[s[i] -  a ][s[i + 1] -  a ] == 0) {         adj[s[i] -  a ].push_back(s[i + 1] -  a );         adj[s[i + 1] -  a ].push_back(s[i] -  a );         hehe[s[i] -  a ][s[i + 1] -  a ] = 1;         hehe[s[i + 1] -  a ][s[i] -  a ] = 1;         degree[s[i + 1] -  a ]++;         degree[s[i] -  a ]++;       }     }     long long onecount = 0;     long long pos = -1;     if (n == 1) pos = s[0] -  a ;     for (long long i = 0; i <= 25; i++) {       if (degree[i] > 2) {         cout <<  NO n ;         return;       }       if (degree[i] == 1) {         onecount++;         pos = i;       }     }     if (n != 1 && onecount != 2) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     dfs(pos);     for (long long i = 0; i < 26; i++) {       if (!visited[i]) hold.push_back(i);     }     for (auto x : hold) cout << char(x +  a );     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long T = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1024;   int size[MAXN], in[MAXN], deg[MAXN];   bitset<MAXN> a[MAXN], c;   vector<pair<int, int> > edges;   set<pair<int, int> > was;   int main() {     int n;     scanf( %d , &n);     bool star = 1;     for (int i = 0; (i) < (n); ++i) {       scanf( %d , &size[i]);       if (size[i] != n) star = 0;       for (int j = 0; (j) < (size[i]); ++j) {         int l;         scanf( %d , &l);         a[i][l - 1] = 1;       }     }     if (star) {       for (int i = 0; (i) < (n - 1); ++i) printf( %d %d n , i + 1, n);       return 0;     }     for (int i = 0; (i) < (n); ++i)       for (int j = (i + 1); (j) < (n); ++j) {         c = a[i] & a[j];         unsigned int *cur = (unsigned int *)&c;         vector<int> v;         for (int g = 0; (g) < (MAXN / 32); ++g) {           if (*cur != 0) {             for (int k = (32) - 1; (k) >= 0; --k)               if (((*cur) >> k) & 1) v.push_back(g * 32 + k);             if ((int)((v).size()) > 2) break;           }           cur++;         }         if ((int)((v).size()) == 2) edges.push_back(make_pair(v[0], v[1]));       }     sort((edges).begin(), (edges).end());     edges.resize(unique((edges).begin(), (edges).end()) - edges.begin());     for (auto edge : edges) {       in[edge.first] = in[edge.second] = 1;       deg[edge.first]++, deg[edge.second]++;       was.insert(make_pair(edge.first, edge.second));       was.insert(make_pair(edge.second, edge.first));     }     for (int i = 0; (i) < (n); ++i)       if (!in[i]) {         int minn = 2 * n, ind = -1;         for (int j = 0; (j) < (n); ++j)           if (a[j][i] == 1 && size[j] < minn) {             minn = min(minn, size[j]);             ind = j;           }         assert(ind != -1);         vector<int> vIn;         for (int j = 0; (j) < (n); ++j)           if (a[ind][j] && in[j]) vIn.push_back(j);         if ((int)((vIn).size()) > 2) {           for (int j = 0; (j) < ((int)((vIn).size())); ++j) {             bool ok = 1;             for (int g = 0; (g) < ((int)((vIn).size())); ++g) {               if (g != j && !was.count(make_pair(vIn[j], vIn[g]))) {                 ok = 0;                 break;               }             }             if (ok) {               edges.push_back(make_pair(vIn[j], i));               break;             }           }         } else {           assert((int)((vIn).size()) == 2);           assert(deg[vIn[0]] == 1 || deg[vIn[1]] == 1);           if (deg[vIn[0]] == 1 && deg[vIn[1]] == 1) {             int ind2 = -1;             for (int j = 0; (j) < (n); ++j)               if (size[j] != n) {                 ind2 = j;                 break;               }             assert(ind != -1);             if (a[ind2] == a[ind])               edges.push_back(make_pair(vIn[0], i));             else               edges.push_back(make_pair(vIn[1], i));           } else {             for (int j = 0; (j) < (2); ++j)               if (deg[vIn[j]] == 1) edges.push_back(make_pair(vIn[j], i));           }         }       }     for (auto edge : edges) printf( %d %d n , edge.first + 1, edge.second + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double PI = acos(-1);   const long long mod = 1e9 + 7;   const long long OO = 2e18;   const int N = 3e5 + 5;   int parent[N];   set<int> st;   set<int>::iterator it1, it2;   int n, m, l, r, x;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) st.insert(i);     st.insert(oo);     while (m--) {       cin >> l >> r >> x;       it1 = st.lower_bound(l);       while (*it1 <= r) {         if (*it1 != x) {           parent[*it1] = x;           it2 = it1;           it1++;           st.erase(it2);         } else           it1++;       }     }     for (int i = 1; i <= n; i++) {       cout << parent[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool dp[1001][1001];   int data[1001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     if (n > m) {       cout <<  YES             <<   n ;       return 0;     } else {       for (int i = 1; i <= n; i++) {         cin >> data[i], data[i] %= m;         if (!data[i]) {           cout <<  YES                 <<   n ;           return 0;         }       }       dp[0][0] = true;       for (int i = 1; i <= n; i++) {         for (int j = 0; j <= m; j++) {           dp[i][j] = dp[i - 1][j];           int var = j - data[i];           if (var < 0) var += m;           dp[i][j] |= dp[i - 1][var];         }         if (dp[i][m]) {           cout <<  YES                 <<   n ;           return 0;         }       }     }     cout <<  NO           <<   n ;     return 0;   }