#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX 200002 int n; int q; char buf[3]; pair mo(long long int t, long long int ich,bool x){ //false left,true right if (x==1){ t %= (n+2); ich -= t; if (ich < 0){ ich++; if (ich < 0){ ich++; } x ^= 1; } ich = abs(ich); ich = 0; } else{ t %= (n+2); ich += t; if (ich >= n){ ich -= n-1; if (ich){ ich--; } ich = n - 1 - ich; x ^= 1; } } return make_pair(ich, x); } struct BIT{ long long int bit[MAX]; BIT(){ for (int i = 0; i < MAX; i++){ bit[i] = 0; } } void add(int i, long long int x){ i++; while (i < MAX){ bit[i] += x; i += i&-i; } } long long int sum(int i){ long long int r = 0; i++; while (i){ r += bit[i]; i -= i&-i; } return r; } long long int q(int a, int b){ if (a > b){ swap(a, b); } return sum(b) - sum(a - 1); } }; BIT B[2]; void ins(int a, int b, int c){ B[b].add(a, c); } int main(){ scanf("%d%d", &n, &q); while (q--){ pair kari; scanf("%s", buf); int t, y, z; scanf("%d%d%d", &t, &y, &z); if (buf[0] == 'L'){ kari = mo(t, y, false); ins(kari.first, kari.second, z); continue; } if (buf[0] == 'R'){ kari = mo(t, y, true); ins(kari.first, kari.second, z); continue; } long long int ans = 0; t %= (n+2); z--; for (int i = 0; i < 2; i++){ pair kari = mo(t, y, i); pair kari2 = mo(t, z, i); if (kari.first>kari2.first){ swap(kari, kari2); } if (kari.second != kari2.second){ int chu = 0; if (i == 0){ chu = n-1; } ans += B[kari.second].q(kari.first,chu); ans += B[kari2.second].q(chu, kari2.first); } else{ ans += B[kari.second].q(kari2.first, kari.first); } } printf("%lld\n", ans); } return 0; }