#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   int lca[400100][20];   int len[400100];   long long s[400100][20];   int w[400100];   int main() {     ios::sync_with_stdio(false);     int Q;     cin >> Q;     int cnt = 0;     int last = 0;     len[0] = 1;     for (long long q = 0; q < (long long)(Q); ++q) {       int t, x;       long long y;       cin >> t >> x >> y;       x ^= last;       --x;       y ^= last;       if (t == 1) {         ++cnt;         w[cnt] = y;         for (int i = 20 - 1; i >= 0; --i) {           if (w[lca[x][i]] < y) {             x = lca[x][i];           }         }         if (w[x] < y) {           x = lca[x][0];         }         if (w[x] < y) {           x = cnt;         }         lca[cnt][0] = x;         len[cnt] = len[x] + 1;         s[cnt][0] = y;         for (long long i = 0; i < (long long)(20 - 1); ++i) {           lca[cnt][i + 1] = lca[lca[cnt][i]][i];           s[cnt][i + 1] = s[cnt][i] + s[lca[cnt][i]][i];         }       } else {         last = 0;         int upp = len[x];         for (int i = 20 - 1; i >= 0; --i) {           if (s[x][i] <= y) {             y -= s[x][i];             x = lca[x][i];             last += 1 << i;           }         }         last = min(last, upp);         cout << last << endl;       }     }     return 0;   }   