#include<cstdio>
#include<cstdlib>
const int B=10,B2=B*2,M=32768,N=100111;
typedef long long i64;
i64 _a;
#define lc c[0]
#define rc c[1]
struct node{
int v[B2];
node*c[2];
i64 s2;
int sz,len,rnd,s1;
void init(int D){
lc=rc=0;
sz=len=D;
rnd=rand();
s2=s1;
}
void read(int D){
init(D);
s1=0;
for(int i=0;i<len;++i)scanf("%d",v+i),s1+=v[i];
s2=s1;
}
void get(node*a){
init(B);
s1=0;
for(int i=0,*b=a->v+B;i<B;++i)s1+=v[i]=b[i];
a->s1-=s1,a->len=B;
s2=s1;
}
void up(){
sz=len,s2=s1;
if(lc)sz+=lc->sz,s2+=lc->s2;
if(rc)sz+=rc->sz,s2+=rc->s2;
}
void sum(int L,int R){
if(!this)return;
if(L<=1&&R>=sz){
_a+=s2;
return;
}
int ls=lc?lc->sz:0;
if(L<=ls)lc->sum(L,R),L=ls+1;
L-=ls,R-=ls;
if(R>len)rc->sum(L-len,R-len),R=len;
if(L==1&&R==len)_a+=s1;
else for(--L;L<R;++L)_a+=v[L];
}
void set(int w,int x){
int ls=lc?lc->sz:0;
if(w<=ls)lc->set(w,x);
else if(w>ls+len)rc->set(w-ls-len,x);
else{
w-=ls+1;
s1+=x-v[w];
v[w]=x;
}
up();
}
node*chk(int d){
if(c[d]&&c[d]->rnd>rnd){
node*u=c[d];
c[d]=u->c[d^1];
u->c[d^1]=this;
return up(),u->up(),u;
}
return up(),this;
}
node*del(int x);
node*ins(int x);
}ns[N/B+5],*ss[N/B+5],*rt,*tmp;
int n,m,sp=0,flag,_pos;
node*mg(node*a,node*b){
if(!a)return b;
if(!b)return a;
if(a->rnd>b->rnd){
a->rc=mg(a->rc,b);
a->up();
return a;
}else{
b->lc=mg(a,b->lc);
b->up();
return b;
}
}
node*node::del(int w){
int ls=lc?lc->sz:0;
if(w<=ls)return lc=lc->del(w),chk(0);
if(w>ls+len)return rc=rc->del(w-ls-len),chk(1);
if(flag&&len<=B){
flag=0;
for(int i=len-1;i>=0;--i)v[i+B-1]=v[i];
for(int i=0;i<B-1;++i)v[i]=tmp->v[i];
len+=B-1,sz+=B-1;
s1+=tmp->s1,s2+=tmp->s1;
ss[sp++]=tmp;
return this;
}
_a=v[w-ls-1];
s1-=_a,s2-=_a;
for(int i=w-ls;i<len;++i)v[i-1]=v[i];
--len,--sz;
if(flag){
tmp->s1+=tmp->v[B-1]=_a;
tmp->init(B);
return lc=mg(lc,tmp),chk(0);
}
if(len<B){
if(!len)ss[sp++]=this;
else flag=1,_pos=ls-w,tmp=this;
return mg(lc,rc);
}
return this;
}
node*node::ins(int w){
int ls=lc?lc->sz:0;
if(w<=ls)return lc=lc->ins(w),chk(0);
if(w>ls+len+1)return rc=rc->ins(w-ls-len),chk(1);
w-=ls+1;
for(int i=len++;i>w;--i)v[i]=v[i-1];
v[w]=_a;
s1+=_a,s2+=_a;
if(len<B2)return up(),this;
tmp=ss[--sp];
tmp->get(this);
return rc=mg(tmp,rc),chk(1);
}
int main(){
scanf("%d%d",&n,&m);
srand(n^m<<1^1512);
for(int i=0,mx=n/B+1;i<mx;++i)ss[sp++]=ns+i;
for(int D=B*3/2,l=1,r=D;l<=n;l+=D,r+=D){
if(r>n)r=n;
node*w=ss[--sp];
w->read(r-l+1);
rt=mg(rt,w);
}
for(;m;--m){
char o;
int a,b;
scanf(" %c %d%d",&o,&a,&b);
if(o==‘Q‘-48){
_a=0;
rt->sum(a,b);
printf("%lld\n",_a);
}else if(o==‘C‘-48){
rt->set(a,b);
}else{
flag=0;
rt=rt->del(a);
if(flag){
_pos+=a+1;
if(_pos<=n-1-tmp->len){
i64 a0=_a;
rt=rt->del(_pos);
_a=a0;
}else{
tmp->init(tmp->len);
rt=mg(rt,tmp);
}
}
rt=rt->ins(b);
}
}
return 0;
}