#include using namespace std; using uint = unsigned int; using lint = long long int; using ulint = unsigned long long int; template using V = vector; template using VV = V< V >; template void assign(V& v, int n, const U& a) { v.assign(n, a); } template void assign(V& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); } template struct FenwickTree { const int n, h; FenwickTree(int n) : n(n), h(__lg(n) + 1), t(n + 1) {} void add(int x, Int a) { assert(0 <= x and x < n); for (int i = x + 1; i <= n; i += i & -i) t[i] += a; } Int sum(int x) { x = min(x, n); Int res = 0; for (int i = x; i > 0; i -= i & -i) res += t[i]; return res; } Int sum(int l, int r) { l = max(0, l), r = min(r, n); if (l >= r) return 0; return sum(r) - sum(l); } private: V t; }; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, q; cin >> n >> q; FenwickTree ft(2 * n); auto sum = [&](int l, int r) -> lint { l %= 2 * n, r %= 2 * n; if (l <= r) return ft.sum(l, r); return ft.sum(0, r) + ft.sum(l, ft.n); }; while (q--) { char c; cin >> c; int t; cin >> t; if (c == 'L') { int i, a; cin >> i >> a; ft.add((i + t) % (2 * n), a); } else if (c == 'R') { int i, a; cin >> i >> a; ft.add((2 * n - 1 - i + t) % (2 * n), a); } else { int l, r; cin >> l >> r; lint res = sum(l + t, r + t) + sum(2 * n - r + t, 2 * n - l + t); cout << res << '\n'; } } }