#include #include #include #include #define FORR(i,b,e) for(int i=(b);i<(int)(e);++i) #define FOR(i,e) FORR(i,0,e) #define sortuniq(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(),v.end()),v.end()) #define dump(var) cerr << #var ": " << var << "\n" #define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n" typedef long long ll; typedef unsigned long long ull; const double EPS = 1e-6; const int d4[] = {0, -1, 0, 1, 0}; using namespace std; template struct BIT { int size; vector bit; BIT(int size):size(size), bit(size+1) {} void add(int p, T v) { p++; for (; p <= size; p+=(p&-p)) bit[p]+=v; } // [0, p] T sum(int p) { p++; T r = 0; for (; p > 0; p-=(p&-p)) r += bit[p]; return r; } // [a, b] T sum(int a, int b) { return sum(b) - sum(a-1); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; vector x(Q); vector y(Q), z(Q); FOR(i, Q) cin >> x[i] >> y[i] >> z[i]; BIT bit(1<<16); int n2 = N * 2; FOR(i, Q) { // cout << x[i] << ' ' << y[i] << ' ' << z[i] << endl; if (x[i] == 'R') { int p = (n2 + y[i] - i%n2) % n2; bit.add(p, z[i]); } else if (x[i] == 'L') { int p = (n2 + n2 - y[i] - 1 - i%n2) % n2; bit.add(p, z[i]); } else { ll total = 0; int pos[2][2] = {{y[i],z[i]}, {n2-z[i],n2-y[i]}}; for (const auto &p: pos) { int l = (n2 + p[0] - i%n2) % n2; int r = (n2 + p[1] - i%n2) % n2; if (l < r) { total += bit.sum(l, r-1); } else { if (r > 0) total += bit.sum(r-1); total += bit.sum(l, n2-1); } } cout << total << '\n'; } } return 0; }