#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define mmt(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define N 300100
using namespace std;
typedef long long LL;
typedef long double LD;
int n,m,a[N],sta[N],top;char op[11];
int getint()
{
char ch;int flag=0,tmp=0;
for (ch=getchar();ch<48||ch>57;ch=getchar()) if (ch==int('-')) break;
if (ch==int('-')) flag=1;else tmp=int(ch)-48;
for (ch=getchar();48<=ch&&ch<=57;ch=getchar())
tmp=tmp*10+int(ch)-48;
return (flag)?-tmp:tmp;
}
int max3(int x,int y,int z){return (x>y?x:y)>z?(x>y?x:y):z;}
struct SplayTree
{
int lc[3*N],rc[3*N],s[3*N],fa[3*N],key[3*N];
int rev[3*N],sum[3*N],lm[3*N],rm[3*N],om[3*N],ms[3*N];
int root,len;
void init(){root=1;len=1;lm[1]=rm[1]=om[1]=-1e4;}
int newnode()
{
int r;
if (top) r=sta[top--];else r=++len;
return r;
}
void build(int *a,int x,int L,int R)
{
int mid=(L+R)>>1;key[x]=a[mid];ms[x]=-1e4;rev[x]=0;lc[x]=rc[x]=0;
if (L==R) {s[x]=1;lm[x]=rm[x]=om[x]=sum[x]=key[x];return;}
if (mid>L) {lc[x]=newnode();fa[lc[x]]=x;build(a,lc[x],L,mid-1);}
if (mid<R) {rc[x]=newnode();fa[rc[x]]=x;build(a,rc[x],mid+1,R);}
upd(x);
}
void sms(int x,int y)
{
if (x==0) return;
key[x]=ms[x]=y;sum[x]=(LL)ms[x]*s[x];
if (ms[x]>0) lm[x]=rm[x]=om[x]=sum[x];
else lm[x]=rm[x]=om[x]=ms[x];
}
void srev(int x)
{
if (x==0) return;
rev[x]^=1;
swap(lc[x],rc[x]);swap(lm[x],rm[x]);
}
void pushdown(int x)
{
if (x==0) return;
if (rev[x])
{
srev(lc[x]);srev(rc[x]);
rev[x]=0;
}
if (ms[x]!=-1e4)
{
sms(lc[x],ms[x]);sms(rc[x],ms[x]);
ms[x]=-1e4;
}
}
void upd(int x)
{
if (x==0) return;
pushdown(x);pushdown(lc[x]);pushdown(rc[x]);
s[0]=sum[0]=0;lm[0]=rm[0]=om[0]=key[0]-1e4;
s[x]=s[lc[x]]+s[rc[x]]+1;
sum[x]=sum[lc[x]]+sum[rc[x]]+key[x];om[x]=lm[x]=rm[x]=sum[x];
lm[x]=max(lm[x],max3(lm[lc[x]],sum[lc[x]]+key[x],sum[lc[x]]+key[x]+lm[rc[x]]));
rm[x]=max(rm[x],max3(rm[rc[x]],sum[rc[x]]+key[x],sum[rc[x]]+key[x]+rm[lc[x]]));
om[x]=max(max(0,rm[lc[x]])+key[x]+max(0,lm[rc[x]]),om[x]);
om[x]=max3(om[x],om[lc[x]],om[rc[x]]);
}
void rotate(int x,int t)
{
int y=fa[x];fa[x]=fa[y];fa[y]=x;
if (t) {if (lc[x]!=0) fa[lc[x]]=y;rc[y]=lc[x];lc[x]=y;}
else {if (rc[x]!=0) fa[rc[x]]=y;lc[y]=rc[x];rc[x]=y;}
if (fa[x]==0) root=x;
else if (y==lc[fa[x]]) lc[fa[x]]=x;else rc[fa[x]]=x;
upd(y);upd(x);
}
void Splay(int x,int goal)
{
while (fa[x]!=goal)
{
pushdown(fa[x]);
pushdown(x);
rotate(x,rc[fa[x]]==x);
}
upd(x);
}
void splay(int x){Splay(x,0);}
int select(int x,int ks)
{
pushdown(x);
int ls=s[lc[x]];
if (ks<=ls) return select(lc[x],ks);
if (ks<=ls+1) return x;
return select(rc[x],ks-ls-1);
}
int getid(int L,int R)
{
int pL=select(root,L-1+1);
Splay(pL,0);
int pR=select(root,R+1+1);
Splay(pR,root);
return lc[rc[root]];
}
void Del(int x) {if (!x) return;sta[++top]=x;Del(lc[x]);Del(rc[x]);}
void del(int L,int R)
{
int id=getid(L,R);Del(id);
lc[fa[id]]=0;upd(fa[id]);upd(fa[fa[id]]);
}
void ins(int p,int *a,int tot)
{
int id=getid(p+1,p+1);
int pos=++len;
build(a,len,1,tot);
fa[pos]=id;lc[id]=pos;
upd(id);upd(fa[id]);upd(fa[fa[id]]);
}
void Ms(int L,int R,int d)
{
int id=getid(L,R);
sms(id,d);upd(fa[id]);upd(fa[fa[id]]);
}
void Rev(int L,int R)
{
int id=getid(L,R);
srev(id);
}
}tree;
int main()
{
int i,t1,t2,t3,j,len;
scanf("%d%d",&n,&m);
FOR(i,1,n) scanf("%d",&a[i]);
a[0]=a[n+1]=a[n+2]=-1e4;
tree.init();int ccc=0;
tree.build(a,1,0,n+2);
FOR(i,1,m)
{
scanf("%s",&op);
if (op[0]=='M')
{
if (op[2]=='X')
{
int L=tree.s[tree.root]-3;
int id=tree.getid(1,L);
printf("%d\n",tree.om[id]);
}else
{t1=getint();t2=getint();t3=getint();tree.Ms(t1,t1+t2-1,t3);}
}
if (op[0]=='R') {t1=getint();t2=getint();tree.Rev(t1,t1+t2-1);}
if (op[0]=='D') {t1=getint();t2=getint();tree.del(t1,t1+t2-1);}
if (op[0]=='G')
{
t1=getint();t2=getint();
int id=tree.getid(t1,t1+t2-1);
printf("%d\n",tree.sum[id]);
}
if (op[0]=='I')
{
t1=getint();t2=getint();
FOR(j,1,t2) a[j]=getint();
tree.ins(t1,a,t2);
}
}
return 0;
}