#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
typedef long long i64;
template<typename... T>int debug(T ...a){return fprintf(stderr, a...);}
bool ___mem_b;
constexpr int N(6e5 + 5);
int n, m, sta[N], top, root;
mt19937 eng(system_clock::now().time_since_epoch().count());
struct node {
int ch[2], sz, pri, x;
i64 y, sum;
}t[N];
int new_node(int x, int y) {
int u(sta[--top]);
t[u].ch[0] = t[u].ch[1] = 0;
t[u].sz = 1;
t[u].pri = eng();
t[u].x = x;
t[u].sum = t[u].y = y;
return u;
}
void push_up(int u) {
t[u].sz = t[t[u].ch[0]].sz + t[t[u].ch[1]].sz + 1;
t[u].sum = t[t[u].ch[0]].sum + t[t[u].ch[1]].sum + t[u].y;
}
void build(int& u, int l, int r) {
if (l > r) return;
const int mid((l + r) >> 1);
u = new_node(mid, 1);
build(t[u].ch[0], l, mid - 1);
cin >> t[u].y;
build(t[u].ch[1], mid + 1, r);
push_up(u);
}
void rotate(int& f, bool d) {
int u(t[f].ch[d]);
t[f].ch[d] = t[u].ch[d ^ true];
t[u].ch[d ^ true] = f;
push_up(f); push_up(u);
f = u;
}
void op_c(int x, int y, int u = root) {
if (x == t[u].x) {
t[u].y -= y;
} else if (x < t[u].x) {
op_c(x, y, t[u].ch[0]);
} else {
op_c(x, y, t[u].ch[1]);
}
push_up(u);
}
void op_i(int x, int y, int& u = root) {
if (!u) {
u = new_node(x, y);
return;
}
if (x == t[u].x) {
t[u].y = y;
} else if (x < t[u].x) {
op_i(x, y, t[u].ch[0]);
if (t[t[u].ch[0]].pri > t[u].pri) rotate(u, false);
} else {
op_i(x, y, t[u].ch[1]);
if (t[t[u].ch[1]].pri > t[u].pri) rotate(u, true);
}
push_up(u);
}
void erase(int& u) {
if (!t[u].ch[0] || !t[u].ch[1]) {
sta[top++] = u;
u = t[u].ch[t[u].ch[0] == 0];
return;
}
bool d(t[t[u].ch[0]].pri < t[t[u].ch[1]].pri);
rotate(u, d);
erase(t[u].ch[d ^ true]);
push_up(u);
}
void op_d(int x, int& u = root) {
int l(t[t[u].ch[0]].sz + 1);
if (x == l) {
erase(u);
} else if (x < l) {
op_d(x, t[u].ch[0]);
} else {
op_d(x - l, t[u].ch[1]);
}
push_up(u);
}
i64 op_q() {
return t[root].sum;
}
void travel(int& u = root) {
if (u) {
travel(t[u].ch[0]);
debug("<%d,%d>", t[u].x, t[u].y);
travel(t[u].ch[1]);
}
}
bool ___mem_e;
int main() {
#ifndef ONLINE_JUDGE
debug("memory: %fMB\n", (&___mem_e - &___mem_b) / 1048576.0);
return 0;
#endif
cin.tie(nullptr)->sync_with_stdio(false);
char o;
int i, x, y;
iota(sta, sta + N - 1, 1);
top = N - 1;
cin >> n >> m;
build(root, 1, n);
for (i = 0; i < m; ++i) {
cin >> o;
switch(o) {
case 'C':
cin >> x >> y;
op_c(x, y);
break;
case 'I':
cin >> x >> y;
op_i(x, y);
break;
case 'D':
cin >> x;
op_d(x);
break;
default:
cout << op_q() << '\n';
break;
}
}
return 0;
}