从来没见过 72 pts 的
#include<bits/stdc++.h>
#define int long long
#define PII pair< int, int >
using namespace std;
const int N = 1e5 + 5, mod = 998244353;
int n, tot, rt, a, b, c;
struct node{
int val, key, siz;
int lson, rson;
} t[N];
struct {
int New(int x){
t[++tot].val = x;
t[tot].key = 1ll * rand() * rand() % mod;
t[tot].siz = 1;
t[tot].lson = t[tot].rson = 0;
return tot;
}
void update(int x){
if (x == 0) return ;
t[x].siz = t[t[x].lson].siz + t[t[x].rson].siz + 1;
}
void split(int now, int &a, int &b, int k){
if (now == 0){
a = b = 0;
return ;
}
if (t[now].val <= k){
a = now;
split(t[now].rson, t[a].rson, b, k);
}
else {
b = now;
split(t[now].lson, a, t[b].lson, k);
}
update(now);
}
void merge(int &now, int a, int b){
if (a == 0 || b == 0){
now = a + b;
return ;
}
if (t[a].key >= t[b].key){
now = a;
merge(t[now].rson, t[a].rson, b);
}
else {
now = b;
merge(t[now].lson, a, t[b].lson);
}
update(now);
}
int query(int rt, int k){
int now = rt;
while(true){
if (k <= t[t[now].lson].siz) now = t[now].lson;
else if (k > t[t[now].lson].siz + 1){
k -= t[t[now].lson].siz + 1;
now = t[now].rson;
}
else return t[now].val;
}
}
} FHQ_treap;
template< typename T >inline void read(T &x){bool f=1;x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=!f;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}x=(f?x:-x);return;}
template< typename T, typename ... L > void read(T &a , L && ... b) { read(a); read(b ...); }
int ksm(int a, int b, int p){int ans = 1;while(b){if(b & 1)ans =(ans*a)%p;b >>= 1;a = (a*a) % p;}return ans;}
signed main(){
// freopen("a.in", "r", stdin);
// freopen("a.out","w",stdout);
srand(time(0));
read(n);
while (n--){
int op, x;
read(op, x);
if (op == 1){
int now = FHQ_treap.New(x);
FHQ_treap.split(rt, a, b, x);
FHQ_treap.merge(a, a, now);
FHQ_treap.merge(rt, a, b);
}
if (op == 2){
FHQ_treap.split(rt, a, b, x);
FHQ_treap.split(a, a, c, x - 1);
FHQ_treap.merge(c, t[c].lson, t[c].rson);
FHQ_treap.merge(rt, a, c);
FHQ_treap.merge(rt, rt, b);
}
if (op == 3){
FHQ_treap.split(rt, a, b, x - 1);
printf("%lld\n", t[a].siz + 1);
FHQ_treap.merge(rt, a, b);
}
if (op == 4){
printf("%lld\n", FHQ_treap.query(rt, x));
}
if (op == 5){
FHQ_treap.split(rt, a, b, x - 1);
printf("%lld\n", FHQ_treap.query(a, t[a].siz));
FHQ_treap.merge(rt, a, b);
}
if (op == 6){
FHQ_treap.split(rt, a, b, x + 1);
printf("%lld\n", FHQ_treap.query(b, 1));
FHQ_treap.merge(rt, a, b);
}
}
return 0;
}