malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int n1, n2, n3;     cin >> n1 >> n2 >> n3;     vector<int> v[n + 1];     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     auto out = []() {       cout <<  NO n ;       exit(0);     };     if (n2 == 0) {       if (m == 0) {         cout <<  YES n ;         cout << string(n1,  1 ) + string(n3,  3 ) <<   n ;         exit(0);       } else         out();     }     vector<int> vis(n + 1, 0);     vector<vector<int>> one;     vector<vector<int>> two;     vector<vector<array<int, 2>>> dp(n + 1, vector<array<int, 2>>(n + 1, {0, 0}));     dp[0][0] = {-1, 1};     int comp = 0;     for (int i = 1; i <= n; i++) {       if (vis[i] != 0) continue;       comp++;       queue<int> q;       q.push(i);       vis[i] = 1;       vector<int> d[3];       vector<int> cnt(3, 0);       d[1].push_back(i);       cnt[1] = 1;       while (!q.empty()) {         int x = q.front();         q.pop();         for (int to : v[x]) {           if (vis[to] == 0) {             q.push(to);             vis[to] = 3 - vis[x];             d[vis[to]].push_back(to);             cnt[vis[to]]++;           } else if (vis[to] == vis[x])             out();         }       }       one.push_back(d[1]);       two.push_back(d[2]);       for (int j = 0; j <= n; j++) {         if (dp[comp - 1][j][1] == 0) continue;         for (int k = 1; k <= 2; k++)           if (dp[comp][j + cnt[k]][1] == 0)             dp[comp][j + cnt[k]] = {(int)one.size() - 1, k};       }     }     if (dp[comp][n2][1] == 0) out();     string res(n + 1,  0 );     int c = comp;     int now = n2;     while (now > 0) {       if (dp[c][now][1] == 1) {         for (int x : one[dp[c][now][0]]) res[x] =  2 ;         now -= one[dp[c][now][0]].size();       } else {         for (int x : two[dp[c][now][0]]) res[x] =  2 ;         now -= two[dp[c][now][0]].size();       }       c--;     }     for (int i = 1; i <= n; i++) {       if (res[i] ==  2 ) continue;       if (n1 > 0) {         res[i] =  1 ;         n1--;       } else         res[i] =  3 ;     }     cout <<  YES n ;     cout << res.substr(1, n) <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   using namespace std;   inline int read() {     int x = 0, neg = 1;     char op = getchar();     while (!isdigit(op)) {       if (op ==  - ) neg = -1;       op = getchar();     }     while (isdigit(op)) {       x = 10 * x + op -  0 ;       op = getchar();     }     return neg * x;   }   inline void print(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1000005;   long long f[N], g[N];   int k, q, mul = 1;   void ckmax(long long &a, long long b) {     if (a < b) a = b;   }   void work() {     int tmp = k, t = 1, x;     x = read();     memset(g, 192, sizeof(g));     for (int v = 0; v < 10; v++) {       long long cost = 1ll * mul * v;       long long w = v % 3 == 0 ? 1ll * (v / 3) * x : 0;       for (int i = 0; i < N - cost; i++) {         ckmax(g[i + cost], f[i] + w);       }     }     memcpy(f, g, sizeof(g));     while (tmp > t) {       tmp -= t;       long long cost = 1ll * mul * t;       cost *= 3;       long long w = 1ll * x * t;       if (cost < N) {         for (int i = N - 1; i >= cost; i--) {           ckmax(f[i], f[i - cost] + w);         }       }       t <<= 1;     }     long long cost = 1ll * mul * tmp;     cost *= 3;     long long w = 1ll * x * tmp;     if (cost < N) {       for (int i = N - 1; i >= cost; i--) {         ckmax(f[i], f[i - cost] + w);       }     }     mul *= 10;   }   int main() {     k = (read() - 1) * 3;     memset(f, 192, sizeof(f)), f[0] = 0;     for (int i = 1; i <= 6; i++) work();     q = read();     while (q--) {       int x = read();       printf( %lld n , f[x]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef pair<long long, long long> pii;   typedef vector<long long> vi;   typedef vector<pii> vpii;   typedef vector<vi> vvi;   double prob[20][20];   double dp[(1 << 19)];   double pmove(long long prev_mask, long long j, long long n) {     long long k = __builtin_popcount(prev_mask);     long long den = k * (k - 1) / 2;     double moveprob = 0;     for (long long i = (0); i < (n); i += 1) {       if ((1 << i) & prev_mask) {         moveprob += prob[i][j];       }     }     return moveprob / (1.0 * den);   }   double get_ans(long long mask, long long n) {     long long alive = __builtin_popcount(mask);     if (alive == n) return 1;     if (dp[mask] > -0.9) return dp[mask];     double ans = 0;     for (long long i = (0); i < (n); i += 1) {       if (!(mask & (1 << i))) {         long long prev_mask = mask ^ (1 << i);         ans += get_ans(prev_mask, n) * pmove(prev_mask, i, n);       }     }     return dp[mask] = ans;   }   void solve() {     long long n;     cin >> n;     memset(dp, -1, sizeof dp);     for (long long i = (0); i < (n); i += 1)       for (long long j = (0); j < (n); j += 1) cin >> prob[i][j];     for (long long i = (0); i < (n); i += 1) {       printf( %.6lf  , get_ans((1 << i), n));     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9;   int n, q;   int a[400005];   struct rmq {     int tree[1050000], lim;     void init(int n) {       memset(tree, 0, sizeof(tree));       for (lim = 1; lim <= n; lim <<= 1)         ;     }     void add(int x, int v) {       x += lim;       tree[x] = max(tree[x], v);       while (x > 1) {         x >>= 1;         tree[x] = max(tree[2 * x], tree[2 * x + 1]);       }     }     int query(int s, int e) {       s += lim;       e += lim;       int ret = 0;       while (s < e) {         if (s % 2 == 1) ret = max(ret, tree[s++]);         if (e % 2 == 0) ret = max(ret, tree[e--]);         s >>= 1;         e >>= 1;       }       if (s == e) ret = max(ret, tree[s]);       return ret;     }   } rmq;   int dpl[400005], dpr[400005], lis;   int cnt[400005];   bool check_indep(int x) {     return cnt[dpr[x]] != 1 || dpl[x] + dpr[x] != lis + 1;   }   int is_indep[400005];   int aux[400005], ret[400005];   struct query {     int x, y, idx;     bool operator<(const query &q) const { return x < q.x; }   };   int main() {     scanf( %d %d , &n, &q);     vector<int> v;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       v.push_back(a[i]);     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     for (int i = 1; i <= n; i++) {       a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;     }     rmq.init(n);     for (int i = 1; i <= n; i++) {       dpl[i] = rmq.query(1, a[i] - 1) + 1;       rmq.add(a[i], dpl[i]);     }     rmq.init(n);     for (int i = n; i; i--) {       dpr[i] = rmq.query(a[i] + 1, n) + 1;       rmq.add(a[i], dpr[i]);     }     for (int i = 1; i <= n; i++) {       lis = max(lis, dpl[i]);     }     for (int i = 1; i <= n; i++) {       if (dpl[i] + dpr[i] == lis + 1) {         cnt[dpr[i]]++;       }     }     for (int i = 1; i <= n; i++) {       is_indep[i] = check_indep(i);     }     vector<query> qr;     for (int i = 0; i < q; i++) {       int x, y;       scanf( %d %d , &x, &y);       if (is_indep[x]) {         ret[i] = lis;       } else         ret[i] = lis - 1;       qr.push_back({x, y, i});     }     sort(qr.begin(), qr.end());     rmq.init(n);     int pnt = 1;     for (int i = 0; i < q; i++) {       while (pnt <= n && pnt < qr[i].x) {         rmq.add(a[pnt], dpl[pnt]);         pnt++;       }       int sy = lower_bound(v.begin(), v.end(), qr[i].y) - v.begin();       aux[qr[i].idx] += rmq.query(1, sy);     }     pnt = n;     rmq.init(n);     for (int i = q - 1; i >= 0; i--) {       while (pnt && pnt > qr[i].x) {         rmq.add(a[pnt], dpr[pnt]);         pnt--;       }       int ey = upper_bound(v.begin(), v.end(), qr[i].y) - v.begin() + 1;       aux[qr[i].idx] += rmq.query(ey, n);     }     for (int i = 0; i < q; i++) {       ret[i] = max(ret[i], aux[i] + 1);       printf( %d n , ret[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int n0 = 1 << 17;   const long long inf = 1e18;   int n, a[n0], q;   long long d[n0], gaps;   struct Node {     int l = 0, r = 0;     long long val[3];     Node() { val[0] = val[1] = val[2] = -inf; }     void init(int pos) {       l = r = pos;       if (l < 2 || l > n - 1) {         val[0] = val[1] = val[2] = -inf;         return;       }       long long d1 = d[l - 1], d2 = d[l];       long long t = -abs(d1) - abs(d2);       val[0] = d1 - d2 + t;       val[1] = max(d1 + d2, -d1 - d2) + t;       val[2] = -d1 + d2 + t;     }     void merge(Node &x, Node &y) {       if (!x.l) {         x = y;         return;       }       l = x.l, r = y.r;       for (int i = 0; i < 3; i++) val[i] = max(x.val[i], y.val[i]);     }     long long get(long long x) {       return max({-2 * x + val[0], val[1], 2 * x + val[2]});     }   };   struct Segtree {     Node t[n0 << 1];     void build() {       for (int i = (n0 << 1) - 1; i > 0; i--) {         if (i >= n0)           t[i].init(i - n0);         else           t[i].merge(t[i << 1], t[i << 1 | 1]);       }     }     void upd(int x) {       t[x + n0].init(x);       for (x += n0; x > 1; x /= 2) t[x >> 1].merge(t[x], t[x ^ 1]);     }     Node get(int l, int r) {       r++;       Node res;       for (l += n0, r += n0; l < r; l /= 2, r /= 2) {         if (l & 1) res.merge(res, t[l++]);         if (r & 1) res.merge(res, t[--r]);       }       return res;     }   };   Segtree st;   void upd(int x, int y) {     gaps -= abs(d[x]);     d[x] += y;     gaps += abs(d[x]);     st.upd(x), st.upd(x + 1);   }   long long get(int l, int r, long long x) {     long long res = st.get(l, r).get(x);     if (l == 1) res = max(res, abs(d[1] + x) - abs(d[1]));     if (r == n) res = max(res, abs(d[n - 1] - x) - abs(d[n - 1]));     return gaps + res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) d[i] = a[i] - a[i + 1], gaps += abs(d[i]);     st.build();     cin >> q;     while (q--) {       int t, l, r, x;       cin >> t >> l >> r >> x;       if (t == 1) {         cout << get(l, r, x) <<   n ;       } else {         upd(l - 1, -x), upd(r, x);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const int mod = 1000000007;   const int MAXN = 1010;   int n, m, t, x, y, xx, yy, ans, v, u, q, a, b, c, cnt;   string A[MAXN];   int dist[MAXN][MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> A[i];       A[i] =  .  + A[i];       for (int j = 1; j <= m; j++) {         if (A[i][j] ==  S ) {           xx = i;           yy = j;         }         if (A[i][j] ==  E ) {           x = i;           y = j;         }       }     }     queue<pair<int, int> > q;     q.push({x, y});     memset(dist, 63, sizeof(dist));     dist[x][y] = 0;     while (!q.empty()) {       int x = q.front().first, y = q.front().second;       q.pop();       if (dist[x][y] > dist[xx][yy]) break;       if (x < 1 || y < 1 || x > n || y > m || A[x][y] ==  T ) continue;       if (dist[x][y] + 1 < dist[x + 1][y]) {         dist[x + 1][y] = dist[x][y] + 1;         q.push({x + 1, y});       }       if (dist[x][y] + 1 < dist[x][y + 1]) {         dist[x][y + 1] = dist[x][y] + 1;         q.push({x, y + 1});       }       if (dist[x][y] + 1 < dist[x - 1][y]) {         dist[x - 1][y] = dist[x][y] + 1;         q.push({x - 1, y});       }       if (dist[x][y] + 1 < dist[x][y - 1]) {         dist[x][y - 1] = dist[x][y] + 1;         q.push({x, y - 1});       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (A[i][j] ==  S  || A[i][j] ==  E  || A[i][j] ==  T ) continue;         if (dist[i][j] <= dist[xx][yy]) ans += A[i][j] -  0 ;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxt = 1000000, maxn = maxt + 7;   int h[7][7];   char s[5][maxn];   void output(int n) {     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= n; j++) printf( %c , s[i][j]);       puts(  );     }   }   bool DoIt_2(int I, int n, int tot) {     for (int i = 1; i <= n; i++)       if (s[2][i] != s[I][i]) tot--;     if (tot < 0) return false;     if (tot == 0) return true;     if (tot % 2 == 1) return false;     vector<int> A, B;     A.clear(), B.clear();     for (int i = 1; i <= n; i++)       if (s[2][i] == s[I][i]) {         if (s[2][i] ==  a ) A.push_back(i);         if (s[2][i] ==  b ) B.push_back(i);       }     for (int i = 0; i < min(A.size(), B.size()); i++) {       int x = A[i], y = B[i];       tot -= 2;       swap(s[I][x], s[I][y]);       if (tot == 0) return true;     }     return false;   }   bool DoIt_3(int I, int n, int tot) {     for (int i = 1; i <= n; i++)       if (s[3][i] != s[I][i]) tot--;     if (tot < 0) return false;     if (tot == 0) return true;     if (tot % 2 == 1) return false;     vector<int> AA, AB, BA, BB;     AA.clear(), AB.clear(), BA.clear(), BB.clear();     for (int i = 1; i <= n; i++)       if (s[3][i] == s[I][i]) {         if (s[2][i] ==  a  && s[3][i] ==  a ) AA.push_back(i);         if (s[2][i] ==  a  && s[3][i] ==  b ) AB.push_back(i);         if (s[2][i] ==  b  && s[3][i] ==  a ) BA.push_back(i);         if (s[2][i] ==  b  && s[3][i] ==  b ) BB.push_back(i);       }     for (int i = 0; i < min(AA.size(), AB.size()); i++) {       int x = AA[i], y = AB[i];       tot -= 2;       swap(s[I][x], s[I][y]);       if (tot == 0) return true;     }     for (int i = 0; i < min(BA.size(), BB.size()); i++) {       int x = BA[i], y = BB[i];       tot -= 2;       swap(s[I][x], s[I][y]);       if (tot == 0) return true;     }     return false;   }   bool check(int n) {     for (int i = 1; i <= 4; i++)       for (int j = 1; j <= n; j++) s[i][j] =  a ;     for (int i = 2; i <= 4; i++)       for (int j = 1; j <= h[1][i]; j++) s[i][j] =  b ;     for (int i = 3; i <= 4; i++)       if (!DoIt_2(i, n, h[2][i])) return false;     if (!DoIt_3(4, n, h[3][4])) return false;     return true;   }   int main() {     for (int i = 1; i <= 4; i++)       for (int j = i + 1; j <= 4; j++) scanf( %d , &h[i][j]);     int head = 1, tail = maxt;     while (head <= tail) {       int mid = (head + tail) / 2;       if (check(mid))         tail = mid - 1;       else         head = mid + 1;     }     int n = tail + 1;     if (n > maxt) {       puts( -1 );       return 0;     }     printf( %d n , n);     check(n);     output(n);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   map<pair<int, long long>, bool> vis;   map<pair<int, long long>, int> memo;   int grundy(int x, long long mask) {     for (int i = 61; i > x; i--) {       if ((mask >> i) & 1) mask ^= (1ll << i);     }     if (vis[{x, mask}]) return memo[{x, mask}];     vis[{x, mask}] = 1;     set<int> s;     for (int i = 1; i <= x; i++) {       if ((mask >> i) & 1) {         s.insert(grundy(x - i, mask ^ (1ll << i)));       }     }     int res = 0;     while (s.find(res) != s.end()) res++;     return memo[{x, mask}] = res;   }   int n;   int s[MAXN];   int main() {     scanf( %d , &n);     int res = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , s + i);       res ^= grundy(s[i], (1ll << 61) - 1);     }     if (res)       puts( NO );     else       puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int div[] = {1, 2, 3, 4, 6, 12};     while (t--) {       string s;       cin >> s;       vector<pair<int, int> > dimen;       int n, m;       int i, j, k;       for (k = 0; k < 6; k++) {         n = div[k];         m = 12 / n;         for (j = 0; j < m; j++) {           for (i = 0; i < n; i++) {             if (s[i * m + j] !=  X ) break;           }           if (i == n) {             dimen.push_back(make_pair(n, m));             break;           }         }       }       cout << dimen.size() <<    ;       for (int i = 0; i < dimen.size(); i++)         cout << dimen[i].first <<  x  << dimen[i].second <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string gen[100];   string merge(string s1, string s2) {     int e = s1.size() - 1;     for (int i = 0; i < s2.size(); i++) {       if (s1[0] == s2[i]) {         int k = s2.size() - i;         if (k <= s1.size()) {           s1.erase(0, k);           return s2 + s1;         }         return s2;       }       if (s1[e] == s2[i]) {         if (e - i >= 0) {           s1.erase(e - i, i + 1);           return s1 + s2;         }         return s2;       }     }     return  0 ;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> gen[i];     }     bool f = true;     for (int k = 0; k < n; k++) {       f = true;       while (f && gen[k] !=   ) {         f = false;         for (int i = k + 1; i < n; i++) {           if (gen[i] !=   ) {             string s;             if (gen[i].length() < gen[k].length()) {               s = merge(gen[i], gen[k]);             } else {               s = merge(gen[k], gen[i]);             }             if (s !=  0 ) {               gen[k] = s;               gen[i] =   ;               f = true;               break;             }           }         }       }     }     string s3;     for (int i = 0; i < n; i++) {       s3 += gen[i];     }     cout << s3;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> frequency(vector<long long> v) {     map<long long, long long> m;     for (long long i = 0; i < v.size(); i++) {       if (m.find(v[i]) != m.end())         m[v[i]]++;       else {         m.insert({v[i], 1});       }     }     return m;   }   void input(vector<long long>& v, long long n) {     for (long long i = 0; i < (long long)(n); i++) {       long long in;       cin >> in;       v.push_back(in);     }   }   void output(vector<long long> v) {     for (long long i = 0; i < (long long)(v.size()); i++) cout << v[i] <<    ;   }   void solve() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long m = max((3 * a) / 10, a - (a / 250) * c);     long long v = max((3 * b) / 10, b - (b / 250) * d);     if (m > v) {       cout <<  Misha  << endl;     } else if (v > m) {       cout <<  Vasya  << endl;     } else {       cout <<  Tie  << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, i, m, x, s = 0;       cin >> n >> m;       for (i = 1; i <= n; i++) {         cin >> x;         s += x;       }       if (s == m)         cout <<  YES ;       else         cout <<  NO ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long bl_size = 320;   int n, m;   long long k;   long long res;   long long a[100005];   unordered_map<long long, long long> cnt;   struct Query {     int l, r, id;     bool operator<(Query other) const {       if (l / bl_size != other.l / bl_size)         return l < other.l;       else         return (l / bl_size & 1) ? (r < other.r) : (r > other.r);     }   };   void add(long long x) {     long long y = x ^ k;     res += cnt[y];     cnt[x]++;   }   void rem(long long x) {     long long y = x ^ k;     if (y != x)       res -= (cnt[y]);     else       res -= (cnt[y] - 1);     cnt[x]--;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     scanf( %d%d%d , &n, &m, &k);     long long prev[n + 10];     prev[0] = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), prev[i] = prev[i - 1] ^ a[i];     Query q[100005];     for (int i = 1; i <= m; i++) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].l--;       q[i].id = i;     }     sort(q + 1, q + n + 1);     res = 0;     long long ans[m + 10];     int cur_l = 0, cur_r = -1;     for (int i = 1; i <= m; i++) {       while (cur_l > q[i].l) {         cur_l--;         add(prev[cur_l]);       }       while (cur_l < q[i].l) {         rem(prev[cur_l]);         cur_l++;       }       while (cur_r > q[i].r) {         rem(prev[cur_r]);         cur_r--;       }       while (cur_r < q[i].r) {         cur_r++;         add(prev[cur_r]);       }       ans[q[i].id] = res;     }     for (int i = 1; i <= m; i++) cout << ans[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e5 + 10;   const int LG = 20;   int power(int a, int b) {     int res = 1;     while (b > 0) {       if (b & 1) {         res = 1LL * res * a % mod;       }       a = 1LL * a * a % mod;       b >>= 1;     }     return res;   }   int seg[4 * N], lazy[4 * N];   void update(int node, int start, int end, int l, int r, int val) {     if (lazy[node]) {       seg[node] += lazy[node];       if (start != end) {         lazy[node << 1] += lazy[node];         lazy[node << 1 | 1] += lazy[node];       }       lazy[node] = 0;     }     if (start > end || r < start || end < l) return;     if (l <= start && end <= r) {       seg[node] += val;       if (start != end) {         lazy[node << 1] += val;         lazy[node << 1 | 1] += val;       }       return;     }     int mid = (start + end) >> 1;     update(node << 1, start, mid, l, r, val);     update(node << 1 | 1, mid + 1, end, l, r, val);     seg[node] = min(seg[node << 1], seg[node << 1 | 1]);   }   int query(int node, int start, int end, int l, int r) {     if (lazy[node]) {       seg[node] += lazy[node];       if (start != end) {         lazy[node << 1] += lazy[node];         lazy[node << 1 | 1] += lazy[node];       }       lazy[node] = 0;     }     if (start > end || r < start || end < l) return 1e9;     if (l <= start && end <= r) {       return seg[node];     }     int mid = (start + end) >> 1;     return min(query(node << 1, start, mid, l, r),                query(node << 1 | 1, mid + 1, end, l, r));   }   int main() {     int n, m, a[N], ans = 0, idx = 0;     vector<pair<int, int> > lft[N], rght[N];     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       update(1, 1, n, i, i, a[i]);     }     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d %d , &l, &r);       lft[r].push_back({l, i});       rght[l].push_back({r, i});     }     for (int i = 1; i <= n; i++) {       int val = a[i] - query(1, 1, n, 1, i - 1);       if (val > ans) {         idx = i;         ans = val;       }       for (auto l : lft[i]) {         update(1, 1, n, l.first, i, -1);       }     }     memset(seg, 0, sizeof(seg));     memset(lazy, 0, sizeof(lazy));     for (int i = 1; i <= n; i++) {       update(1, 1, n, i, i, a[i]);     }     for (int i = n; i >= 1; i--) {       int val = a[i] - query(1, 1, n, i + 1, n);       if (val > ans) {         idx = -i;         ans = val;       }       for (auto r : rght[i]) {         update(1, 1, n, i, r.first, -1);       }     }     printf( %d n , ans);     vector<int> res;     if (idx > 0) {       for (int i = 1; i < idx; i++) {         for (auto j : lft[i]) {           res.push_back(j.second);         }       }     } else if (idx < 0) {       for (int i = n; i > abs(idx); i--) {         for (auto j : rght[i]) {           res.push_back(j.second);         }       }     }     printf( %d n , res.size());     for (int pp : res) {       printf( %d  , pp);     }     return 0;   }