malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t, x, sum = 0, y, z, flag = 0, a, p, l, r, b, c, q, i, j, k, n,                         m, maxi = LONG_MIN, mini = LONG_MAX, mul = 1;     string s, s1;     vector<long long int> v, va, vb;     map<long long int, long long int> mp, mp1;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       mp[x]++;       mp1[x]++;     }     auto it = mp.begin();     auto it1 = mp1.begin();     while (it1 != mp1.end()) {       if (it->first == it1->first) it1++;       if (it1 == mp1.end()) break;       x = it->second;       y = it1->second;       for (i = 0; i < x && i < y; i++) {         mp[it->first]--;         sum++;         mp1[it1->first]--;       }       if (x == i) it++;       if (y == i) it1++;     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct ele {     long long next, prev, delta, y;   };   long long r, c, k, n, curcnt = 0, ans = 0;   vector<ele> a;   vector<long long> deltaleft, deltaright;   vector<vector<long long> > X, id;   vector<pair<long long, long long> > tmp;   void init() {     X.clear();     X.resize(r + 1);     id.resize(r + 1);   }   void remove(long long id) {     long long cur = id;     deltaleft.clear();     deltaright.clear();     for (long long i = 0; i <= k; i++) {       if (cur == -1 || a[cur].delta == -1) break;       deltaleft.push_back(a[cur].delta);       cur = a[cur].prev;     }     cur = a[id].next;     for (long long i = 0; i <= k; i++) {       if (cur == -1 || a[cur].delta == -1) break;       deltaright.push_back(a[cur].delta);       cur = a[cur].next;     }     curcnt -= deltaright[0] * deltaleft[0];     curcnt -= deltaright[0] * (deltaright[0] - 1) / 2 +               deltaleft[0] * (deltaleft[0] - 1) / 2;     curcnt +=         (deltaright[0] + deltaleft[0]) * (deltaright[0] + deltaleft[0] - 1) / 2;     for (long long i = 0; i <= k; i++) {       if (i < deltaleft.size() && k - i < deltaright.size())         curcnt += deltaleft[i] * deltaright[k - i];     }     a[a[id].prev].next = a[id].next;     a[a[id].next].prev = a[id].prev;     a[a[id].next].delta += a[id].delta;   }   long long cmp(pair<long long, long long> a, pair<long long, long long> b) {     return X[a.first][a.second] < X[b.first][b.second];   }   void solve(long long r1) {     tmp.clear();     for (long long i = r1; i <= r; i++) {       for (long long j = 0; j < X[i].size(); j++) {         tmp.push_back({i, j});       }     }     sort(tmp.begin(), tmp.end(), cmp);     a.resize(tmp.size() + 2);     a[0].prev = -1;     a[0].next = 1;     a[0].y = 0;     a[tmp.size() + 1].prev = (long long)tmp.size();     a[tmp.size() + 1].next = -1;     a[tmp.size() + 1].y = c + 1;     for (long long i = 0; i < tmp.size(); i++) {       id[tmp[i].first][tmp[i].second] = i + 1;       a[i + 1].y = X[tmp[i].first][tmp[i].second];       a[i + 1].prev = i;       a[i + 1].next = i + 2;     }     a[0].delta = -1;     for (long long i = 1; i < a.size(); i++) {       a[i].delta = a[i].y - a[i - 1].y;     }     curcnt = 0;     for (long long i = 1; i < a.size(); i++) {       curcnt += (a[i].delta - 1) * a[i].delta / 2;       for (long long j = 1; j <= k; j++) {         if (i - j <= 0) break;         curcnt += a[i].delta * a[i - j].delta;       }     }     for (long long i = r; i >= r1; i--) {       ans += curcnt;       for (long long j = 0; j < X[i].size(); j++) {         remove(id[i][j]);       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> r >> c >> n >> k;     k--;     init();     for (long long i = 1; i <= n; i++) {       long long u, v;       cin >> u >> v;       X[u].push_back(v);     }     for (long long i = 1; i <= r; i++) {       id[i].resize(X[i].size());     }     for (long long i = 1; i <= r; i++) {       solve(i);     }     ans = (r + 1) * r / 2 * (c + 1) * c / 2 - ans;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300007;   struct tup {     int u, v, pos;     friend bool operator<(tup x, tup y) {       if (x.v < y.v) {         return 1;       }       return 0;     }   } ans[maxn];   int rec[maxn], n;   int solve() {     int cnt = 0;     rec[cnt++] = n;     ans[n].v = 2 * n + 1;     for (int i = n - 1; i >= 0; --i) {       if (ans[i].u < ans[rec[cnt - 1]].v && ans[i].u < ans[i].v) {         rec[cnt++] = i;       }     }     return cnt;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &ans[i].u, &ans[i].v);       ans[i].pos = i;     }     sort(ans, ans + n);     int cnt1 = solve() - 1;     int tmp[maxn];     for (int i = 1; i <= cnt1; ++i) {       tmp[i] = ans[rec[i]].pos + 1;     }     for (int i = 0; i < n; ++i) {       ans[i].u = -ans[i].u;       ans[i].v = -ans[i].v;     }     sort(ans, ans + n);     int cnt = solve() - 1;     if (cnt <= cnt1) {       printf( %d n , cnt1);       for (int i = 1; i <= cnt1; ++i) {         printf( %d  , tmp[i]);       }     } else {       printf( %d n , cnt);       for (int i = 1; i <= cnt; ++i) {         printf( %d  , ans[rec[i]].pos + 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, q, counts = 0;     cin >> n;     int s[n];     for (int i = 0; i < n; i++) cin >> s[i];     cin >> q;     int l[q], r[q];     for (int i = 0; i < q; i++) cin >> l[i] >> r[i];     int sums[n + 1];     sums[0] = 0;     for (int i = 1; i < n + 1; i++) sums[i] = sums[i - 1] + s[i - 1];     for (int i = 0; i < q; i++)       cout << (sums[r[i]] - sums[l[i] - 1]) / 10 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int M = 107;   const int inf = 1e9 + 7;   vector<int> g[N], a[M];   int w[N][M], d[N];   void bfs(int u) {     queue<int> q;     memset(d, inf, sizeof(d));     for (int i = 0; i < (int)a[u].size(); ++i) {       q.push(a[u][i]);       d[a[u][i]] = 0;     }     while (!q.empty()) {       int v = q.front();       q.pop();       w[v][u] = d[v];       for (int i = 0; i < (int)g[v].size(); ++i) {         int to = g[v][i];         if (d[to] > d[v] + 1) {           d[to] = d[v] + 1;           q.push(to);         }       }     }   }   int main() {     int n, m, k, second;     scanf( %d %d %d %d , &n, &m, &k, &second);     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       a[x].push_back(i);     }     for (int i = 0, u, v; i < m; ++i) {       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= k; ++i) bfs(i);     for (int i = 1; i <= n; ++i) {       sort(w[i] + 1, w[i] + k + 1);       int ans = 0;       for (int j = 1; j <= second; ++j) ans += w[i][j];       printf( %d  , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, m, x;     unordered_map<int, int> mp;     cin >> t;     int a[t];     for (int i = 1; i <= t; i++) {       cin >> a[i];       mp[i] = a[i];     }     for (int i = 1; i <= t; i++) {       n = mp[i];       m = mp[n];       x = mp[m];       if (i == x) {         cout <<  YES ;         return 0;       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 23;   const int mod = 1000 * 1000 * 1000 + 7;   int dp[2][1 << maxN];   int a[maxN];   int res[maxN][maxN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     dp[0][1] = 1;     dp[0][0] = mod;     memset(res, -1, sizeof res);     for (int i = 0; i < n; i++)       for (int j = 0; j < i; j++)         for (int k = 0; k < i; k++)           if (a[j] + a[k] == a[i]) res[i][j] = k;     for (int i = 1; i < n; i++) {       int u = i & 1;       for (int mask = 0; mask < (1 << (i + 1)); mask++) dp[u][mask] = mod;       for (int mask = 0; mask < (1 << i); mask++) {         for (int j = 0; j < i; j++) {           if (res[i][j] == -1) continue;           if (mask >> j & 1)             if (mask >> res[i][j] & 1) {               int tmp = mask ^ (1 << i);               dp[u][tmp] =                   min(dp[u][tmp], max(__builtin_popcount(tmp), dp[!u][mask]));               for (int k = 0; k < i; k++) {                 if (mask >> k & 1) {                   dp[u][tmp ^ (1 << k)] =                       min(dp[u][tmp ^ (1 << k)], dp[!u][mask]);                 }               }               break;             }         }       }     }     int ans = mod;     for (int mask = 0; mask < (1 << n); mask++)       ans = min(ans, dp[(n - 1) & 1][mask]);     if (ans == mod)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 51;   char a[MN][MN], b[MN][MN];   const char L =  L , R =  R , U =  U , D =  D ;   vector<pair<int, int> > sol, sol2;   int n, m;   void show() {     ;     for (int i = 0; i < n; ++i)       ;     ;     ;     for (int i = 0; i < n; ++i)       ;     ;   }   bool move(char arr[MN][MN], int i, int j) {     ;     if (arr[i][j] == U && arr[i][j + 1] == U && arr[i + 1][j] == D &&         arr[i + 1][j + 1] == D) {       ;       arr[i][j] = arr[i + 1][j] = L;       arr[i][j + 1] = arr[i + 1][j + 1] = R;     } else if (arr[i][j] == L && arr[i + 1][j] == L && arr[i][j + 1] == R &&                arr[i + 1][j + 1] == R) {       ;       arr[i][j] = arr[i][j + 1] = U;       arr[i + 1][j] = arr[i + 1][j + 1] = D;     } else {       ;       return false;     }     sol.emplace_back(i, j);     return true;     ;     show();   }   void push(char arr[MN][MN], int i, int k, bool ver) {     char aim = ver ? U : L;     ;     show();     assert(arr[i][k] == L || arr[i][k] == U);     if (arr[i][k] != aim) {       if (!move(arr, i, k)) {         push(arr, i + ver, k + !ver, !ver);         move(arr, i, k);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %s , a[i]);     for (int i = 0; i < n; ++i) scanf( %s , b[i]);     if (n % 2) {       ;       for (int k = 0; k < m; k += 2)         for (int i = 0; i < n; ++i) push(a, i, k, false);       swap(sol, sol2);       ;       for (int k = 0; k < m; k += 2)         for (int i = 0; i < n; i++) push(b, i, k, false);     } else {       ;       for (int i = 0; i < n; i += 2)         for (int k = 0; k < m; k++) push(a, i, k, true);       swap(sol, sol2);       ;       for (int i = 0; i < n; i += 2)         for (int k = 0; k < m; k++) push(b, i, k, true);     }     printf( %d n , (int)(sol.size() + sol2.size()));     reverse(sol.begin(), sol.end());     for (auto x : sol2) printf( %d %d n , x.first + 1, x.second + 1);     for (auto x : sol) printf( %d %d n , x.first + 1, x.second + 1);   }
#include <bits/stdc++.h>   char ans[4][128];   int main() {     int i, j, n;     while (scanf( %d , &n) != EOF) {       memset(ans, 0, sizeof(ans));       if (n % 2 == 1) {         j = 0;         ans[0][0] =  a  + j;         ans[1][0] =  a  + j;         j = (j + 1) % 26;         for (i = 0; i < n; i += 2) {           ans[0][i + 1] = ans[0][i + 2] =  a  + j;           j = (j + 1) % 26;           ans[1][i + 1] = ans[1][i + 2] =  a  + j;           j = (j + 1) % 26;           ans[2][i + 1] = ans[2][i] =  a  + j;           j = (j + 1) % 26;           ans[3][i + 1] = ans[3][i] =  a  + j;           j = (j + 1) % 26;         }         ans[2][n - 1] =  a  + j;         ans[3][n - 1] =  a  + j;         ans[0][n] = ans[1][n] = ans[2][n] = ans[3][n] =   0 ;       } else {         j = 0;         ans[1][0] =  a  + j;         ans[2][0] =  a  + j;         j = (j + 1) % 26;         for (i = 0; i < n; i += 2) {           ans[1][i + 1] = ans[1][i + 2] =  a  + j;           j = (j + 1) % 26;           ans[2][i + 1] = ans[2][i + 2] =  a  + j;           j = (j + 1) % 26;           ans[0][i + 1] = ans[0][i] =  a  + j;           j = (j + 1) % 26;           ans[3][i + 1] = ans[3][i] =  a  + j;           j = (j + 1) % 26;         }         ans[1][n - 1] =  a  + j;         ans[2][n - 1] =  a  + j;         ans[0][n] = ans[1][n] = ans[2][n] = ans[3][n] =   0 ;       }       puts(ans[0]);       puts(ans[1]);       puts(ans[2]);       puts(ans[3]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   inline T LCM(T a, T b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return a * (b / gcd(a, b));   }   vector<int> arr;   const int N = 50005;   int memo[5001];   int save[N];   int visit[N];   int find(int pos, int &xr) {     for (int i = 0; i < N; i++) visit[i] = 0;     vector<int> toAdd;     int end = pos;     visit[arr[pos]] = 1;     for (int i = 0; i < pos; i++) {       visit[arr[i]] = 2;     }     if (visit[arr[pos]] == 2) {       return -1;     }     bool cant = false;     for (int i = pos; i < arr.size(); i++) {       if (visit[arr[i]] == 2) {         cant = true;       }       if (visit[arr[i]] == 1) {         if (cant) return -1;         for (int j = 0; j < toAdd.size(); j++) {           visit[toAdd[j]] = 1;         }         toAdd.clear();         end = i;       } else {         toAdd.push_back(arr[i]);       }     }     xr = 0;     for (int i = 0; i < N; i++) {       if (visit[i] == 1) {         xr = xr ^ i;       }     }     return end;   }   int solve(int from) {     int txr = 0;     int ret = 0;     if (from >= arr.size()) return 0;     if (memo[from] != -1) {       return memo[from];     }     int end = find(from, txr);     if (end != -1) {       ret = max(txr + solve(end + 1), solve(from + 1));     } else {       ret = solve(from + 1);     }     memo[from] = ret;     return ret;   }   int main() {     int n, i, temp, j;     for (i = (int)0; i < (int)5001; ++i) {       memo[i] = -1;     }     scanf( %d , &n);     for (i = (int)0; i < (int)n; ++i) {       scanf( %d , &temp);       arr.push_back(temp);     }     int xx;     cout << solve(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d;   void solve() {     double m = max((3.0) * a / (10.0), (double)(a - a * c / 250));     double v = max((3.0) * b / (10.0), (double)(b - b * d / 250));     if (m > v) cout <<  Misha  << endl;     if (m == v) cout <<  Tie  << endl;     if (m < v) cout <<  Vasya  << endl;   }   int main() {     while (cin >> a >> b >> c >> d) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string op;   bool check(int l, int r) {     char c;     cout <<  ?   << l <<     << r << endl;     cin >> c;     return c ==  x ;   }   int main() {     while (cin >> op) {       if (op ==  end ) {         return 0;       }       int l = 1, r = 2;       while (1) {         if (check(l, r)) break;         l <<= 1, r <<= 1;       }       while (l + 1 < r) {         int mid = (l + r) >> 1;         if (check(l - 1, mid))           r = mid;         else           l = mid + 1;       }       if (l == 1 && r == 2) {         if (check(2, 3))           cout <<  ! 1  << endl;         else           cout <<  ! 2  << endl;       } else {         if (l == r)           cout <<  !   << l << endl;         else {           if (check(l, l + 1))             cout <<  !   << l + 1 << endl;           else             cout <<  !   << l << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, a[1000005];   long long l;   vector<int> val, cou, dp[1000005];   void add(int &a, int b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   void setup() {     cin >> n >> l >> k;     for (int i = 0; i <= n - 1; i++) {       cin >> a[i];       val.push_back(a[i]);     }     sort(val.begin(), val.end());     val.resize(unique(val.begin(), val.end()) - val.begin());     cou.resize(val.size());     for (int i = 0; i <= n - 1; i++) {       dp[i].resize(k + 1);       dp[i][1] = 1;       a[i] = lower_bound(val.begin(), val.end(), a[i]) - val.begin();     }   }   void xuly() {     for (int j = 2; j <= k; j++) {       for (int i = 0; i <= int(cou.size()) - 1; i++) cou[i] = 0;       for (int i = 0; i <= n - 1; i++) add(cou[a[i]], dp[i][j - 1]);       for (int i = 1; i <= int(cou.size()) - 1; i++) add(cou[i], cou[i - 1]);       for (int i = 0; i <= n - 1; i++) dp[i][j] = cou[a[i]];     }     int ans = 0;     for (int i = 0; i <= n - 1; i++)       for (int j = 1; j <= k; j++) {         long long m = l / n;         if (i < l % n) m++;         m = m - j + 1;         if (m > 0) ans = (ans + (m % 1000000007) * dp[i][j]) % 1000000007;       }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     setup();     xuly();     return 0;   }
#include <bits/stdc++.h>   const int N = 500005;   int to[N << 1], edge, Next[N << 1], last[N], n, x, y, d[N], mx1[N], mx2[N];   int f[N], fmx[N], ans1, mx[N], f0[N], f1[N], sum[N];   std::vector<int> e[N];   void upd(int &x, int y) {     if (y > x) x = y;   }   void add(int x, int y) {     to[++edge] = y;     Next[edge] = last[x];     last[x] = edge;   }   void dfs1(int x, int y) {     f[x] = y;     for (int i = last[x]; i; i = Next[i]) {       int u = to[i];       if (u == y) continue;       dfs1(u, x);       if (mx1[u] + 1 > mx1[x])         mx2[x] = mx1[x], mx1[x] = mx1[u] + 1;       else if (mx1[u] + 1 > mx2[x])         mx2[x] = mx1[u] + 1;     }   }   void dfs2(int x, int y) {     if (y) e[fmx[x]].push_back(x);     for (int i = last[x]; i; i = Next[i]) {       int u = to[i];       if (u == y) continue;       if (mx1[x] == mx1[u] + 1)         fmx[u] = std::max(mx2[x], fmx[x]) + 1;       else         fmx[u] = std::max(mx1[x], fmx[x]) + 1;       e[mx1[u] + 1].push_back(x);     }     for (int i = last[x]; i; i = Next[i])       if (to[i] != y) dfs2(to[i], x);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       add(x, y), add(y, x);       d[x]++, d[y]++;     }     for (int i = 1; i <= n; i++) upd(ans1, d[i] + 1);     dfs1(1, 0);     dfs2(1, 0);     f0[n] = f1[n] = 1;     for (int i = n; i >= 1; i--) {       int lst = 0;       for (auto u : e[i]) {         sum[u]++;         upd(f0[i], sum[u]);         upd(f1[i - 1], sum[u]);         if (lst != u) upd(f1[i], sum[u]);         upd(mx[f[u]], sum[u]);         upd(f0[i], sum[u] + mx[u] - 2);         if (f[u]) upd(f0[i], sum[u] + sum[f[u]] - 2);         lst = u;       }     }     for (int i = n; i >= 1; i--) upd(f0[i], f0[i + 1]), upd(f1[i], f1[i + 1]);     printf( %d  , ans1);     for (int i = 2; i <= n; i++)       if (i & 1)         printf( %d  , f1[i / 2]);       else         printf( %d  , f0[i / 2]);   }
#include <bits/stdc++.h>   using namespace std;   int a[1000];   bool b[1000][1000];   int main() {     int N, M;     scanf( %d%d , &N, &M);     for (int i = 0; i < N; i++) scanf( %d , &a[i]);     for (int i = 0; i < M; i++) {       int x, y;       scanf( %d%d , &x, &y);       --x;       --y;       b[x][y] = true;       b[y][x] = true;     }     int mincost = 1000000000;     for (int x = 0; x < N; x++)       for (int y = 0; y < N; y++)         for (int z = 0; z < N; z++)           if (b[x][y] && b[y][z] && b[x][z])             if (a[x] + a[y] + a[z] < mincost) mincost = a[x] + a[y] + a[z];     if (mincost == 1000000000)       printf( -1 );     else       printf( %d n , mincost);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > arr(n + 1, vector<int>(m + 1));     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= m; i++) {         cin >> arr[k][i];         arr[k][i] += arr[k][i - 1];       }     }     for (int i = 1; i <= m; i++) {       for (int k = 1; k <= n; k++) {         arr[k][i] += arr[k - 1][i];       }     }     int a, b;     cin >> a >> b;     int res = 1e9;     for (int k = a; k <= n; k++) {       for (int i = b; i <= m; i++) {         res = min(res,                   arr[k][i] - arr[k][i - b] - arr[k - a][i] + arr[k - a][i - b]);       }     }     for (int k = b; k <= n; k++) {       for (int i = a; i <= m; i++) {         res = min(res,                   arr[k][i] - arr[k][i - a] - arr[k - b][i] + arr[k - b][i - a]);       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5 + 50;   using namespace std;   int n, m, h, tot, mx, maxn, ans;   int a[N], b[N], cnt[N], num[N];   int read() {     int s = 0, t = 1;     char c;     while (c <  0  || c >  9 ) {       if (c ==  - ) t = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = s * 10 + c -  0 ;       c = getchar();     }     return s * t;   }   long long readl() {     long long s = 0, t = 1;     char c;     while (c <  0  || c >  9 ) {       if (c ==  - ) t = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = s * 10 + c -  0 ;       c = getchar();     }     return s * t;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= m; i++) a[i] = read(), b[a[i]]++, mx = max(mx, a[i]);     for (int i = 1; i <= mx; i++)       if (b[i] > 0) cnt[++tot] = b[i];     for (int i = 1; i <= m; i++) {       h = 0;       for (int j = 1; j <= tot; j++) h += cnt[j] / i;       if (h >= n)         ans = i;       else         break;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     set<int> s;     multiset<int> d;     auto Add = [&](int x) {       auto ret = s.insert(x);       auto it = ret.first;       if (next(it) != s.end() && it != s.begin()) {         d.erase(d.find(*next(it) - *prev(it)));       }       if (it != s.begin()) {         d.insert(*it - *prev(it));       }       if (next(it) != s.end()) {         d.insert(*next(it) - *it);       }     };     auto Remove = [&](int x) {       auto it = s.find(x);       if (it != s.begin()) {         d.erase(d.find(*it - *prev(it)));       }       if (next(it) != s.end()) {         d.erase(d.find(*next(it) - *it));       }       if (next(it) != s.end() && it != s.begin()) {         d.insert(*next(it) - *prev(it));       }       s.erase(it);     };     for (int i = 0; i < n; i++) {       int foo;       cin >> foo;       Add(foo);     }     for (int i = 0; i <= q; i++) {       if (d.empty()) {         cout << 0 <<   n ;       } else {         cout << *prev(s.end()) - *s.begin() - *prev(d.end()) <<   n ;       }       if (i == q) {         break;       }       int c, x;       cin >> c >> x;       if (c) {         Add(x);       } else {         Remove(x);       }     }     return 0;   }