#include // c #include // io #include #include #include #include // container #include #include #include #include #include #include // other #include #include #include #include #include using namespace std; using ll =long long; #define ALL(c) (begin(c)),(end(c)) #define REP(i,n) FOR(i,0,n) #define REPr(i,n) FORr(i,0,n) #define FOR(i,l,r) for(int i=(int)(l);i<(int)(r);++i) #define FORr(i,l,r) for(int i=(int)(r)-1;i>=(int)(l);--i) #define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it) #define IN(l,v,r) ((l)<=(v) && (v)<(r)) #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()) //debug #define DUMP(x) cerr << #x << " = " << (x) #define LINE() cerr<< " (L" << __LINE__ << ")" ll pmod(ll v,ll M){return (v%M+M)%M;} //[a,b)にxを加算 O(logN) [a,b)の最小値 O(logN) template struct RBST{ public: struct Node{ T v,sum;// 値,和 int sz;//部分木のサイズ Node *l,*r; Node(T v):v(v),sum(v),sz(1),l(NULL),r(NULL){ } }; int size(){return size(root);} int size(Node* t){return !t?0:t->sz;} T sum(Node* t){return !t?0:t->sum;} Node* root; RBST():root(NULL){}; Node* update(Node* t){ t->sz=size(t->l)+size(t->r)+1; t->sum=sum(t->l)+sum(t->r)+t->v; return t; } Node* merge(Node* l,Node* r){ if(!l || !r)return l?l:r; update(l);update(r); if(rand()%(size(l)+size(r))r = merge(l->r,r); return update(l); }else{ r->l = merge(l,r->l); return update(r); } } pair split(int k,Node* t){//[0,k) [k,n) if(!t)return {NULL,NULL}; update(t); if(k<=size(t->l)){ auto s=split(k,t->l); t->l=s.second; s.second=update(t); return s; }else{ auto s=split(k - (size(t->l)+1),t->r); t->r=s.first; s.first=update(t); return s; } } Node* insert(int k,T v){return root=insert(k,v,root);} Node* insert(int k,T v,Node* t){ auto s=split(k,t); return update(merge(merge(s.first,new Node(v)),s.second)); } Node* erase(int k){return root=erase(k,root);} Node* erase(int k,Node* t){ auto sr=split(k+1,t),sl=split(k,sr.first); return update(merge(sl.first,sr.second)); } Node* find(int k){return find(k,root);} Node* find(int k,Node* t){ update(t); if(k==size(t->l))return t; if(kl)) return find(k,t->l); else return find(k - size(t->l) - 1,t->r); } void add(int l,int r,T x){return add(l,r,x,root);} void add(int l,int r,T x,Node* t){ if(!t || size(t)<=l || r<=0)return; if(l<=0 && size(t) <=r){ t->v+=x; update(t); return; } add(l,r,x,t->l); if(l<=size(t->l) && size(t->l) < r) t->v += x; add(l- size(t->l) -1,r- size(t->l) -1,x,t->r); update(t); } T query(int l,int r){return query(l,r,root);} T query(int l,int r,Node* t){ if(!t || size(t)<=l || r<=0)return 0; // cerr << make_tuple(l,r,t->sum)<l) + query(l- size(t->l) -1,r- size(t->l) -1,t->r); if(l<=size(t->l) && size(t->l) < r) res += t->v; return res; } }; class Main{ public: void run(){ int N,Q;cin >> N >> Q; RBST L,R; REP(i,N)L.insert(i,0); REP(i,N)R.insert(i,0); REP(t,Q){ char x;ll y,z;cin >> x >> y >> z; if(x=='L')L.add(y,y+1,z); if(x=='R')R.add(y,y+1,z); if(x=='C'){ cout << L.query(y,z) + R.query(y,z)<v; ll rv=R.find(N-1)->v; L.erase(0);L.insert(N-1,rv); R.erase(N-1);R.insert(0,lv); } } }; int main(){ cout <