malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 3e5 + 10;   long long pow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   long long y[5], m[5];   long long h, a, d;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     for (long long i = 1; i <= 3; i++) {       cin >> y[i];     }     for (long long i = 1; i <= 3; i++) {       cin >> m[i];     }     cin >> h >> a >> d;     long long mn = 1e18;     for (long long i = y[1]; i <= 1000; i++) {       for (long long j = y[2]; j <= 201; j++) {         for (long long k = y[3]; k <= 201; k++) {           long long z = (i - y[1]) * h + (j - y[2]) * a + (k - y[3]) * d;           if (j <= m[3]) {             continue;           } else if (k >= m[2]) {             mn = min(mn, z);           } else {             long long sec_to_take_yong =                 (m[1] / (j - m[3])) + (m[1] % (j - m[3]) != 0);             long long sec_to_take_m = (i / (m[2] - k)) + (i % (m[2] - k) != 0);             if (sec_to_take_yong < sec_to_take_m) mn = min(mn, z);           }         }       }     }     cout << mn << endl;   }
#include <bits/stdc++.h>   using namespace std;   float distance(long long x, long long y, long long a, long long b) {     return sqrt((x - y) * (x - y) + (a - b) * (a - b));   }   int32_t main() {     float n, x1, y1, x2, y2;     cin >> n >> x1 >> y1 >> x2 >> y2;     if ((x1 == x2 && (x1 == n || x1 == 0)) ||         (y1 == y2 && (y1 == 0 || y2 == n))) {       cout << abs(x1 - x2) + abs(y1 - y2);       return 0;     }     long long path1 = 0, path2 = 0;     if (abs(x1 - x2) == n) {       path1 = 2 * n - (y1 + y2);       path2 = y1 + y2;       cout << (path1 > path2 ? path2 : path1) + n;       return 0;     }     if (abs(y1 - y2) == n) {       path1 = 2 * n - (x1 + x2);       path2 = x1 + x2;       cout << (path1 > path2 ? path2 : path1) + n;       return 0;     }     cout << abs(x1 - x2) + abs(y2 - y1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, l, r, c, ans;     cin >> a >> b >> l >> r;     c = l % (a + b);     if (c > a) {       ans = 1;       l += (a + b - c + 1);       if (l <= r) ans += min(a, r - l + 1);       if (a > b) {         l += (2 * b);         if (l <= r) ans += min(a - b, r - l + 1);       }     } else {       ans = min(a - c + 1, r - l + 1);       l += (a - c + 1);       if (l <= r) {         ans++;         l += b;         if ((a <= b && a >= r - l + 1) || a > b) ans--;       }       if (l <= r) ans += min(c - 1, r - l + 1);       l += (c - 1);       if (a > b) {         if ((a - c + 1) > (a - b)) {           l += (b - c + 1);           if (l <= r) ans += min(a - b, r - l + 1);         } else {           if (l <= r) ans += min(a - c + 1, r - l + 1);           l += (a - c + 1);           l += (b + b);           if (l <= r) ans += min(c - b - 1, r - l + 1);         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int maxn = 1e3 + 10;   int n, m, mp[maxn][maxn], cnt, dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};   bool vis[maxn][maxn];   vector<int> ans;   void dfs(int x, int y) {     if (vis[x][y] || x <= 0 || x > n || y <= 0 || y > m) return;     vis[x][y] = 1, ++cnt;     for (int i = 0; i < 4; ++i)       if (!(mp[x][y] & (1 << i))) dfs(x + dx[i], y + dy[i]);   }   void solve() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) scanf( %d , &mp[i][j]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (!vis[i][j]) cnt = 0, dfs(i, j), ans.push_back(cnt);     sort(ans.begin(), ans.end());     for (int i = ans.size() - 1; ~i; --i) printf( %d  , ans[i]);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   char v[500010];   vector<pair<int, int> > inter;   int memo[500010];   int calcula(int ind) {     int res = 0;     int x = ind;     int ini = 0;     int fim = 0;     bool erro = false;     int lh = -1;     inter.clear();     for (int i = 0; i < (n); i++) {       if (v[i] ==  H ) {         x--;         lh = i;       } else if (v[i] ==  S ) {         x++;       }       if (x == -1 && !erro) {         ini = i;         erro = true;       }       if (x == 0 && erro) {         if (i < n && v[i + 1] ==  H ) continue;         inter.push_back(make_pair(ini, i));         erro = false;       }     }     if (x < 0) return false;     if ((int)inter.size() == 0) {       if (lh < t) return true;       return false;     }     int i = 0;     res = inter[0].first;     fim = max(lh, inter[(int)inter.size() - 1].second);     memo[inter.size()] = 0;     int next;     for (int i = (int)inter.size() - 1; i >= 0; i--) {       if (i + 1 < (int)inter.size()) {         next = inter[i + 1].first - 1;       } else {         next = fim;       }       memo[i] = min((inter[i].second - inter[i].first + 1) * 3 - 2 + memo[i + 1] +                         (next - inter[i].second),                     (fim - inter[i].first + 1) * 2 - 1);     }     res += memo[0];     if (res <= t) return true;     return false;   }   int main() {     scanf( %d %d , &n, &t);     for (int i = 0; i < (n); i++) {       scanf(  %c , &v[i]);     }     int inicio = 0;     int fim = n;     int res = -1;     while (1) {       if (inicio > fim) break;       int meio = (inicio + fim) / 2;       if (calcula(meio)) {         res = meio;         fim = meio - 1;       } else {         inicio = meio + 1;       }     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     int x, y;     Point(int x = 0, int y = 0) : x(x), y(y) {}     Point operator-(const Point z) const { return Point(x - z.x, y - z.y); }     friend long long Cross(Point a, Point b) {       return 1ll * a.x * b.y - 1ll * a.y * b.x;     }   } a[2010], b[2010];   bool f[2010];   char ch[2010];   int main(int argc, char const *argv[]) {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;     cin >> ch;     int p = 0;     for (int i = 1; i < n; i++)       if (a[i].y < a[p].y || a[i].y == a[p].y && a[i].x < a[p].x) p = i;     f[p] = 1;     cout << p + 1 <<    ;     for (int i = 0; !i || ch[i - 1]; i++) {       int x = -1;       for (int j = 0; j < n; j++)         if (!f[j]) {           if (x == -1)             x = j;           else if (ch[i] ==  L )             if (Cross(a[j] - a[p], a[x] - a[p]) > 0)               x = j;             else               ;           else if (Cross(a[j] - a[p], a[x] - a[p]) < 0)             x = j;         }       cout << x + 1 <<    ;       f[x] = 1;       p = x;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef pair<int, int> pii;   typedef long long ll;   typedef unsigned long long ull;   template <typename T>   bool umax(T& a, const T& b) {     return b <= a ? false : (a = b, true);   }   template <typename T>   bool umin(T& a, const T& b) {     return b >= a ? false : (a = b, true);   }   template <typename T>   void V2A(T a[], const vector<T>& b) {     for (int i = 0; i < b.size(); i++) a[i] = b[i];   }   template <typename T>   void A2V(vector<T>& a, const T b[]) {     for (int i = 0; i < a.size(); i++) a[i] = b[i];   }   const double PI = acos(-1.0);   const int INF = 1e9 + 7;   const int maxn = 2e3 + 7;   bool plot[maxn][maxn];   int r[maxn][maxn];   int n, m, k;   int check(int row, int col) {     if (col >= 0 && col < m) return true;     return false;   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       if (!plot[x][y]) {         printf( %d %d n , x + 1, y + 1);         plot[x][y] = true;         continue;       }       for (int d = 1; d <= 3; d++) {         int Max = min(n, x + d + 1);         for (int row = max(0, x - d); row < Max; row++) {           int t = d - abs(x - row), col1 = y - t, col2 = y + t;           if (check(row, col1)) umax(r[x][y], r[row][col1] - d);           if (check(row, col2)) umax(r[x][y], r[row][col2] - d);         }       }       for (int d = r[x][y] + 1;; d++) {         int Max = min(n, x + d + 1);         bool ok = false;         for (int row = max(0, x - d); row < Max; row++) {           int t = d - abs(x - row), col1 = y - t, col2 = y + t;           if (check(row, col1) && !plot[row][col1]) {             ok = true;             printf( %d %d n , row + 1, col1 + 1);             plot[row][col1] = true;             break;           }           if (check(row, col2) && !plot[row][col2]) {             ok = true;             printf( %d %d n , row + 1, col2 + 1);             plot[row][col2] = true;             break;           }         }         if (ok) {           r[x][y] = d - 1;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int p, q;   } a[1009];   bool cmp(node a, node b) {     if (a.p != b.p) return a.p < b.p;     if (a.p == b.p) return a.q > b.q;   }   int main() {     int m, n, i;     scanf( %d%d , &m, &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &a[i].p, &a[i].q);     }     sort(a + 1, a + 1 + n, cmp);     int sum = m;     for (i = 1; i <= n; i++) {       if (sum > a[i].p)         sum += a[i].q;       else         break;     }     if (i == n + 1)       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int len = s.size();     cout << s[0];     int flag = 0;     for (int i = 1; i < len; i++) {       if (s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t  &&           (i + 2 != len - 1)) {         cout <<  . ;         i += 2;       } else if (s[i] ==  a  && s[i + 1] ==  t  && flag == 0) {         cout <<  @ ;         i++;         flag = 1;       } else         cout << s[i];     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     long long n, k, a, z = 0;     cin >> n >> k;     vector<int> x(n), c(n);     for (int i = 0; i < n; i++) cin >> x[i];     cin >> a;     for (int i = 0; i < n; i++) cin >> c[i];     multiset<int> ms;     for (int i = 0; i < n; i++) {       ms.insert(c[i]);       while (k < x[i]) {         if (ms.size() == 0) {           cout <<  -1 n ;           return 0;         } else {           k += a;           z += *ms.begin();           ms.erase(ms.begin());         }       }     }     cout << z <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 * 2;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       int l = 0, r = n - 1;       while (l <= n && s[l] ==  0 ) l++;       while (r >= 0 && s[r] ==  0 ) r--;       int ans;       if (l > r)         ans = n;       else         ans = max(r + 1, n - l) * 2;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   #pragma GCC optimize( -ffloat-store )   const long long INF = 0xFFFFFFFFFFFFFFFL;   const long long N = 1e9 + 7;   vector<long long> pri;   void yo(int n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (int p = 2; p <= n; p++)       if (prime[p]) pri.push_back(p);   }   void solve() {     long long n;     cin >> n;     for (long long i = 1; i < 1001; i++) {       if (!binary_search((pri).begin(), (pri).end(), n * i + 1)) {         cout << i;         return;       }     }   }   int32_t main(int32_t argc, char **argv) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     yo(1000003);     long long t;     t = 1;     while (t--) solve();     cerr <<   n           <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d%d , &n, &k);     int mat[n + 1][n + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) mat[i][j] = 0;     }     int br = 0;     for (int i = 1; i <= n; i += 2) {       for (int j = 1, x = i; j <= n && x <= n; j++, x++) {         mat[x][j] = 1;         br++;       }     }     for (int i = 3; i <= n; i += 2) {       for (int h = 1, j = i; h <= n && j <= n; h++, j++) {         mat[h][j] = 1;         br++;       }     }     if (br < k) {       printf( NO );       return 0;     }     printf( YES n );     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (k > 0) {           if (mat[i][j]) {             printf( L );             k--;           } else             printf( S );         } else           printf( S );       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a = 1;     int b = 2;     bool ok = true;     int k;     for (int i = 0; i < n; i++) {       cin >> k;       if (k != a && k != b) {         ok = false;       } else {         if (b == 3 && a == 1) {           a = min(2, k);           b = max(2, k);         } else if (b == 2 && a == 1) {           a = min(3, k);           b = max(3, k);         } else if (b == 3 && a == 2) {           a = min(1, k);           b = max(1, k);         }       }     }     if (ok) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5, M = 20;   int n, m, a[N], b[M], ans[M];   set<vector<int> > use[M + 1];   void find(int y, vector<int>& current) {     if (y == m) {       for (int i = 0; i < n; i++)         if (a[i] != current[i]) return;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cout <<  .* [(bool)(ans[j] & (1 << i))];         cout << endl;       }       exit(0);     }     if (use[y].find(current) != use[y].end()) return;     for (int i = 0; i < (1 << n); i++) {       if ((((((((i << 1) | i) ^ i) >> 1) >> 0)) & 1) +               (((((((i << 1) | i) ^ i) >> 1) >> 1)) & 1) +               (((((((i << 1) | i) ^ i) >> 1) >> 2)) & 1) +               (((((((i << 1) | i) ^ i) >> 1) >> 3)) & 1) +               (((((((i << 1) | i) ^ i) >> 1) >> 4)) & 1) !=           b[y])         continue;       ans[y] = i;       vector<int> newCur = current;       bool flag = true;       for (int j = 0; j < n; j++) {         if (ans[y] & (1 << j) && (!y || !(ans[y - 1] & (1 << j)))) newCur[j]++;         if (newCur[j] > a[j] || newCur[j] < a[j] - ((m - y) / 2)) {           flag = false;           break;         }       }       if (flag) find(y + 1, newCur);     }     use[y].insert(current);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     vector<int> c(n + 1, 0);     find(0, c);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1100;   int n;   char s[maxn + 10];   int data[maxn + 10];   int dp[maxn + 10][2];   int main() {     cin >> n;     getchar();     gets(s);     int i;     for (i = 0; s[i]; i++) data[i] = s[i] -  0 ;     if (i == 1)       printf( 0 n );     else {       int ans1 = 0, ans2 = 0;       for (int j = 0; j < i; j++) {         if ((j & 1) != data[j]) ans1++;       }       for (int j = 0; j < i; j++) {         if ((j & 1) == data[j]) ans2++;       }       printf( %d n , min(ans1, ans2));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct prog {     int i;     int cmp;   } a[100005];   int ans[100005];   bool cmp(prog a, prog b) {     if (a.cmp == b.cmp)       return a.i < b.i;     else       return a.cmp < b.cmp;   }   int main() {     int n, m;     while (cin >> n >> m) {       priority_queue<prog> q;       int i, j;       for (i = 0; i < m; i++) {         a[i].i = i + 1;         a[i].cmp = (int)fabs((m + 1) / 2.0 - i - 1);       }       sort(a, a + m, cmp);       for (i = 0; i < n; i++) {         int k = i % m;         cout << a[k].i << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<pair<pair<int, int>, pair<int, int> > > s;   vector<int> ed[2][300000];   int n, m, k;   int a[300000], b[300000];   long long ans[300000];   bool add(int x, int y, int dx, int dy) {     pair<pair<int, int>, pair<int, int> > g =         make_pair(make_pair(x, y), make_pair(dx, dy));     if (s.find(g) != s.end()) return false;     s.insert(g);     return true;   }   void go(int x, int y, int dx, int dy, long long t) {     int tt = 1;     int d = x - y + m;     if (dx - dy != 0) {       tt = 0;       d = x + y;     }     bool f = add(x, y, dx, dy);     if (!f) return;     for (int j = 0; j < ed[tt][d].size(); j++) {       int kx = a[ed[tt][d][j]];       int ky = b[ed[tt][d][j]];       kx = kx - x;       ky = ky - y;       kx = kx / dx;       ky = ky / dy;       int g = ed[tt][d][j];       if (ans[g] != -1) continue;       ans[g] = t + min(kx, ky);     }     if (dx == 1 && dy == 1) {       int v = min(n - x, m - y);       x += v;       y += v;       if (x == n && y == m) return;       if (y == m)         go(x, y, 1, -1, t + v);       else         go(x, y, -1, 1, t + v);     }     if (dx == -1 && dy == -1) {       int v = min(x, y);       x -= v;       y -= v;       if (x == 0 && y == 0) return;       if (y == 0)         go(x, y, -1, 1, t + v);       else         go(x, y, 1, -1, t + v);     }     if (dx == 1 && dy == -1) {       int v = min(n - x, y);       x += v;       y -= v;       if (x == n && y == 0) return;       if (y == 0)         go(x, y, 1, 1, t + v);       else         go(x, y, -1, -1, t + v);     }     if (dx == -1 && dy == 1) {       int v = min(x, m - y);       x -= v;       y += v;       if (x == 0 && y == m) return;       if (x == 0)         go(x, y, 1, 1, t + v);       else         go(x, y, -1, -1, t + v);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = 1; i <= k; i++) ans[i] = -1;     for (int i = 1; i <= k; i++) {       cin >> a[i] >> b[i];       ed[0][a[i] + b[i]].push_back(i);       ed[1][a[i] - b[i] + m].push_back(i);     }     go(0, 0, 1, 1, 0);     for (int i = 1; i <= k; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long x = 0, f = 1;     while (ch <  0  || ch >  9 ) f = ch ==  -  ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   int main(int argc, char *argv[]) {     ios::sync_with_stdio(false);     cin.tie(0);     long long base = (1LL << 7) - 1;     long long res = 0, cur;     printf( ? );     for (long long i = (1); i <= (100); i += (1)) printf(  %lld , i);     putchar(  n );     fflush(stdout);     cur = read();     res += (cur >> 7) << 7;     printf( ? );     for (long long i = (1); i <= (100); i += (1)) printf(  %lld , i << 7);     putchar(  n );     fflush(stdout);     cur = read();     res += cur & base;     printf( ! %lld n , res);     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct Segtree {     int N;     vector<T> seg, lazy;     Segtree(int _n) : N(_n) {       seg.resize(4 * N, 0);       lazy.resize(4 * N, 0);     }     T join(T x, T y) { return max(x, y); }     void push(int x, int s, int e) {       if (!lazy[x]) return;       seg[x] = max(seg[x], lazy[x]);       if (s != e) {         lazy[2 * x] = max(lazy[2 * x], lazy[x]);         lazy[2 * x + 1] = max(lazy[2 * x + 1], lazy[x]);       }       lazy[x] = 0;     }     void build(int x, int s, int e) {       if (s == e) {         seg[x] = 0;         return;       }       int mid = (s + e) >> 1;       build(2 * x, s, mid);       build(2 * x + 1, mid + 1, e);       seg[x] = join(seg[2 * x], seg[2 * x + 1]);     }     void update(int x, int s, int e, int l, int r, T val) {       push(x, s, e);       if (s > r || e < l) return;       if (s >= l && e <= r) {         lazy[x] = val;         push(x, s, e);         return;       }       int mid = (s + e) >> 1;       update(2 * x, s, mid, l, r, val);       update(2 * x + 1, mid + 1, e, l, r, val);       seg[x] = join(seg[2 * x], seg[2 * x + 1]);     }     T query(int x, int s, int e, int l, int r) {       push(x, s, e);       if (e < l || s > r) return 0;       if (s >= l && e <= r) {         return seg[x];       }       int mid = (s + e) >> 1;       return join(query(2 * x, s, mid, l, r), query(2 * x + 1, mid + 1, e, l, r));     }     void update(int l, int r, T val) { update(1, 0, N - 1, l, r, val); }     T query(int l, int r) { return query(1, 0, N - 1, l, r); }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     vector<int> x(q), y(q), d(q), cc(1, 0);     for (int i = 0; i < q; ++i) {       char c;       cin >> x[i] >> y[i] >> c;       d[i] = (c ==  U );       cc.push_back(x[i]);       cc.push_back(y[i]);       cc.push_back(n + 1 - x[i]);       cc.push_back(n + 1 - y[i]);     }     sort(cc.begin(), cc.end());     cc.erase(unique(cc.begin(), cc.end()), cc.end());     Segtree<int> left(cc.size() + 1), up(cc.size() + 1);     for (int i = 0; i < q; ++i) {       x[i] = lower_bound(cc.begin(), cc.end(), x[i]) - cc.begin();       y[i] = lower_bound(cc.begin(), cc.end(), y[i]) - cc.begin();       if (d[i]) {         int id = up.query(y[i], y[i]);         up.update(y[i], y[i], y[i]);         cout << cc[y[i]] - cc[id] <<   n ;         id = lower_bound(cc.begin(), cc.end(), n + 1 - cc[id]) - cc.begin();         y[i] = lower_bound(cc.begin(), cc.end(), n + 1 - cc[y[i]]) - cc.begin();         left.update(y[i], id, x[i]);       } else {         int id = left.query(x[i], x[i]);         left.update(x[i], x[i], x[i]);         cout << cc[x[i]] - cc[id] <<   n ;         id = lower_bound(cc.begin(), cc.end(), n + 1 - cc[id]) - cc.begin();         x[i] = lower_bound(cc.begin(), cc.end(), n + 1 - cc[x[i]]) - cc.begin();         up.update(x[i], id, y[i]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int l = 1, r = 0;   int a[MAXN], b[MAXN], now[MAXN], num[MAXN << 1], cnt[MAXN], ans[MAXN];   map<int, int> ms;   struct Change {     int p, x, y;   } c[MAXN];   struct Query {     int l, r, t, id;     bool operator<(const Query &A) const {       if (b[l] == b[A.l]) return b[r] == b[A.r] ? t < A.t : b[r] < b[A.r];       return b[l] < b[A.l];     }   } q[MAXN];   void update(int x, int d) {     int &y = num[x];     if (y > 0) cnt[y]--;     y += d;     if (y > 0) cnt[y]++;   }   void modify(int p, int d) {     if (l <= p && p <= r) {       update(a[p], -1);       update(d, 1);     }     a[p] = d;   }   int get() {     for (int i = 1;; i++) {       if (!cnt[i]) return i;     }   }   int main() {     int n, m, id = 0, Time = 0, sz = 0;     scanf( %d%d , &n, &m);     int B = 2000;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       int &t = ms[a[i]];       if (!t) t = ++sz;       now[i] = a[i] = t;       b[i] = i / B + 1;     }     while (m--) {       int op, x, y;       scanf( %d%d%d , &op, &x, &y);       if (op == 1)         q[++id] = (Query){x, y, Time, id};       else {         int &t = ms[y];         if (!t) t = ++sz;         c[++Time] = (Change){x, y = t, now[x]};         now[x] = y;       }     }     sort(q + 1, q + id + 1);     int v = 0;     for (int i = 1; i <= id; i++) {       while (v < q[i].t) modify(c[v + 1].p, c[v + 1].x), v++;       while (v > q[i].t) modify(c[v].p, c[v].y), v--;       while (l < q[i].l) update(a[l], -1), l++;       while (l > q[i].l) update(a[l - 1], 1), l--;       while (r < q[i].r) update(a[r + 1], 1), r++;       while (r > q[i].r) update(a[r], -1), r--;       ans[q[i].id] = get();     }     for (int i = 1; i <= id; i++) {       printf( %d n , ans[i]);     }     return 0;   }