#include #include #include using namespace std; typedef long long LL; struct Fish { int t, num, pos, heading; // 0:左,1:右 }; int n, q; vector fishes; int main() { // freopen("fish.in", "r", stdin); // freopen("fish.out", "w", stdout); scanf("%d%d", &n, &q); for (int i = 1; i <= q; ++i) { int t, y, z; char ch; scanf(" %c%d%d%d", &ch, &t, &y, &z); if (ch == 'L') { fishes.push_back({ t, z, y, 0 }); } else if (ch == 'R') { fishes.push_back({ t, z, y, 1 }); } else { LL ans = 0LL; for (Fish f : fishes) { int left_t = t - f.t, heading = f.heading, pos = f.pos; while (left_t-- > 0) { if (heading == 0) { if (pos == 0) heading = 1; else --pos; } else { if (pos == n - 1) heading = 0; else ++pos; } } if (y <= pos && pos < z) ans += f.num; } printf("%lld\n", ans); } } return 0; }