#include <bits/stdc++.h>
using namespace std;
ifstream f("secv8.in");
ofstream g("secv8.out");
const int MOD = 1e9 + 7;
struct nod{
nod *st, *dr;
int prior;
int val;
int sz;
bool rev;
};
nod *nil= new nod;
nod *reverse1(nod *n)
{
swap(n->st,n->dr);
n->rev=!n->rev;
return n;
}
nod *propag (nod *n)
{
if (n!=nil&&n->rev==true)
{
n->st=reverse1(n->st);
n->dr=reverse1(n->dr);
n->rev=false;
}
return n;
}
nod *mod_fiu (nod *n , int care ,nod *fiu)
{
if (care==0)
{
n->st=fiu;
}
else
{
n->dr=fiu;
}
n->sz=n->st->sz+1+n->dr->sz;
return n;
}
nod *join (nod *st , nod *dr)
{
st=propag(st);
dr=propag(dr);
if (st==nil)
{
return dr;
}
if (dr==nil)
{
return st;
}
if (st->prior>=dr->prior)
{
return mod_fiu(st,1,join(st->dr,dr));
}
else
{
return mod_fiu(dr,0,join(st,dr->st));
}
}
pair <nod*,nod*> split (nod *n , int k)
{
n=propag(n);
if (n==nil)
{
return {nil,nil};
}
if (n->st->sz>=k)
{
/*n=[st]++[dr]
n=[x]++[y]++[dr] , join(x,y)=n->st [x] are k elemente?
*/
auto t=split( n->st, k);
return make_pair(t.first,mod_fiu(n,0,t.second));
}
else
{
/*n=[st]++[x]++[y] , join(x,y)= n->dr [x] are k-n->st elemente
*/
auto t=split(n->dr,k- n->st->sz -1);
return make_pair(mod_fiu(n,1,t.first),t.second);
}
}
int acces (nod *T, int poz) {
T = propag(T);
auto t = split(T, poz+1);
auto t_ = split(t.first, poz);
T = join(join(t_.first, t_.second), t.second);
return t_.second->val;
}
nod *invers (nod *n, int x, int y) {
n = propag(n);
auto t = split(n, y+1);
auto t_ = split(t.first, x);
t_.second = reverse1(t_.second);
return join(join(t_.first, t_.second), t.second);
}
nod *adaug (nod *n, int poz, int val) {
n = propag(n);
pair <nod*, nod*> S = split(n, poz);
nod *now = new nod;
*now = nod{nil, nil, ((rand() << 15) + rand()) % MOD, val, 1, 0};
return join(join(S.first, now), S.second);
}
nod *delete1(nod *n, int x,int y)
{
n=propag(n);
auto t=split (n,y+1);
auto t_= split (t.first,x);
return join(t_.first,t.second);
}
void afisare (nod *n)
{
if (n==nil)
{
return;
}
afisare(n->st);
g<<n->val<<" ";
afisare(n->dr);
}
int q,i,poz,val,st,dr,p;
char tip;
int main()
{
srand(65464563);
nod *n=nil;
f>>q>>p;
for (i=1;i<=q;i++)
{
f>>tip;
if (tip=='I')
{
f>>poz>>val;
poz--;
n=adaug(n,poz,val);
}
else
if (tip=='D')
{
f>> st >>dr;
st--;
dr--;
n=delete1(n,st,dr);
}
else
if (tip=='R')
{
f>> st>> dr;
st--;
dr--;
n=invers(n,st,dr);
}
else
if (tip=='A')
{
f>>poz;
poz--;
g<<acces(n,poz)<<'\n';
}
}
afisare(n);
return 0;
}