malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long const mod = 1e9 + 7;   long long const long_max = LONG_LONG_MAX;   int interact(int i, int j) {     cout <<  ?   << i + 1 <<     << j + 1 <<   n ;     ;     cout.flush();     int x;     cin >> x;     return x;   }   void solve() {     int n;     cin >> n;     int ind = 0;     vector<int> b(n);     for (int i = 1; i < n; i++) {       int x = interact(ind, i);       int y = interact(i, ind);       if (x < y) {         b[i] = y;       } else {         b[ind] = x;         ind = i;       }     }     b[ind] = n;     cout <<  !  ;     for (auto i : b) cout << i <<    ;     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1, p;     p = t;     t = 1;     while (p--) {       solve();       t++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char c = getchar();     long long u = 0, f = 1;     while (c !=  -  && (c <  0  ||  9  < c)) c = getchar();     if (c ==  - ) {       f = -1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       u = u * 10 + c -  0 ;       c = getchar();     }     return u * f;   }   inline char readc() {     for (;;) {       char c = getchar();       if ( A  <= c && c <=  Z  ||  a  <= c && c <=  z ) return c;     }   }   inline int read_digit() {     for (;;) {       char c = getchar();       if ( 0  <= c && c <=  9 ) return c -  0 ;     }   }   inline int max(int a, int b) { return a > b ? a : b; }   inline int min(int a, int b) { return a < b ? a : b; }   template <typename T>   inline void updmax(T &a, T b) {     if (b > a) a = b;   }   template <typename T>   inline void updmin(T &a, T b) {     if (b < a) a = b;   }   inline void swap(int &a, int &b) {     int t = a;     a = b;     b = t;   }   inline void fileio(string s) {     if (s ==  txt ) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     } else {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   char a[1000010];   map<int, int> cnt;   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %s , a);       int l = strlen(a);       int b[26] = {0};       for (int j = 0; j < l; j++) b[a[j] -  a ]++;       int num = 0, id = 1;       for (int j = 0; j < 26; j++) {         if (b[j] % 2 == 1) num += id;         id <<= 1;       }       ans += cnt[num];       for (int j = 0; j < 26; j++) {         int p = (1 << j);         if (num & p)           ans += cnt[num - p];         else           ans += cnt[num + p];       }       cnt[num]++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 500 * 1000 + 10;   vector<int> adj[MAX_N], vec[MAX_N];   int n, m, cnt;   queue<int> q;   set<int> s;   void readInput() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 0; i < n; i++) sort(adj[i].begin(), adj[i].end()), s.insert(i);   }   void solve() {     while (!s.empty()) {       q.push(*s.begin()), s.erase(s.begin());       while (!q.empty()) {         int u = q.front();         q.pop(), vec[cnt].push_back(u);         int cur = 0;         vector<int> tmp;         for (auto v : s) {           while (cur < adj[u].size() && adj[u][cur] < v) cur++;           if (cur == adj[u].size() || adj[u][cur] != v) tmp.push_back(v);         }         for (auto v : tmp) q.push(v), s.erase(v);       }       cnt++;     }   }   void writeOutput() {     cout << cnt << endl;     for (int i = 0; i < cnt; i++) {       cout << vec[i].size() <<    ;       for (auto u : vec[i]) cout << u + 1 <<    ;       cout << endl;     }   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     readInput(), solve(), writeOutput();     return 0;   }
#include <bits/stdc++.h>   char s[300010], p;   int main() {     int n, m, sum = 0, k, i;     scanf( %d%d , &n, &m);     scanf( %s , s);     for (i = 1; i < n; i++)       if (s[i] ==  .  && s[i - 1] ==  . ) sum++;     while (m--) {       scanf( %d %c , &k, &p);       if (p !=  .  && s[k - 1] ==  . ) {         if (s[k - 2] ==  . ) sum--;         if (s[k] ==  . ) sum--;       } else if (p ==  .  && s[k - 1] !=  . ) {         if (s[k - 2] ==  . ) sum++;         if (s[k] ==  . ) sum++;       }       s[k - 1] = p;       printf( %d n , sum);     }     return 0;   }
#include <bits/stdc++.h>   int N, K, A, B, Q, a[200001], TA[524288], TB[524288];   void P(int x) {     int p = 1, l = 1, r = N;     while (l < r) {       int m = l + r >> 1;       if (x <= m)         r = m, p <<= 1;       else         l = m + 1, p = p << 1 | 1;     }     TA[p] = std::min(a[x], A);     TB[p] = std::min(a[x], B);     while (p > 1) {       p >>= 1;       TA[p] = TA[p << 1] + TA[p << 1 | 1];       TB[p] = TB[p << 1] + TB[p << 1 | 1];     }   }   int G(int *T, int p, int l, int r, int L, int R) {     if (L <= l && r <= R) return T[p];     int m = l + r >> 1;     if (R <= m) return G(T, p << 1, l, m, L, R);     if (L > m) return G(T, p << 1 | 1, m + 1, r, L, R);     return G(T, p << 1, l, m, L, R) + G(T, p << 1 | 1, m + 1, r, L, R);   }   int main() {     scanf( %d%d%d%d%d , &N, &K, &A, &B, &Q);     while (Q--) {       int ty, u, w;       scanf( %d%d , &ty, &u);       if (ty == 1) {         scanf( %d , &w);         a[u] += w;         P(u);       } else         printf( %d n , (u > 1 ? G(TB, 1, 1, N, 1, u - 1) : 0) +                            (u > N - K ? 0 : G(TA, 1, 1, N, u + K, N)));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string n;   int ar[123], sum = 0;   int main() {     getline(cin, n);     for (int i = 1; i < n.size(); i += 3) {       ar[(int)n[i]] = 1;     }     for (int i = 0; i < 123; i++) {       sum += ar[i];     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a, b, c;     if (n % 3 == 0) {       a = n - 2;       b = 1;       c = 1;     } else {       if ((n + 1) % 3 == 0) {         a = n - 3;         b = 2;         c = 1;       } else if ((n - 1) % 3 == 0) {         a = n - 2;         b = 1;         c = 1;       }     }     cout << a <<     << b <<     << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long int **sparse;   void buildSparseTable(long long int arr[], long long int n,                         long long int **sparse) {     for (long long int i = 0; i < n; i++) {       sparse[i][0] = i;     }     for (long long int j = 1; pow(2, j) <= n; j++) {       for (long long int i = 0; i + pow(2, j) - 1 < n; i++) {         if (arr[sparse[i][j - 1]] >=             arr[sparse[i + (long long int)pow(2, j - 1)][j - 1]]) {           sparse[i][j] = sparse[i][j - 1];         } else {           sparse[i][j] = sparse[i + (long long int)pow(2, j - 1)][j - 1];         }       }     }   }   long long int query(long long int l, long long int r, long long int **sparse,                       long long int arr[]) {     long long int len = r - l + 1;     long long int k = (log(len) / log(2.0));     long long int m;     if (arr[sparse[l][k]] >= arr[sparse[l + len - (long long int)pow(2, k)][k]]) {       return sparse[l][k];     } else       return sparse[l + len - (long long int)pow(2, k)][k];   }   int main() {     long long int n;     cin >> n;     long long int arr[n];     sparse = new long long int *[n];     for (long long int i = 0; i < n; i++) {       sparse[i] = new long long int[(long long int)floor(log(n) / log(2.0)) + 1];     }     arr[n - 1] = n - 1;     for (long long int i = 0; i < n - 1; i++) {       cin >> arr[i];       arr[i]--;     }     buildSparseTable(arr, n, sparse);     long long int dp[n];     dp[n - 1] = 0;     long long int sum = 0;     for (long long int i = n - 2; i >= 0; i--) {       long long int m = query(i + 1, arr[i], sparse, arr);       dp[i] = dp[m] - (arr[i] - m) + n - 1 - i;       sum += dp[i];     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e5 + 21;   long long n, m, a[maxN], cnt[maxN], ans;   bool p[maxN], f = true;   vector<long long> g[maxN];   int32_t main() {     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     queue<long long> q;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (!a[i]) q.push(i);     }     while (!q.empty()) {       long long i = q.front();       q.pop();       if (a[i] == cnt[i]) {         cnt[i]++, p[i] = true, ans++;         for (long long j = 0; j < g[i].size(); j++) {           long long u = g[i][j];           cnt[u]++;           if (a[u] == cnt[u]) q.push(u);         }       }     }     for (long long i = 1; i <= n; i++)       if (a[i] == cnt[i]) f = false;     if (!f)       cout << -1 << endl;     else {       cout << ans << endl;       for (long long i = 1; i <= n; i++) {         if (p[i]) cout << i <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, h, a, b, k, t1, f1, t2, f2;     scanf( %lld%lld%lld%lld%lld , &n, &h, &a, &b, &k);     while (k--) {       scanf( %lld%lld%lld%lld , &t1, &f1, &t2, &f2);       if (t1 == t2)         printf( %lld n , abs(f2 - f1));       else {         long long int ans = abs(t1 - t2);         if (f1 > b) {           ans += f1 - b;           f1 = b;         } else if (f1 < a) {           ans += a - f1;           f1 = a;         }         ans += abs(f2 - f1);         printf( %lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   long long a[100013];   long long mpow(long long x, int k) {     long long res = 1;     while (k) {       if (k & 1) {         res *= x;         res %= 1000000007;       }       x *= x;       x %= 1000000007;       k >>= 1;     }     return res;   }   int main() {     scanf( %d , &N);     long long a = 1, b = -1;     for (int i = int(0); i < int(N); i++) {       long long x;       scanf( %I64d , &x);       a *= x % (1000000007 - 1);       a %= (1000000007 - 1);       if ((x & 1) == 0) {         b = 1;       }     }     if (a == 0ll) {       a = 1000000007 - 1;     }     a--;     a = mpow(2, a);     long long x = a + b;     x *= mpow(3, 1000000007 - 2);     x %= 1000000007;     printf( %I64d/%I64d n , x, a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l[200010], r[200010], a[200010], b[200010], n, m;   long long sum = 1;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     int p = n - 1;     for (int i = m - 1; i >= 0; i--) {       while (p >= 0 && a[p] != b[i] && a[p] > b[i]) p--;       r[i] = p;       while (p >= 0 && a[p] >= b[i]) p--;       l[i] = p;       if (i > 0)         sum = 1LL * sum * (r[i] - l[i]) % 998244353;       else {         if (l[i] != -1 || r[i] == -1) sum = 0;       }     }     printf( %lld n , sum);   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n;     unsigned long long ans;     string str;     cin >> n >> str;     map<int, vector<int> > myMap;     myMap[0].push_back(0);     int cur = 0;     ans = 0;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  0 ) {       } else {         cur++;       }       if (cur >= n && myMap.count(cur - n) != 0) {         ans += myMap[cur - n].size();       }       myMap[cur].push_back(i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500500;   bool x[maxn];   int p[maxn], num[maxn], tmp[110];   int main() {     int n, q;     long long ans = 0;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , num + i + 1);     for (int u = 0; u < q; u++) {       int t, k, cnt = 0;       scanf( %d , &t);       k = num[t];       if (x[t]) {         for (int i = 2; i * i <= k; i++)           if (k % i == 0) {             tmp[cnt++] = i;             while (k % i == 0) k /= i;           }         if (k != 1) tmp[cnt++] = k;         for (int i = 0; i < (1 << cnt); i++) {           long long cur = 0;           int add = 0, mult = 1;           for (int j = 0; j < cnt; j++)             if (i & (1 << j)) mult *= tmp[j], add++;           p[mult]--;           cur = p[mult];           if (add & 1)             ans += cur;           else             ans -= cur;         }         x[t] = 0;       } else {         for (int i = 2; i * i <= k; i++)           if (k % i == 0) {             tmp[cnt++] = i;             while (k % i == 0) k /= i;           }         if (k != 1) tmp[cnt++] = k;         for (int i = 0; i < (1 << cnt); i++) {           long long cur = 0;           int add = 0, mult = 1;           for (int j = 0; j < cnt; j++)             if (i & (1 << j)) mult *= tmp[j], add++;           cur = p[mult];           p[mult]++;           if (add & 1)             ans -= cur;           else             ans += cur;         }         x[t] = 1;       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   const int INF = 1e9;   int n, m, cl, ce, v, q;   int a[maxn + 5], b[maxn + 5];   int main() {     scanf( %d%d%d%d%d , &n, &m, &cl, &ce, &v);     for (int i = 1; i <= cl; i++) scanf( %d , &b[i]);     for (int i = 1; i <= ce; i++) scanf( %d , &a[i]);     sort(a + 1, a + ce + 1);     sort(b + 1, b + cl + 1);     scanf( %d , &q);     while (q--) {       int Ax, Ay, Bx, By;       int Min = INF, t;       scanf( %d%d%d%d , &Ay, &Ax, &By, &Bx);       if (Ax > Bx) swap(Ax, Bx);       if (Ay > By) swap(Ay, By);       if (Ay == By) Min = min(Min, Bx - Ax);       int l = 1, r = ce, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (a[mid] <= Ax)           l = mid + 1, ans = mid;         else           r = mid - 1;       }       if (ans != 0)         t = (Ax - a[ans]) * 2 + (By - Ay + v - 1) / v + Bx - Ax;       else         t = INF;       Min = min(Min, t);       l = 1, r = cl, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (b[mid] <= Ax)           l = mid + 1, ans = mid;         else           r = mid - 1;       }       if (ans != 0)         t = (Ax - b[ans]) * 2 + By - Ay + Bx - Ax;       else         t = INF;       Min = min(Min, t);       l = 1, r = ce, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (a[mid] >= Ax)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0 && a[ans] <= Bx)         t = Bx - Ax + (By - Ay + v - 1) / v;       else         t = INF;       Min = min(Min, t);       l = 1, r = cl, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (b[mid] >= Ax)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0 && b[ans] <= Bx)         t = Bx - Ax + By - Ay;       else         t = INF;       Min = min(Min, t);       l = 1, r = ce, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (a[mid] >= Bx)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0)         t = (a[ans] - Bx) * 2 + Bx - Ax + (By - Ay + v - 1) / v;       else         t = INF;       Min = min(Min, t);       l = 1, r = cl, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (b[mid] >= Bx)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0)         t = (b[ans] - Bx) * 2 + Bx - Ax + By - Ay;       else         t = INF;       Min = min(Min, t);       printf( %d n , Min);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[300005];   int l[5005], r[5005];   long long dp[5005][5005];   const long long inf = 2e16;   void Min(long long &a, long long b) {     if (a > b) a = b;   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int cur = 0, tmp = n / k;     int c1 = n - tmp * k, c2 = k - c1;     for (int i = 0; i < 5005; i++)       for (int j = 0; j < 5005; j++) dp[i][j] = inf;     for (int i = 1; i <= k; i++) {       if (c1 < i)         r[i] = min(n, c1 * (tmp + 1) + (i - c1) * tmp);       else         r[i] = min(n, i * (tmp + 1));       if (c2 < i)         l[i] = min(n, c2 * tmp + (i - c2) * (tmp + 1));       else         l[i] = min(n, i * tmp);     }     dp[0][0] = 0;     for (int i = 1; i <= k; i++)       for (int j = l[i]; j <= r[i]; j++) {         int pre = j - tmp;         if (pre <= r[i - 1] && pre >= l[i - 1])           Min(dp[i][j - l[i]], dp[i - 1][pre - l[i - 1]] + a[j] - a[pre + 1]);         if (pre - 1 <= r[i - 1] && pre - 1 >= l[i - 1])           Min(dp[i][j - l[i]], dp[i - 1][pre - 1 - l[i - 1]] + a[j] - a[pre]);       }     printf( %d n , dp[k][n - l[k]]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200010];   int a[200010];   int ans[50];   int n, k, x;   void init() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i <= n; i++) a[i] = (int)s[i] -  a  + 1;     a[++n] = 30;     for (int i = 1; i <= 26; i++) {       int l;       bool flag = 0;       for (int j = 1; j <= n; j++) {         if (flag == 0 & a[j] == i) {           l = j;           flag = 1;         }         if (flag && a[j] != i) {           ans[i] += (j - l) / k;           flag = 0;         }       }     }   }   int main() {     init();     for (int i = 1; i <= 26; i++) x = max(ans[i], x);     cout << x;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int f, a, b;     scanf( %d , &f);     scanf( %d:%d , &a, &b);     if (b > 59) b %= 10;     if (a > f or a == 24) a %= 10;     if (a == 0 and f == 12) a = 10;     printf( %02d:%02d , a, b);   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int gcd(long long int a, long long int b) {     if (a < b)       return gcd(b, a);     else if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int isPrime(long long int n) {     long long int p = (long long int)sqrt(n);     for (int i = (2); i <= (p); i += (1))       if (n % i == 0) return 0;     return 1;   }   long long int pow(long long int b, long long int e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long int a = pow(b, e / 2);       return a * a;     } else {       long long int a = pow(b, e / 2);       return b * a * a;     }   }   long long int powm(long long int x, long long int y,                      long long int m = 1000000007) {     x = x % m;     long long int res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long int modInverse(long long int a, long long int m) {     return powm(a, m - 2, m);   }   int spf[10000005];   void sieve() {     spf[1] = 1;     for (int i = 2; i < 10000005; i++) spf[i] = i;     for (int i = 4; i < 10000005; i += 2) spf[i] = 2;     for (int i = 3; i * i < 10000005; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 10000005; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   void solve() {     sieve();     int n;     cin >> n;     vector<int> arr(n);     vector<pair<long long int, long long int>> ans(n);     for (int i = (0); i <= (n - 1); i += (1)) {       cin >> arr[i];       int x = arr[i];       vector<int> fac;       while (x != 1) {         int temp = spf[x];         fac.push_back(spf[x]);         while (x % temp == 0) x /= temp;       }       bool poss = 0;       ans[i] = {-1, -1};       if ((int)fac.size() > 1) {         int a = fac[0], b = 1;         for (int i = (1); i <= ((int)fac.size() - 1); i += (1)) b *= fac[i];         ans[i] = {a, b};       }     }     for (int i = (0); i <= (n - 1); i += (1)) cout << ans[i].first <<    ;     cout <<   n ;     for (int i = (0); i <= (n - 1); i += (1)) cout << ans[i].second <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   const int LIM = 1e5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, q, x, p;     cin >> n >> q;     for (int i = 0; i < q; i++) {       cin >> x;       p = (n - x) + x / 2;       while (x % 2 == 0) {         x += p;         p >>= 1;       }       cout << (x + 1) / 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void operator>>(istream& is, vector<T>& v) {     for (auto& e : v) {       is >> e;     }   }   template <class T>   void operator<<(ostream& os, const vector<T>& v) {     for (const auto& e : v) {       os << e <<    ;     }     os <<   n ;   }   long long LenToAns(long long len) { return len * (len + 1) / 2; }   struct Node {     int last;     int first;     int pref;     int suff;     int inf;     int size;     long long ans;   };   vector<Node> tree;   int n;   int n_full;   Node MakeNode(int v) { return {v, v, 1, 1, 1, 1, 1}; }   Node MakeNeutral() { return {0, 0, 0, 0, 0, 0, 0}; }   Node Merge(const Node& l, const Node& r) {     Node res;     res.first = l.first;     res.last = r.last;     res.pref = l.pref;     res.suff = r.suff;     res.inf = max(l.inf, r.inf);     res.ans = l.ans + r.ans;     if (l.last <= r.first) {       res.inf = max(res.inf, l.suff + r.pref);       res.ans += LenToAns(l.suff + r.pref);       res.ans -= LenToAns(l.suff);       res.ans -= LenToAns(r.pref);       if (l.pref == l.size) {         res.pref = l.size + r.pref;       }       if (r.pref == r.size) {         res.suff = l.suff + r.size;       }     }     res.size = l.size + r.size;     return res;   }   void Init(const vector<int>& a) {     n_full = 1;     while (n_full < n) {       n_full *= 2;     }     tree.resize(n_full * 2 - 1);     for (int i = 0; i < n; i++) {       tree[n_full + i - 1] = MakeNode(a[i]);     }     for (int i = n_full - 2; i >= 0; i--) {       tree[i] = Merge(tree[2 * i + 1], tree[2 * i + 2]);     }   }   void Set(int i, int v, int xi, int xl, int xr) {     if (xl > i || i >= xr) {       return;     }     if (xr - xl == 1) {       tree[xi] = MakeNode(v);       return;     }     int xm = (xl + xr) / 2;     Set(i, v, xi * 2 + 1, xl, xm);     Set(i, v, xi * 2 + 2, xm, xr);     tree[xi] = Merge(tree[xi * 2 + 1], tree[xi * 2 + 2]);   }   void Set(int i, int v) { Set(i, v, 0, 0, n_full); }   Node Sum(int l, int r, int xi, int xl, int xr) {     if (xl >= r || l >= xr) {       return MakeNeutral();     }     if (l <= xl && xr <= r) {       return tree[xi];     }     int xm = (xl + xr) / 2;     return Merge(Sum(l, r, xi * 2 + 1, xl, xm), Sum(l, r, xi * 2 + 2, xm, xr));   }   long long Sum(int l, int r) {     Node res = Sum(l, r, 0, 0, n_full);     return res.ans;   }   int main() {     int k;     cin >> n >> k;     vector<int> a(n);     cin >> a;     Init(a);     while (k--) {       int q;       cin >> q;       if (q == 1) {         int i, v;         cin >> i >> v;         i--;         Set(i, v);       } else {         int l, r;         cin >> l >> r;         l--;         cout << Sum(l, r) <<   n ;       }     }   }