malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int firstt(int* a, int n) {     long long l, r, s;     for (int i = 0; i <= n - 1; ++i) {       l = 0;       r = 10000000000;       while (l < r - 1) {         s = (-l + r) / 2 + l;         if (s * n >= a[i] - i) {           r = s;         } else {           l = s;         }       }       if (l * n >= a[i] - i) {         a[i] = l;       } else {         a[i] = l + 1;       }     }     l = 0;     int minn = a[0];     for (int i = 1; i <= n - 1; ++i) {       if (a[i] < minn) {         minn = a[i];         l = i;       }     }     return (l + 1);   }   int main() {     int n, i;     cin >> n;     int* a = new int[n];     for (i = 0; i <= n - 1; ++i) {       cin >> a[i];     }     long long res = firstt(a, n);     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > V(7);   vector<vector<string> > S(7);   set<string> SS;   int n, m;   void DFS(int node, string T) {     if (T.length() == n) {       SS.insert(T);       return;     }     for (int i = 0; i < S[node].size(); i++) {       string R = S[node][i];       string E;       E += R[1];       if (T.length() + 2 == n) {         DFS(0, T + R);       } else         DFS(R[0] -  a , T + E);     }   }   int main() {     cin >> n >> m;     string y;     char C;     char A[m];     for (int i = 0; i < m; i++) {       cin >> y >> C;       A[i] = C;       S[C -  a ].push_back(y);     }     for (int i = 0; i < m; i++) {       if (A[i] ==  a ) {         DFS(A[i] -  a ,   );       }     }     cout << SS.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 5e5 + 5;   struct Node {     long long t, h, m;   } a[MAXN];   bool cmp(Node x, Node y) { return x.m > y.m; }   long long n, x;   long long vis[MAXN];   long long solve(long long now) {     memset(vis, 0, sizeof(vis));     long long ans = 0;     long long h = x;     while (1) {       long long f = 0;       for (long long i = 1; i <= n; i++) {         if (vis[i] == 0 && now != a[i].t && h >= a[i].h) {           f = 1;           now = 1 - now;           vis[i] = 1;           ans++;           h += a[i].m;           break;         }       }       if (f == 0) {         break;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> x;     for (long long i = 1; i <= n; i++) {       cin >> a[i].t >> a[i].h >> a[i].m;     }     sort(a + 1, a + n + 1, cmp);     long long ans = max(solve(1), solve(0));     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, perm[305], m[305][305];     char s[305];     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &perm[i]);     }     memset(m, 0, sizeof(m));     for (int i = 0; i < n; i++) {       scanf( %s , s);       for (int j = 0; j < n; j++) {         if (s[j] ==  1 ) {           m[i][j] = 1;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (m[i][j] == 1) {           for (int a = 0; a < n; a++) {             if (m[i][a] == 1 || m[j][a] == 1 || m[a][i] == 1 || m[a][j] == 1) {               m[i][a] = 1;               m[j][a] = 1;               m[a][i] = 1;               m[a][j] = 1;             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (m[i][j] && perm[j] < perm[i]) {           swap(perm[j], perm[i]);         }       }     }     for (int i = 0; i < n; i++) {       if (i != 0) {         printf(   );       }       printf( %d , perm[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define ll long long int   #define pb push_back   #define mp make_pair   #define deb(x) cout<< #x <<     << x <<   n ;   #define MAX 9223372036854775807   #define MIN -9223372036854775807   #define PI 3.141592653589   #define setbits(n) __builtin_popcountll(n)   #define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());   const ll mod=998244353;            int main() {              ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);       ll T=clock();          ll t;       cin>>t;       while(t--){           ll n,m;           cin>>n>>m;           vector<vector<ll>> a(n,vector<ll>(m));           vector<ll> p(n+m);           for(ll i=0;i<n;i++){               for(ll j=0;j<m;j++){                   cin>>a[i][j];                   p[i+j]^=a[i][j];               }           }           bool ok=false;           for(ll i=0;i<n+m;i++)               if(p[i]!=0)                   ok=true;           if(ok)               cout<< Ashish n ;           else               cout<< Jeel n ;       }                cerr<<  n nTIME:  <<(double)(clock()-T)/CLOCKS_PER_SEC<<  sec n ;       T = clock();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q;   int n;   int nav[200005], pos[200005];   int main() {     scanf( %d , &q);     while (q--) {       int men = 999999, lar = 999999;       scanf( %d , &n);       int a;       for (int i = 0; i < n; i++) {         scanf( %d , &a);         if (nav[a] == 0) nav[a] = 1, pos[a] = i;         if (nav[a] == 1) lar = i - pos[a], pos[a] = i;         if (lar < men && lar != 0) men = lar;       }       printf( %d n , men == 999999 ? -1 : men + 1);       for (int i = 0; i < 200001; i++) nav[i] = pos[i] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3;   int main() {     int n;     cin >> n;     for (int i = 1; i < N; i++)       if (i * (i + 1) <= 2 * n && (i + 2) * (i + 1) > 2 * n) {         cout << i << endl;         for (int j = 1; j < i; j++) cout << j <<    ;         cout << n - (i - 1) * i / 2;         return 0;       }   }
#include <bits/stdc++.h>   using namespace std;   int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};   int ans[505][505];   int col = 1, n, coz = 0;   int main() {     std::ios::sync_with_stdio(false);     scanf( %d , &n);     if (n < 3) {       printf( -1 );       return 0;     }     int now_ = 0, cot = n;     int x = 1, y = 0;     int rest = n * n;     while (rest != 9) {       for (int i = 1; i <= cot; i++) {         coz++;         x += dir[now_][0];         y += dir[now_][1];         ans[x][y] = coz;       }       rest -= cot;       col++;       if (col % 2 == 0) cot--;       now_ = (now_ + 1) % 4;     }     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 1;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 2;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 4;     now_ = (now_ + 1) % 4;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 5;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 9;     now_ = (now_ + 1) % 4;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 6;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 7;     now_ = (now_ + 1) % 4;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 8;     now_ = (now_ + 1) % 4;     x += dir[now_][0];     y += dir[now_][1];     ans[x][y] = coz + 3;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) printf( %d  , ans[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tf = 0, f = 0, hun = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 25)         tf++;       else if (a[i] == 50) {         f++;         tf--;       } else {         hun++;         if (f >= 1) {           f--;           tf--;         } else           tf = tf - 3;       }       if (tf < 0) {         cout <<  NO ;         break;       }     }     if (tf >= 0) cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, y;   int main() {     cin >> n;     n--;     for (int i = 1; i <= sqrt(n); i++)       if (n % i == 0) {         y = n / i - 1 - i;         if ((y % 2 == 0) && (y > 0)) {           cout << i <<     << y / 2;           return 0;         }       }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n];     int b[m];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     int flag = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i] == b[j] && flag == 0) {           cout << a[i] <<    ;           flag = 1;         }       }       flag = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int power(int a, int b, int p) {     int ans = 1 % p;     for (; b; b >>= 1) {       if (b & 1) ans = (long long)ans * a % p;       a = (long long)a * a % p;     }     return ans;   }   int a, b, c, d;   int main() {     scanf( %d%d%d%d , &a, &b, &c, &d);     if (a == d && (a != 0 || c == 0))       printf( 1 n );     else       printf( 0 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXINT = 1000001;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n), b(n);       vector<bool> used(MAXINT);       set<int> dif;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a.begin(), a.end());       for (int i = 0; i < n; i++) {         for (int j = 0; j < i; j++) {           dif.insert(a[i] - a[j]);         }       }       int p = 1;       bool can = true;       for (int i = 0; i < n; i++) {         while (p < MAXINT && used[p]) {           ++p;         }         if (p == MAXINT) {           can = false;           break;         }         b[i] = p;         used[p] = true;         for (int d : dif) {           if (b[i] + d < MAXINT) {             used[b[i] + d] = true;           }         }       }       if (can) {         cout <<  YES n ;         for (int i : b) {           cout << i <<    ;         }         cout <<   n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[100001];   int tmp, n, b[100001];   vector<pair<int, int> > a;   int main() {     int tt, ss;     cin >> n;     for (int i = (0); i <= (n - 1); i++) {       cin >> tt >> ss;       a.push_back(make_pair(tt, ss));     }     sort(a.begin(), a.end());     tmp = 0;     int mn = INT_MIN;     for (int i = (0); i <= (n - 1); i++) {       int lb = lower_bound(a.begin(), a.end(),                            make_pair(a[i].first - a[i].second, 0)) -                a.begin();       dp[i] = dp[lb - 1] + 1;       mn = max(mn, dp[i]);     }     cout << n - mn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long b, deocoai, g, n, p, q, i, a[300], t, tong, z, a1, a2, k2, k1;     cin >> b >> g >> n;     if (min(b, g) >= n) {       cout << n + 1;       return 0;     }     if (max(b, g) >= n && min(b, g) <= n) {       cout << min(b, g) + 1;       return 0;     }     cout << b + g - n + 1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     vector<pair<int, int> > v;     vector<int> all;     for (int i = 1; i <= n; ++i) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       if (a + b < c + d) {         if (a > d) v.push_back(make_pair(a - d, d - a));         if (b > c) v.push_back(make_pair(c - b, b - c));       } else {         v.push_back(make_pair(a, b));         v.push_back(make_pair(c, d));       }     }     for (auto p : v) {       int a = p.first, b = p.second;       all.push_back(a + b);       ans += a - b;     }     sort(all.begin(), all.end(), greater<int>());     for (int i = 0; i < (int)all.size(); ++i) {       if (i & 1)         ans -= all[i];       else         ans += all[i];     }     printf( %lld n , ans / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long max_sz = 1e5 + 1;   const long long mod = 1e9 + 7;   const long long MAXN = 4e18 + 1;   char flip(char k) {     if (k ==  0 ) return  1 ;     return  0 ;   }   long long sum_digit(long long n) {     long long a = 0, i;     for (i = n; i > 0; i = i / 10) {       a += (i % 10);     }     return a;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long t;     t = 1;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n);       for (int i = 0; i < n; ++i) cin >> a[i];       sort(a.begin(), a.end());       long long f = 0;       for (long long i = 0; i < n - 2; i++) {         if (a[i] == a[i + 1] && a[i] == a[i + 2]) {           f = 1;           break;         }       }       if (f == 1)         cout <<  NO               <<   n ;       else {         cout <<  YES               <<   n ;         vector<long long> inc, dec;         for (long long i = 0; i < n;) {           if (a[i] == a[i + 1]) {             inc.push_back(a[i]);             dec.push_back(a[i + 1]);             i += 2;           } else {             inc.push_back(a[i]);             i++;           }         }         cout << inc.size() << endl;         for (auto it : inc) cout << it <<    ;         cout << endl;         cout << dec.size() << endl;         sort(dec.begin(), dec.end(), greater<long long>());         for (auto it : dec) cout << it <<    ;         cout << endl;       }     }     cerr << endl          <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double EPS = 1e-8;   using namespace std;   int main() {     int n;     while (cin >> n) {       if (n <= 2)         puts( -1 );       else {         if (n % 2)           cout << 2 * ((long long)(n / 2) * (n / 2) + n / 2) <<                    << 2 * ((long long)(n / 2) * (n / 2) + n / 2) + 1 << endl;         else           cout << (long long)(n / 2) * (n / 2) - 1 <<                    << (long long)(n / 2) * (n / 2) + 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double across(int n, int num_sides) {     double ang = M_PI * ((double)num_sides / n) / 2;     return 0.5 / sin(M_PI / (2 * n)) * sin(ang) * 2;   }   int main() {     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       double arg = (M_PI * (n - 1)) / ((double)2 * n);       if (n % 2 == 0) {         cout << setprecision(50) << tan(arg) <<   n ;       } else {         double r = 0.5 / sin(M_PI / (2 * n));         double side = r * 2 * sin((M_PI / n * (n - 1)) / 2);         cout << setprecision(50)              << sqrt(pow(across(n, n / 2), 2) / (double)2) +                     sqrt(pow(across(n, n / 2 + 1), 2) / (double)2)              <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a, i, j, ans, k, n, m;     scanf( %d , &t);     while (t--) {       ans = 0;       set<int> a;       a.clear();       scanf( %d , &n);       for (i = 1; i <= n; i++) {         scanf( %d , &k);         if (k % 2 == 0) a.insert(k);       }       while (a.size() != 0) {         m = *a.rbegin();         ans++;         a.erase(m);         m /= 2;         if (m % 2 == 0) a.insert(m);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline pair<long long int, long long int> compute_pos(       pair<long long int, long long int> prev, char ch) {     int flag = 1;     pair<long long int, long long int> dest;     dest = prev;     if (ch ==  U ) dest.second += flag;     if (ch ==  D ) dest.second -= flag;     if (ch ==  R ) dest.first += flag;     if (ch ==  L ) dest.first -= flag;     return dest;   }   int main() {     string str;     pair<long long int, long long int> dest;     ios_base::sync_with_stdio(false);     cin >> dest.first >> dest.second;     cin >> str;     long long int R_num = 0, L_num = 0, U_num = 0, D_num = 0, i;     for (i = 0; i < str.length(); i++)       if (str[i] ==  U )         U_num++;       else if (str[i] ==  D )         D_num++;       else if (str[i] ==  L )         L_num++;       else         R_num++;     long long int initial_moves, initial_moves_1 = 0, initial_moves_2 = 0,                                  R_net = R_num - L_num, U_net = U_num - D_num;     if (R_net != 0) initial_moves_1 = dest.first / R_net;     if (U_net != 0) initial_moves_2 = dest.second / U_net;     int s_bit_1 = 1, s_bit_2 = 1;     s_bit_1 = dest.first > 0 ? 1 : -1;     s_bit_2 = dest.second > 0 ? 1 : -1;     while (initial_moves_1 * R_net * s_bit_1 + R_num >= s_bit_1 * dest.first &&            initial_moves_1 > 0)       initial_moves_1--;     while (initial_moves_2 * U_net * s_bit_2 + U_num >= s_bit_2 * dest.second &&            initial_moves_2 > 0)       initial_moves_2--;     initial_moves =         initial_moves_2 < initial_moves_1 ? initial_moves_1 : initial_moves_2;     pair<long long int, long long int> position;     position.first = 0;     position.second = 0;     initial_moves = initial_moves > 0 ? initial_moves : 0;     position.first = R_net * initial_moves;     position.second = U_net * initial_moves;     int flag = 0;     {       if (position == dest)         flag = 1;       else if (R_net == 0 && U_net == 0) {         for (i = 0; i < str.length(); i++) {           position = compute_pos(position, str[i]);           if (dest == position) {             flag = 1;             break;           }         }       } else {         while (true) {           for (i = 0; i < str.length(); i++) {             if (position == dest) {               flag = 1;               break;             }             position = compute_pos(position, str[i]);           }           if (position == dest) {             flag = 1;             break;           }           if (position.first - dest.first > L_num) break;           if (position.second - dest.second > D_num) break;           if (dest.first - position.first > R_num) break;           if (dest.second - position.second > U_num) break;         }       }     }     if (flag == 1)       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[101], t, m, c, b, i, j, k, l;   string s;   int main() {     cin >> t >> m;     for (k = 0; k < t; k++) {       cin >> s;       if (s[0] ==  a ) {         cin >> c;         for (i = 0, j = -1; i < m; i++)           if (i - j == c && !d[i])             break;           else if (d[i])             j = i;         if (i - j == c && i < m) {           cout << ++b << endl;           for (l = j + 1; l <= i; l++) d[l] = b;         } else           cout <<  NULL  << endl;       } else if (s[0] ==  e ) {         cin >> c;         for (i = 0, j = 0; i < m; i++)           if (d[i] == c && c != 0) d[i] = 0, j = 1;         if (!j) cout <<  ILLEGAL_ERASE_ARGUMENT  << endl;       } else if (s[0] ==  d )         for (i = 0, j = 0; i < m; i++)           if (d[i]) l = d[j], d[j] = d[i], d[i] = l, j++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ch, s[22][22];   int n, m, N, sg[22][22][22][22], op[22][22];   bool ok, bo[100000];   void read(int &x) {     for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) ok = 1;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     if (ok) x = -x;   }   int calc(int a, int b, int c, int d) {     if (a > b || c > d) return 0;     if (sg[a][b][c][d] != -1) return sg[a][b][c][d];     for (int i = a; i <= b; i++)       for (int j = c; j <= d; j++)         if (op[i][j] == 1)           calc(a, b, c, j - 1), calc(a, b, j + 1, d);         else if (op[i][j] == 2)           calc(a, i - 1, c, d), calc(i + 1, b, c, d);         else if (op[i][j] == 3)           calc(a, i - 1, c, j - 1), calc(a, i - 1, j + 1, d),               calc(i + 1, b, c, j - 1), calc(i + 1, b, j + 1, d);     for (int i = a; i <= b; i++)       for (int j = c; j <= d; j++)         if (op[i][j] == 1)           bo[calc(a, b, c, j - 1) ^ calc(a, b, j + 1, d)] = 1;         else if (op[i][j] == 2)           bo[calc(a, i - 1, c, d) ^ calc(i + 1, b, c, d)] = 1;         else if (op[i][j] == 3)           bo[calc(a, i - 1, c, j - 1) ^ calc(a, i - 1, j + 1, d) ^              calc(i + 1, b, c, j - 1) ^ calc(i + 1, b, j + 1, d)] = 1;     for (int i = 0;; i++)       if (!bo[i]) {         sg[a][b][c][d] = i;         break;       }     for (int i = a; i <= b; i++)       for (int j = c; j <= d; j++)         if (op[i][j] == 1)           bo[calc(a, b, c, j - 1) ^ calc(a, b, j + 1, d)] = 0;         else if (op[i][j] == 2)           bo[calc(a, i - 1, c, d) ^ calc(i + 1, b, c, d)] = 0;         else if (op[i][j] == 3)           bo[calc(a, i - 1, c, j - 1) ^ calc(a, i - 1, j + 1, d) ^              calc(i + 1, b, c, j - 1) ^ calc(i + 1, b, j + 1, d)] = 0;     return sg[a][b][c][d];   }   int solve(int p) {     memset(op, 0, sizeof(op));     memset(sg, -1, sizeof(sg));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (((i + j) & 1) == p) {           op[(i - j + m + 1) >> 1][(i + j) >> 1] = s[i][j] ==  L    ? 1                                                    : s[i][j] ==  R  ? 2                                                                     : 3;         }     int t = calc(1, N, 1, N);     return t;   }   int main() {     read(n), read(m), N = (n + m) >> 1;     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     puts(solve(0) ^ solve(1) ?  WIN  :  LOSE );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[100010];   int l[100010], r[100010];   int tree[100010 << 2];   int lazy[100010 << 2];   vector<int> v[100010];   void build(int l, int r, int rt) {     if (l == r) {       tree[rt] = num[l];       lazy[rt] = 0;       return;     }     int m = l + r >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);   }   void update(int L, int R, int l, int r, int rt, int w) {     if (L <= l && r <= R) {       tree[rt] += w;       lazy[rt] += w;       return;     }     if (lazy[rt]) {       tree[rt << 1] += lazy[rt];       tree[rt << 1 | 1] += lazy[rt];       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }     int m = l + r >> 1;     if (L <= m) update(L, R, l, m, rt << 1, w);     if (R > m) update(L, R, m + 1, r, rt << 1 | 1, w);     tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);   }   int query(int x, int l, int r, int rt) {     if (l == r) return tree[rt];     int m = l + r >> 1;     if (lazy[rt]) {       tree[rt << 1] += lazy[rt];       tree[rt << 1 | 1] += lazy[rt];       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }     int ans = -0x3f3f3f3f;     if (x <= m)       ans = query(x, l, m, rt << 1);     else       ans = query(x, m + 1, r, rt << 1 | 1);     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> num[i];     build(1, n, 1);     for (int i = 1; i <= m; ++i) {       cin >> l[i] >> r[i];       v[l[i]].emplace_back(i);       v[r[i] + 1].emplace_back(-i);     }     long long ans = -0x3f3f3f3f;     int mark;     for (int i = 1; i <= n; ++i) {       int sz = v[i].size();       for (int j = 0; j < sz; j++) {         int t = v[i][j];         if (t > 0)           update(l[t], r[t], 1, n, 1, -1);         else           update(l[-t], r[-t], 1, n, 1, 1);       }       long long maxx = tree[1];       long long now = query(i, 1, n, 1);       if (maxx - now > ans) {         ans = maxx - now;         mark = i;       }     }     cout << ans << endl;     long long number = 0;     for (int i = 1; i <= m; ++i) {       if (l[i] <= mark && r[i] >= mark) {         number++;       }     }     cout << number << endl;     for (int i = 1; i <= m; ++i) {       if (l[i] <= mark && r[i] >= mark) {         cout << i <<    ;       }     }     return 0;   }