#include <bits/stdc++.h>
using namespace std;
#define inc(i, l, r) for(int i=l; i<=r; i++)
#define midf(l, r) (l+r>>1)
typedef long long ll;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;
const int MOD = 1e9 + 7;
const int maxn = 2e3+10;
const int maxm = 300009;
const int INF = 1e7;
int a[maxn];
int n, m;
namespace SplayTree
{
#define ls(p) t[p].ch[0]
#define rs(p) t[p].ch[1]
struct node {
int size, sum, mx, lm, rm, v;
int tag, rev;
int f, ch[2];
node() {}
node(int val) {ch[0] = ch[1] = tag = rev = f = 0; size = 1; v = sum = mx = lm = rm = val;}
}t[maxn*4];
int st[maxn], sz, top, root;
int newnode() {return top ? st[top--] : ++sz;}
int wh(int p) {return t[t[p].f].ch[1] == p;}
void init(){
sz = top = root = 0;
}
void rever(int p)
{
if(t[p].tag) return;
t[p].rev ^= 1;
swap(ls(p), rs(p)); swap(t[p].lm, t[p].rm);
}
void paint(int p, int val)
{
t[p].tag = 1; t[p].v = val;
t[p].sum = val * t[p].size;
t[p].lm = t[p].rm = t[p].mx = max(val, t[p].sum);
t[p].rev = 0;
}
void pushdown(int p)
{
if(t[p].rev)
{
if(ls(p)) rever(ls(p));
if(rs(p)) rever(rs(p));
t[p].rev = 0;
}
if(t[p].tag)
{
if(ls(p)) paint(ls(p), t[p].v);
if(rs(p)) paint(rs(p), t[p].v);
t[p].tag = 0;
}
}
void pushup(int p)
{
t[p].size = t[ls(p)].size + t[rs(p)].size + 1;
t[p].sum = t[ls(p)].sum + t[rs(p)].sum + t[p].v;
t[p].mx = max(max(t[ls(p)].mx, t[rs(p)].mx), max(0, t[ls(p)].rm) + t[p].v + max(0, t[rs(p)].lm));
t[p].lm = max(t[ls(p)].lm, t[ls(p)].sum + t[p].v + max(0, t[rs(p)].lm));
t[p].rm = max(t[rs(p)].rm, t[rs(p)].sum + t[p].v + max(0, t[ls(p)].rm));
}
void rotate(int p)
{
int f = t[p].f, g = t[f].f, c = wh(p);
if(g) t[g].ch[wh(f)] = p; t[p].f = g;
t[f].ch[c] = t[p].ch[c ^ 1]; if(t[f].ch[c]) t[t[f].ch[c]].f = f;
t[p].ch[c ^ 1] = f; t[f].f = p;
pushup(f); pushup(p);
}
void Splay(int p, int cur)
{
for(;t[p].f != cur; rotate(p))
if(t[t[p].f].f != cur) rotate(wh(p) == wh(t[p].f) ? t[p].f : p);
if(cur == 0) root = p;
}
void build_tree(int &p, int L, int R, int fa)
{
int mid = midf(L, R);
p = newnode();
t[p] = node(a[mid]);
t[p].f = fa;
if(L == R) return;
if(L < mid) build_tree(ls(p), L, mid - 1, p);
if(mid < R) build_tree(rs(p), mid + 1, R, p);
pushup(p);
}
int Kth(int k)
{
int p = root, lsize = 0;
while(p)
{
pushdown(p);
int cur = lsize + t[ls(p)].size;
if(k == cur + 1) return p;
if(k <= cur) p = ls(p);
else {
lsize = cur + 1;
p = rs(p);
}
}
return -1;
}
void Ins_from_a(int k, int tot)
{
for(int i = 1;i <= tot; ++i) scanf("%d", &a[i]);
int f = Kth(k + 1); Splay(f, 0);
int p = Kth(k + 2); Splay(p, f);
build_tree(ls(p), 1, tot, p);
pushup(p); pushup(f);
}
void erase(int p)
{
if(! p) return;
st[++ top] = p;
erase(ls(p)); erase(rs(p));
}
void Del(int k, int tot)
{
int f = Kth(k); Splay(f, 0);
int p = Kth(k + tot + 1); Splay(p, f);
erase(ls(p)); ls(p) = 0;
pushup(p); pushup(f);
}
void Mak(int k, int tot, int x)
{
int f = Kth(k); Splay(f, 0);
int p = Kth(k + tot + 1); Splay(p, f);
paint(ls(p), x);
pushup(p); pushup(f);
}
void Rev(int k, int tot)
{
int f = Kth(k); Splay(f, 0);
int p = Kth(k + tot + 1); Splay(p, f);
rever(ls(p));
pushup(p); pushup(f);
}
int Sum(int k, int tot)
{
int f = Kth(k); Splay(f, 0);
int p = Kth(k + tot + 1); Splay(p, f);
return t[ls(p)].sum;
}
int MaxSum(int k, int tot)
{
int f = Kth(k); Splay(f, 0);
int p = Kth(k + tot + 1); Splay(p, f);
return t[ls(p)].mx;
}
};
using namespace SplayTree;
int main()
{
char op[10];
while(scanf("%d%d", &n, &m) == 2)
{
init();
a[1] = -INF, a[n+2] = -INF;
t[0] = node(-INF), t[0].sum = t[0].size = 0;
inc(i, 2, n+1) scanf("%d", &a[i]);
build_tree(root, 1, n+2, 0);
int num = n;
int a, b, c;
for(int i=0; i<m; i++){
scanf("%s", op);
if(op[0] == 'G' &&op[4] == 'S'){
scanf("%d%d", &a, &b);
printf("%d\n", Sum(a, b));
}
else if(op[0] == 'M'&& op[4] == 'S'){
printf("%d\n", t[root].mx);
}
else if(op[0] == 'I'){
scanf("%d%d", &a, &b);
num += b;
Ins_from_a(a, b);
}
else if(op[0] == 'D'){
scanf("%d%d", &a, &b);
num -= 1;
Del(a, b);
}
else if(op[0] == 'M'&&op[5] == 'S'){
scanf("%d%d%d", &a, &b, &c);
Mak(a, b, c);
}
else if(op[0] == 'R'){
scanf("%d%d", &a, &b);
Rev(a, b);
}
}
}
return 0;
}