#include<iostream> #include<cstdio> #define maxn 400010 #define ll long long usingnamespacestd;
int m, cnt;
int f[maxn][21], nxt[maxn][21];
ll mx[maxn][21], a[maxn], sum[maxn][21];
int lans; inlinevoidsolve_1(){ ll u, w, v; cin >> u >> w; u ^= lans; w ^= lans; v = ++cnt; f[v][0] = u; a[v] = w; mx[v][0] = a[u]; for (int i = 1; i <= 20; ++i) f[v][i] = f[f[v][i - 1]][i - 1]; for (int i = 1; i <= 20; ++i) mx[v][i] = max(mx[f[v][i - 1]][i - 1], mx[v][i - 1]); u = v; for (int i = 20; ~i; --i) if (f[u][i] && mx[u][i] < w) u = f[u][i]; nxt[v][0] = f[u][0]; sum[v][0] = a[nxt[v][0]]; for (int i = 1; i <= 20; ++i) nxt[v][i] = nxt[nxt[v][i - 1]][i - 1]; for (int i = 1; i <= 20; ++i) sum[v][i] = sum[nxt[v][i - 1]][i - 1] + sum[v][i - 1]; }
inlinevoidsolve_2(){ ll u, w; cin >> u >> w; u ^= lans; w ^= lans; if (w < a[u]) return (void) (cout << (lans = 0) << "\n"); lans = 1; w -= a[u]; for (int i = 20; ~i; --i) if (nxt[u][i] && w >= sum[u][i]) w -= sum[u][i], u = nxt[u][i], lans += 1 << i; cout << lans << "\n"; }