#include using namespace std; #define int long long struct RBST{ struct node{ node *lch,*rch; int val,sum,cnt; node(int val):val(val),sum(sum),cnt(1),lch(NULL),rch(NULL){} }; node *root; RBST():root(NULL){} inline int count(node *t){return t?t->cnt:0;} inline int sum(node *t){return t?t->sum:0;} node *update(node *t){ if(!t)return t; t->cnt=count(t->lch)+count(t->rch)+1; t->sum=sum(t->lch)+sum(t->rch)+t->val; return t; } node *merge(node *a,node *b){ if(!a)return b; if(!b)return a; if(rand()%(count(a)+count(b))rch=merge(a->rch,b); return update(a); } else{ b->lch=merge(a,b->lch); return update(b); } } pairsplit(node *t,int k){ if(!t)return make_pair(t,t); if(k<=count(t->lch)){ pairs=split(t->lch,k); t->lch=s.second; return make_pair(s.first,update(t)); } else{ pairs=split(t->rch,k-count(t->lch)-1); t->rch=s.first; return make_pair(update(t),s.second); } } void insert(int k,int x){ pairs=split(root,k); root=merge(merge(s.first,new node(x)),s.second); } int erase(int k){ pairs1,s2; int ret; s1=split(root,k); s2=split(s1.second,1); ret=s2.first->val; root=merge(s1.first,s2.second); return ret; } int sum(int l,int r){ pairs1,s2; int ret; s1=split(root,l); s2=split(s1.second,r-l); ret=s2.first->sum; root=merge(merge(s1.first,s2.first),s2.second); return ret; } }; int N,Q; RBST L,R; signed main(){ cin>>N>>Q; for(int i=0;i>type>>x>>y; if(type=='L'){ int val=L.erase(x); L.insert(x,val+y); } else if(type=='R'){ int val=R.erase(x); R.insert(x,val+y); } else{ cout<