malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e8;   const int MX = 2e5 + 5;   vector<int> vorder;   int dup[MX], lc[MX], rc[MX], good[MX], seek[MX];   string labels, corder;   void ino(int curr) {     if (curr == -1) return;     ino(lc[curr]);     vorder.push_back(curr);     corder += labels[curr];     ino(rc[curr]);   }   void dfs1(int curr) {     if (curr == -1) return;     seek[curr] = INF;     dfs1(lc[curr]);     dfs1(rc[curr]);     if (lc[curr] != -1) seek[curr] = 1 + seek[lc[curr]];     if (good[curr]) seek[curr] = 1;   }   int dfs2(int curr, int k) {     if (curr == -1) return k;     if (seek[curr] <= k) {       k--;       dup[curr] = 1;       k = dfs2(lc[curr], k);       return dfs2(rc[curr], k);     }     return k;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     cin >> labels;     for (int i = 0; i < n; i++) {       cin >> lc[i] >> rc[i];       lc[i]--;       rc[i]--;     }     ino(0);     corder +=  @ ;     char last;     for (int i = n - 1; i >= 0; i--) {       if (corder[i] != corder[i + 1]) last = corder[i + 1];       good[vorder[i]] = corder[i] < last;     }     memset(dup, 0, sizeof dup);     dfs1(0);     dfs2(0, k);     for (int v : vorder) {       if (dup[v])         cout << labels[v] << labels[v];       else         cout << labels[v];     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     if (n % 3) {       cout << 0;       return 0;     }     n /= 3;     vector<long long> d;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         d.push_back(i);       }     }     sort(d.begin(), d.end());     long long r = 0;     for (int i = 0; i < d.size(); i++) {       for (int j = i; j < d.size(); j++) {         if (n % (d[i] * d[j]) == 0 && n / (d[i] * d[j]) >= d[j]) {           long long ab = d[i], bc = d[j], ac = n / (d[i] * d[j]);           long long a = ab + ac - bc, b = ab - ac + bc, c = -ab + ac + bc;           if (a % 2 + b % 2 + c % 2 == 0 && a / 2 > 0 && b / 2 > 0 && c / 2 > 0) {             a /= 2, b /= 2, c /= 2;             if (a == b && b == c) {               r++;             } else if (a == b || b == c || a == c) {               r += 3;             } else               r += 6;           }         }       }     }     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int64_t a, b, x, y, z;     scanf( %I64d%I64d%I64d%I64d%I64d , &a, &b, &x, &y, &z);     int64_t addA, addB;     if (2LL * x + y - a > 0)       addA = 2LL * x + y - a;     else       int64_t addA = 0;     if (3LL * z + y - b > 0)       addB = 3LL * z + y - b;     else       addB = 0;     printf( %I64d n , addA + addB);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, i, j, k, l;     cin >> n >> m;     string s, t;     cin >> s >> t;     if (s == t) {       cout <<  Yes  << endl;       return 0;     }     long long int present = 0;     long long int flag = 0;     for (i = 0; i < s.length(); i++) {       if (s[i] ==  * ) {         present = 1;         break;       }     }     if (present == 0) {       cout <<  No  << endl;       return 0;     } else {       for (i = 0; i < s.length(); i++) {         if (s[i] ==  * ) {           break;         } else if (s[i] != t[i]) {           flag = 1;           break;         } else {           t[i] =  X ;         }       }     }     if (flag == 0) {       long long int ind = t.length() - 1;       for (i = s.length() - 1; i >= 0; i--) {         if (s[i] ==  * ) {           break;         }         if (s[i] != t[ind]) {           flag = 1;           break;         }         ind--;       }     }     if (flag == 0) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool eq(long double l1, long double l2) { return abs(l1 - l2) < 1e-15; }   int main() {     const string names[] = { Vanya ,  Vova ,  Both };     vector<pair<long double, char>> v;     int n, x, y;     cin >> n >> x >> y;     for (int i = 1; i <= x; i++) {       v.push_back({(long double)i / (long double)x, 0});     }     for (int i = 1; i <= y; i++) {       v.push_back({(long double)i / (long double)y, 1});     }     sort(v.begin(), v.end(),          [](pair<long double, char> a1, pair<long double, char> a2) {            return a1.first < a2.first;          });     for (int i = 0; i < v.size() - 1; i++) {       if (eq(v[i].first, v[i + 1].first)) {         v[i].second = 2;         v[++i].second = 2;       }     }     int a;     for (int i = 0; i < n; i++) {       cin >> a;       if (a > x + y) {         a %= (x + y);         if (a == 0) a = x + y;       }       cout << names[v[a - 1].second] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   const long long inf = 1e17;   long long v[N];   long long c[N];   long long dp[N];   bool mark[N];   long long n, q;   long long a, b;   void solver() {     cin >> a >> b;     long long max1 = 0;     long long color1 = 0;     long long max2 = 0;     long long color2 = 1;     for (long long i = 0; i < N; i++) {       dp[i] = -inf;       mark[i] = 0;     }     for (long long i = 0; i < n; i++) {       long long color = c[i];       long long value = v[i];       long long maxi = max1;       if (color1 == color) {         maxi = max2;       }       if (mark[color]) {         dp[color] = max(dp[color], dp[color] + value * a);       }       dp[color] = max(dp[color], maxi + value * b);       mark[color] = true;       if (color != color1 && color != color2) {         if (dp[color] > max1) {           max2 = max1;           color2 = color1;           max1 = dp[color];           color1 = color;           continue;         }         if (dp[color] > max2) {           max2 = dp[color];           color2 = color;         }       }       if (color == color1) {         max1 = dp[color];         color1 = color;       }       if (color == color2) {         max2 = dp[color];         if (max2 > max1) {           swap(max2, max1);           swap(color1, color2);         }       }     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       ans = max(ans, dp[i]);     }     cout << ans << endl;   }   int main() {     cin >> n >> q;     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     for (long long i = 0; i < n; i++) {       cin >> c[i];     }     for (long long i = 0; i < q; i++) {       solver();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.precision(10);     cout << fixed;     int n, neg = 0;     cin >> n;     vector<int> a(2 * n - 1);     bool zero = false;     long long sum = 0;     for (int i = 0; i < 2 * n - 1; ++i) {       cin >> a[i];       if (a[i] == 0)         zero = true;       else if (a[i] < 0)         neg++, a[i] *= -1;       sum += a[i];     }     neg %= n;     if (zero) neg = 0;     vector<bool> vis(2 * n);     queue<int> q;     q.push(neg);     vis[neg] = 1;     int ans = neg;     while (!q.empty()) {       int k = q.front();       q.pop();       if (k % n == 0) {         ans = 0;         break;       }       ans = min(ans, k);       for (int x = 2 * n - 1 - k; x >= n - k; --x) {         int k2 = k + 2 * x - n;         if (k2 > 0 && k2 < 2 * n && !vis[k2]) {           vis[k2] = 1;           q.push(k2);         }       }     }     sort(begin(a), end(a));     for (int i = 0; i < ans; ++i) sum -= 2 * a[i];     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   int t, h[2000010], v[2000010 * 2], nxt[2000010 * 2], ec, in[2000010], n, a, b;   char s[2000010];   void add(int x, int y) {     v[++ec] = y;     in[y]++;     nxt[ec] = h[x];     h[x] = ec;   }   void adj(int x, int y) {     add(x, y);     add(y, x);   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       ec = 0;       memset(h, 0, sizeof(int) * (n + 5));       memset(in, 0, sizeof(int) * (n + 5));       for (int i = 1; i < n; i++) {         scanf( %d%d , &a, &b);         adj(a, b);       }       scanf( %s , s + 1);       if (n < 3) {         printf( Draw n );         continue;       }       if (n == 3) {         int c = 0;         for (int i = 1; i <= n; i++)           if (s[i] ==  W ) c++;         if (c >= 2)           printf( White n );         else           printf( Draw n );         continue;       }       int ct = 0, r = 0, on = n;       for (int i = 1; i <= on; i++)         if (s[i] ==  W ) {           add(i, ++n);           h[n] = 0;           add(n, i);           in[n] = 3;         }       for (int i = 1; i <= n; i++) {         if (in[i] > 3)           r = 1;         else if (in[i] == 3) {           ct++;           int cc = 0;           for (int j = h[i]; j; j = nxt[j])             if (in[v[j]] >= 2) cc++;           r |= cc >= 2;         }       }       if (ct == 2 && (n & 1)) r = 1;       printf(r ?  White n  :  Draw n );     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void prn(Arg1&& arg1) {     cout << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void prn(Arg1&& arg1, Args&&... args) {     cout << arg1 <<    ;     prn(args...);   }   template <typename Arg1>   void prs(Arg1&& arg1) {     cout << arg1 <<    ;   }   template <typename Arg1, typename... Args>   void prs(Arg1&& arg1, Args&&... args) {     cout << arg1 <<    ;     prs(args...);   }   template <typename Arg1>   void read(Arg1&& arg1) {     cin >> arg1;   }   template <typename Arg1, typename... Args>   void read(Arg1&& arg1, Args&&... args) {     cin >> arg1;     read(args...);   }   long long n, k;   void solve() {     read(n, k);     long long sum = 0, invariant = 0;     for (int i = 0; i < k; ++i) {       long long a, b;       read(a, b);       sum += b;       invariant = (invariant + a * b) % n;     }     if (sum < n) {       prn(1);       return;     }     if (sum > n) {       prn(-1);       return;     }     if (invariant != (n * (n + 1) / 2) % n) {       prn(-1);       return;     }     prn(1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int tc = 1; tc <= t; ++tc) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   const int V = 1e6, M = 1e9 + 7;   struct edge {     int v, c, nxt;   } g[V];   int n, m, k, t, dep[V], q[V], l, r, d[7], head[V], dis[V], a1[V], a2[V], a3[V];   std::vector<int> h[V];   inline void Insert(int u, int v, int c) {     g[++k] = (edge){v, c, head[u]};     head[u] = k;   }   bool Cmp(const int& u, const int& v) {     return a1[u] == a1[v] ? a2[u] < a2[v] : a1[u] < a1[v];   }   int main() {     int u, v;     scanf( %d%d , &n, &m);     t = n;     for (int j = 1; j <= m; j++) {       scanf( %d%d , &u, &v);       r = 0;       for (int jj = j; jj; jj /= 10) d[++r] = jj % 10;       if (r == 1)         Insert(u, v, d[1]), Insert(v, u, d[1]);       else {         Insert(u, ++t, d[r]);         for (int jj = r - 1; jj >= 2; jj--) Insert(t, t + 1, d[jj]), ++t;         Insert(t, v, d[1]);         Insert(v, ++t, d[r]);         for (int jj = r - 1; jj >= 2; jj--) Insert(t, t + 1, d[jj]), ++t;         Insert(t, u, d[1]);       }     }     q[l = r = 0] = 1;     dep[1] = 1;     for (; l <= r;) {       u = q[l++];       h[dep[u]].push_back(u);       for (int i = head[u]; i; i = g[i].nxt)         if (!dep[v = g[i].v]) q[++r] = v, dep[v] = dep[u] + 1;     }     dis[1] = 0;     memset(a1, 1, sizeof a1);     memset(a2, 1, sizeof a2);     for (int j = 1; h[j].size(); j++) {       std::sort(h[j].begin(), h[j].end(), Cmp);       r = 0;       for (int i = 0; i < h[j].size(); i++) {         u = h[j][i];         if (!i || a1[u] != a1[h[j][i - 1]] || a2[u] != a2[h[j][i - 1]]) ++r;         a3[u] = r;         for (int i = head[u]; i; i = g[i].nxt)           if (dep[v = g[i].v] > dep[u] &&               (a3[u] < a1[v] || a3[u] == a1[v] && g[i].c < a2[v]))             a1[v] = a3[u], a2[v] = g[i].c, dis[v] = (dis[u] * 10ll + g[i].c) % M;       }     }     for (u = 2; u <= n; u++) printf( %d n , dis[u]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n + 1];     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     int sums = 0;     int sumd = 0;     bool turns = true;     int l = 0, r = n - 1;     while (l <= r) {       if (turns) {         sums += max(arr[l], arr[r]);         turns = false;         arr[l] > arr[r] ? l++ : r--;       } else {         sumd += max(arr[l], arr[r]);         turns = true;         arr[l] > arr[r] ? l++ : r--;       }     }     cout << sums <<     << sumd << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int big = 1e9;   int dp[83][83][83][83], d[100][100];   int s[100][100][100], s1[100][100][100];   int n, kt, m, u, v, c;   int main() {     cin >> n >> kt >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) d[i][j] = -1;     for (int i = 1; i <= m; i++) {       cin >> u >> v >> c;       if (d[u][v] == -1)         d[u][v] = c;       else         d[u][v] = min(d[u][v], c);     }     for (int k = 1; k <= kt; k++)       for (int i = 0; i <= n + 1; i++)         for (int j = 0; j < i; j++)           for (int l = i + 1; l <= n + 1; l++) dp[k][i][j][l] = -1;     for (int k = 1; k <= kt; k++)       for (int i = 0; i <= n + 1; i++)         for (int j = 0; j <= n + 1; j++) {           s[k][i][j] = big;           s1[k][i][j] = big;         }     for (int k = 1; k <= kt; k++) {       for (int i = 1; i <= n; i++)         for (int j = 0; j < i; j++)           for (int l = i + 1; l <= n + 1; l++) {             if (j != 0 || k == 1)               if (d[j][i] > -1 && s[k - 1][j][l] != big)                 dp[k][i][j][l] = s[k - 1][j][l] + d[j][i];             if (l != n + 1 || k == 1)               if (d[l][i] > -1 && s1[k - 1][l][j] != big) {                 if (dp[k][i][j][l] == -1)                   dp[k][i][j][l] = s1[k - 1][l][j] + d[l][i];                 else                   dp[k][i][j][l] = min(dp[k][i][j][l], s1[k - 1][l][j] + d[l][i]);               }           }       for (int i = 1; i <= n; i++)         for (int j = 0; j < i; j++)           for (int l = i + 1; l <= n + 1; l++)             if (dp[k][i][j][l] != -1)               s[k][i][l] = min(s[k][i][l], dp[k][i][j][l]);       for (int i = 1; i <= n; i++)         for (int j = 0; j < i; j++)           for (int l = i + 1; l <= n + 1; l++)             if (dp[k][i][j][l] != -1)               s1[k][i][j] = min(s1[k][i][j], dp[k][i][j][l]);     }     int mini = 1e9;     for (int i = 1; i <= n; i++)       for (int j = 0; j < i; j++)         for (int l = i + 1; l <= n + 1; l++)           if (dp[kt][i][j][l] != -1) mini = min(mini, dp[kt][i][j][l]);     if (mini == 1e9)       printf( -1 n );     else       printf( %d n , mini);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[100005];   map<int, int> mymap;   int main() {     int n;     map<int, int>::iterator it;     int d;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];       mymap[A[i]]++;       d = A[i];       while (mymap[d] % 2 == 0) {         mymap[d + 1]++;         mymap[d] = mymap[d] - 2;         d = d + 1;       }     }     int c = 0;     for (it = mymap.begin(); it != mymap.end(); it++) {       if (it->second == 1) c++;     }     it--;     cout << it->first - c + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string col[1000];   int main() {     cin >> n >> col[0];     for (int i = 1; i < 1000; ++i) col[i] = col[0];     for (int i = 0, a, b; i < n; ++i) {       scanf( %d%d , &a, &b);       char now = col[0][i];       for (int j = b; j < 1000; j += a) {         now =  0  +  1  - now;         for (int t = j; t < min(1000, j + a); ++t) col[t][i] = now;       }     }     int ans = 0;     for (int i = 0; i < 1000; ++i)       ans = max(ans, (int)count(col[i].begin(), col[i].end(),  1 ));     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int a[1000000 + 5];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       bool can = false;       for (int i = 1; i < n; i++) {         if (a[i] >= a[i - 1]) {           can = true;           break;         }       }       if (can)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int r, c;   string s;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> r >> c;     while (r--) cin >> s;     long long int ans = 0;     for (long long int i = 0; i <= c - 1; ++i) {       if (s[i] !=  B ) continue;       ans++;       while (i <= c - 1 && s[i] ==  B ) i++;     }     cout << ans;   }
#include <bits/stdc++.h>   long long p[2750131 + 5];   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long left = 0, right = n - 1, past = 0;     string s =   ;     long long flag = 1;     while (left < right && flag) {       if (a[left] < a[right]) {         if (a[left] > past) {           s +=  L ;           past = a[left];           left++;         } else if (a[right] > past) {           s +=  R ;           past = a[right];           right--;         } else {           flag = 0;         }       } else if (a[right] < a[left]) {         if (a[right] > past) {           s +=  R ;           past = a[right];           right--;         } else if (a[left] > past) {           s +=  L ;           past = a[left];           left++;         } else {           flag = 0;         }       } else {         if (a[left] <= past) {           flag = 0;           continue;         }         past = a[left];         left++;         long long sum1 = 1;         while (a[left] > past) {           sum1++;           past = a[left];           left++;         }         past = a[right];         right--;         long long sum2 = 1;         while (a[right] > past) {           sum2++;           past = a[right];           right--;         }         if (sum1 > sum2) {           while (sum1--) {             s +=  L ;           }         } else {           while (sum2--) {             s +=  R ;           }         }         flag = 0;       }     }     if (left == right && flag && a[left] > past) {       s +=  L ;     }     cout << s.size() <<   n ;     cout << s <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   char s[5010];   long long dp[5010][5010];   bool vis[5010][5010];   long long f(int i, int ind, int n) {     if (vis[i][ind]) return dp[i][ind];     if (i > n) {       if (ind == 0) return 1;       return 0;     }     long long ans = 0;     vis[i][ind] = true;     if (s[i] ==  f )       ans = f(i + 1, ind + 1, n);     else {       ans = f(i + 1, ind, n);       if (ind > 0) ans = (ans + f(i, ind - 1, n)) % mod;     }     dp[i][ind] = ans;     return ans;   }   int main() {     int i, j, n;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf(  %c , &s[i]);     printf( %lld n , f(1, 0, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int l[maxn], r[maxn], a[maxn], pos[40];   map<int, int> m;   int main() {     int n;     scanf( %d , &n);     long long ans = (long long)n * (n + 1) / 2;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       l[i] = m[a[i]];       for (int j = 0; j < 32; j++) {         if (!(a[i] & (1 << j))) {           l[i] = max(l[i], pos[j]);         }       }       for (int j = 0; j < 32; j++) {         if ((a[i] & (1 << j))) {           pos[j] = i;         }       }       m[a[i]] = i;     }     for (int i = 0; i <= 32; i++) pos[i] = n + 1;     for (int i = 1; i <= n; i++) r[i] = n + 1;     for (int i = n; i > 0; i--) {       for (int j = 0; j < 32; j++) {         if (!(a[i] & (1 << j))) {           r[i] = min(r[i], pos[j]);         }       }       for (int j = 0; j < 32; j++) {         if ((a[i] & (1 << j))) {           pos[j] = i;         }       }       long long t = 1LL * (i - l[i]) * (r[i] - i);       ans -= t;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double ans = 0.0000;   void bfs();   list<int> arr[100005];   int visited[100005], dep[100005];   int main() {     int n, i, start, end;     cin >> n;     n--;     while (n--) {       cin >> start;       cin >> end;       arr[start].push_back(end);       arr[end].push_back(start);     }     bfs();     cout.precision(7);     cout << fixed << ans;     return 0;   }   void bfs() {     int node;     dep[1] = 1;     queue<int> qu;     list<int>::iterator iter = arr[1].begin();     node = 1;     visited[1] = 1;     qu.push(1);     while (!qu.empty()) {       for (iter = arr[node].begin(); iter != arr[node].end(); ++iter) {         if (!visited[*iter]) {           qu.push(*iter);           visited[*iter] = 1;           dep[*iter] = dep[node] + 1;         }       }       int k = qu.front();       qu.pop();       node = qu.front();       ans += 1 / (double)dep[k];     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vv;   int main() {     int t, n, x, c1, c2;     scanf( %d , &t);     vv.clear();     c1 = c2 = 0;     for (int i = 0; i < t; i++) {       scanf( %d , &n);       for (int j = 0; j < n / 2; j++) {         scanf( %d , &x);         c1 += x;       }       if (n % 2) {         scanf( %d , &x);         vv.push_back(x);       }       for (int j = 0; j < n / 2; j++) {         scanf( %d , &x);         c2 += x;       }     }     sort(vv.begin(), vv.end());     int flag = 1;     for (int i = vv.size() - 1; i >= 0; i--) {       if (flag == 1)         c1 += vv[i];       else         c2 += vv[i];       flag = -flag;     }     printf( %d %d n , c1, c2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int CNT[7002];   struct seg {     seg(int _l, int _r, int _val) : l(_l), r(_r), val(_val){};     int l, r, val;   };   vector<seg> q[7002];   int pw2[200002];   int up(int lev, int pos) {     int l = 0, r = 200000;     while (r - l > 1) {       int m = (l + r) >> 1;       if (m + pw2[m] >= pos)         r = m;       else         l = m;     }     return r;   }   int down_l(int lev, int pos) { return pos - 1 + pw2[pos - 1] + 1; }   int down_r(int lev, int pos) { return pos + pw2[pos]; }   int find(int lev, int pos) {     set<int> ret;     int l = pos, r = pos;     for (; lev <= 7000; ++lev) {       for (int j = 0; j < q[lev].size(); ++j) {         if (q[lev][j].r < l || q[lev][j].l > r)           ;         else {           ret.insert(q[lev][j].val);         }       }       l = down_l(lev, l);       r = down_r(lev, r);     }     return ret.size();   }   int main() {     for (int i = 0; (1 << i) <= 200000; ++i) {       pw2[1 << i] = 1;     }     for (int i = 1; i <= 200000; ++i) {       pw2[i] += pw2[i - 1];     }     int n, m;     scanf( %d%d , &n, &m);     int cnt = 1, total = 1;     CNT[1] = 1;     for (int i = 2; i <= n; ++i) {       int my = 0, pw = 1;       while (pw <= cnt) {         ++my;         pw <<= 1;       }       cnt = 2 * my + cnt - my;       total += cnt;       CNT[i] = cnt;     }     for (int i = 0; i < m; ++i) {       int t, lev, l, r, x, pos;       scanf( %d , &t);       if (t == 1) {         scanf( %d%d%d%d , &lev, &l, &r, &x);         q[lev].push_back(seg(l, r, x));       } else {         scanf( %d%d , &lev, &pos);         printf( %d n , find(lev, pos));       }     }     return 0;   }