#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <iostream>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define down(i, l, r) for(int i = l; i >= r; i--)
#define MS 567890
#define MAX 1037471823
#define Q 1
using namespace std;
int n, m, a, b, s[MS], h[MS], l[MS], r[MS], k[MS], next[MS], last;
long long sum[MS], lm[MS], mm[MS], rm[MS];
bool rev[MS], e[MS];
char q[10];
void Cal(int o)
{
if (!o) return;
s[o] = s[r[o]] + s[l[o]] + 1;
if (e[o])
{ sum[o] = lm[o] = rm[o] = mm[o] = k[o] * s[o]; if (k[o] < 0) lm[o] = rm[o] = 0, mm[o] = k[o]; return; }
sum[o] = sum[r[o]] + sum[l[o]] + k[o];
if (rev[o])
{ lm[o] = max(rm[r[o]], sum[r[o]]+k[o]+rm[l[o]]), rm[o] = max(lm[l[o]], sum[l[o]]+k[o]+lm[r[o]]), mm[o] = max(rm[l[o]]+k[o]+lm[r[o]], max(mm[l[o]], mm[r[o]])); }
else
{ lm[o] = max(lm[l[o]], sum[l[o]]+k[o]+lm[r[o]]), rm[o] = max(rm[r[o]], sum[r[o]]+k[o]+rm[l[o]]), mm[o] = max(rm[l[o]]+k[o]+lm[r[o]], max(mm[l[o]], mm[r[o]])); }
}
int New(int x) { int o = last; last = next[last]; s[o] = 1, h[o] = 0, l[o] = r[o] = 0, k[o] = sum[o] = x, e[o] = rev[o] = false, lm[o] = mm[o] = rm[o] = x>0?x:0; return o; }
void Down(int o)
{
if (rev[o])
{ int a; a = r[o], r[o] = l[o], l[o] = a; rev[r[o]] ^= 1, rev[l[o]] ^= 1, rev[o] ^= 1; Cal(r[o]); Cal(l[o]); Cal(o); }
if (e[o])
{ e[o] = false; e[r[o]] = e[l[o]] = true; k[r[o]] = k[l[o]] = k[o]; Cal(r[o]); Cal(l[o]); Cal(o); }
}
void Splay(int x)
{
if (!x) return; int o = h[x]; Down(x);
while (o)
{
if (l[o] == x) { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o], h[r[x]] = o, l[o] = r[x], h[o] = x, r[x] = o; Cal(o); }
else { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o], h[l[x]] = o, r[o] = l[x], h[o] = x, l[x] = o; Cal(o); }
o = h[x];
}
Cal(x);
}
void Insert(int rr, int x)
{
if (!l[0]) { int now = New(x); l[0] = now; Cal(now); return; }
int o = l[0]; Down(o); while (rr <= s[l[o]]?l[o]:r[o]) { if (rr <= s[l[o]]) o = l[o]; else rr -= s[l[o]]+1, o = r[o]; Down(o); }
int now = New(x); if (rr <= s[l[o]]) l[o] = now; else r[o] = now; h[now] = o;
Splay(now); Cal(now);
}
int FindRW(int rr)
{
int o = l[0]; Down(o); while (rr != s[l[o]]) { if (rr < s[l[o]]) o = l[o]; else rr -= s[l[o]]+1, o = r[o]; Down(o); }
return o;
}
void InsertP(int o, int n)
{
int ln = (n-1)/2, rn = n-1-ln;
if (ln) { int now = New(0); l[o] = now, h[now] = o; InsertP(now, ln); }
scanf("%d", &k[o]);
if (rn) { int now = New(0); r[o] = now, h[now] = o; InsertP(now, rn); }
Cal(o);
}
void InsertQ(int b, int n)
{
Splay(FindRW(b-1)); Splay(FindRW(b)); int now = New(0); r[l[l[0]]] = now, h[now] = l[l[0]]; InsertP(now, n); Splay(r[l[l[0]]]);
}
void DeleteP(int o)
{
if (l[o]) DeleteP(l[o]); if (r[o]) DeleteP(r[o]); next[o] = last, last = o;
}
void Delete(int b, int n) { Splay(FindRW(b-1)); Splay(FindRW(b+n)); DeleteP(r[l[l[0]]]); r[l[l[0]]] = 0; Cal(l[l[0]]); Cal(l[0]); }
void Edit(int b, int n, int x) { Splay(FindRW(b-1)); Splay(FindRW(b+n)); int o = r[l[l[0]]]; k[o] = x; e[o] = true; Splay(o); }
void Rev(int b, int n) { Splay(FindRW(b-1)); Splay(FindRW(b+n)); int o = r[l[l[0]]]; rev[o] ^= 1; Splay(o); }
void QSum(int b, int n) { Splay(FindRW(b-1)); Splay(FindRW(b+n)); printf("%lld\n", sum[r[l[l[0]]]]); }
void QMaxSum() { Splay(FindRW(0)); Splay(FindRW(s[l[0]]-1)); printf("%lld\n", mm[r[l[l[0]]]]); }
int main()
{
scanf("%d%d", &n, &m); mm[0] = -MAX;
l[0] = 1, l[1] = 2, h[2] = 1, s[1] = 2, s[2] = 1;
last = 3; rep(i, 3, MS-1) next[i] = i+1;
InsertQ(1, n);
rep(i, 1, m)
{
scanf("%s", q);
if (q[2] == 'S')
{ scanf("%d%d", &b, &n); InsertQ(b+1, n); }
else if (q[2] == 'L')
{ scanf("%d%d", &b, &n); Delete(b, n); }
else if (q[2] == 'K')
{ scanf("%d%d%d", &b, &n, &a); Edit(b, n, a); }
else if (q[2] == 'V')
{ scanf("%d%d", &b, &n); Rev(b, n); }
else if (q[2] == 'T')
{ scanf("%d%d", &b, &n); QSum(b, n); }
else if (q[2] == 'X') QMaxSum();
}
return 0;
}
I2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CgojZGVmaW5lIHJlcChpLCBsLCByKSBmb3IoaW50IGkgPSBsOyBpIDw9IHI7IGkrKykKI2RlZmluZSBkb3duKGksIGwsIHIpIGZvcihpbnQgaSA9IGw7IGkgPj0gcjsgaS0tKQojZGVmaW5lIE1TIDU2Nzg5MAojZGVmaW5lIE1BWCAxMDM3NDcxODIzCiNkZWZpbmUgUSAxCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIG0sIGEsIGIsIHNbTVNdLCBoW01TXSwgbFtNU10sIHJbTVNdLCBrW01TXSwgbmV4dFtNU10sIGxhc3Q7CmxvbmcgbG9uZyBzdW1bTVNdLCBsbVtNU10sIG1tW01TXSwgc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