#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 2e5+20, M = 4e4+10, mod = 1e9+7, inf = 0x3f3f3f3f;
int c[N][2],mx[N],size[N],rev[N],fa[N],ID[N],t1,t2,id[N],n,m,rt,sz;
LL v[N],tag[N],sum[N];
inline void push_up(int k) {
int l = c[k][0], r = c[k][1];
sum[k] = sum[l] + sum[r] + v[k];
size[k] = size[l] + size[r] + 1;
}
inline void push_down(int k) {
int l = c[k][0], r = c[k][1], t = tag[k];
if(t) {
tag[k] = 0;
if(l) {tag[l] += t,v[l]+=t,sum[l]+=1LL*size[l]*t;}
if(r) {tag[r] += t,v[r]+=t,sum[r]+=1LL*size[r]*t;}
}
}
inline void rotate(int x,int &k) {
int y = fa[x], z = fa[y], l ,r;
push_down(z);
push_down(y);
push_down(x);
if(c[y][0] == x) l=0;else l=1;
r=l^1;
if(y == k) k = x;
else {if(c[z][0] == y) c[z][0] = x;else c[z][1] = x;}
fa[x]=z;
fa[y]=x;
fa[c[x][r]]=y;
c[y][l]=c[x][r];
c[x][r]=y;
push_up(y);
push_up(x);
}
inline void splay(int x,int &k) {
push_down(k);
while(x!=k) {
int y = fa[x], z = fa[y];
if(y!=k) {
if(c[y][0] == x ^ c[z][0] == y) rotate(x,k);
else rotate(y,k);
}
rotate(x,k);
}
}
inline void ask_befor(int k,int x)
{
push_down(k);
if(k==0)return;
if(ID[k]<=x){t1=k;ask_befor(c[k][1],x);}
else ask_befor(c[k][0],x);
}
inline void ask_after(int k,int x)
{
push_down(k);
if(k==0)return;
if(ID[k]>=x){t2=k;ask_after(c[k][0],x);}
else ask_after(c[k][1],x);
}
inline void update(int l,int r,int val) {
ask_befor(rt,l-1),ask_after(rt,r+1);
int x = t1, y = t2;
splay(x,rt);splay(y,c[x][1]);
int z = c[y][0];
tag[z] += val;
v[z] += val;
sum[z] +=1LL*val*size[z];
}
inline void query(int l,int r) {
ask_befor(rt,l-1), ask_after(rt,r+1);
int x = t1, y = t2;
splay(x,rt),splay(y,c[x][1]);
int z = c[y][0];
printf("%lld\n",sum[z]);
}
inline void ins(int &k,int ids,int val,int last) {
push_down(k);
if(k == 0) {
++sz;
size[sz]=1;
k = sz;
v[k] = val;
sum[k] = val;
fa[k] = last;
ID[k] = ids;
return ;
}
if(ids < ID[k]) ins(c[k][0],ids,val,k);
else ins(c[k][1],ids,val,k);
push_up(k);
}
inline void Delet(int l,int r) {
ask_befor(rt,l-1), ask_after(rt,r+1);
int x = t1, y = t2;
splay(x,rt),splay(y,c[x][1]);
c[y][0] = 0;
}
int main() {
sz = 0;
ins(rt,-1,0,0);
ins(rt,100000001,0,rt);
scanf("%d",&n);
while(n--)
{
char ch[3];
int l,r,val;
scanf("%s%d%d",ch,&l,&r);
if(ch[0] == 'I') {
ins(rt,l,r,rt);
splay(sz,rt);
} else if(ch[0] == 'Q') {
query(l,r);
} else if(ch[0] == 'M') {
scanf("%d",&val);
update(l,r,val);
} else if(ch[0] == 'D') {
Delet(l,r);
}
}
return 0;
}