#include #include #include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define var auto #define mod 1000000007 #define inf 2147483647 typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; } template void output(T a, int precision) { if(precision > 0){ cout << fixed << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } // end of template struct bit { vector v; // 部分和をbitで管理 仮想配列はa[1...n] bit(int n){ // bit(int n) : v(n + 1) {} v.resize(n + 1); } ll sum(int i){ // 仮想配列a[1]~a[i]の和を求める ll ret = 0; for(; i > 0; i -= i & -i){ // i & -i: iの1が立っている最高位bitをの2^を返す ret += v[i]; } return ret; } void add(int i, ll w) { // index:iにwを加える for (; i < v.size(); i += i & -i) { v[i] += w; } } }; int N; int mod2N(int i){ // return 1 ~ 2N i -= 1; return ((i % (2 * N)) + 2 * N) % (2 * N) + 1; } int main() { // source code N = inputValue(); int Q = inputValue(); bit b(2 * N); rep(i, Q){ char c; cin >> c; int t = i; // int t = inputValue(); // セグメントフィッシング+ int y = inputValue(); int z = inputValue(); if (c == 'R') { // right b.add(mod2N(y - t + 1), z); } if (c == 'L') { // left b.add(mod2N(2 * N - y - t), z); } if (c == 'C') { // count int l1 = mod2N(y - t); int r1 = mod2N(z - t); int l2 = mod2N(2 * N - z - t); int r2 = mod2N(2 * N - y - t); ll ret1 = b.sum(r1) - b.sum(l1); ll ret2 = b.sum(r2) - b.sum(l2); if (l1 > r1) { ret1 += b.sum(2 * N); } if (l2 > r2) { ret2 += b.sum(2 * N); } output(ret1 + ret2, 0); } } return 0; }