#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 int main(){ int n,q; cin>>n>>q; n--; fenwick_tree F(2*(n+1)); rep(i,q){ char c; cin>>c; if(c=='L'){ long long t,y,z; cin>>t>>y>>z; long long temp = n+1; temp += n-y; temp -= t; temp %= n*2+2; if(temp<0)temp += n*2+2; F.add(temp,z); } else if(c=='R'){ long long t,y,z; cin>>t>>y>>z; long long temp = y; temp -= t; temp %= n*2+2; if(temp<0)temp += n*2+2; F.add(temp,z); } else{ long long ans = 0; long long t,y,z; cin>>t>>y>>z; long long l = y; long long r = z; l -= t; r -= t; l %= 2*n+2; l+=n*2+2; l %= 2*n+2; r %= 2*n+2; r+=n*2+2; r %= 2*n+2; if(l<=r)ans += F.sum(l,r); else{ ans += F.sum(0,r); ans += F.sum(l,n*2+2); } l = n+1+(n-z); r = n+1+(n-y);//z; l++,r++; l -= t; r -= t; l %= 2*n+2; l+=n*2+2; l %= 2*n+2; r %= 2*n+2; r+=n*2+2; r %= 2*n+2; //cout<