#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x class BIT { public: V bit[1<=0;i--) if(tv+bit[ent+(1< Lbt; BIT Rbt; int N,N2,Q; string X[30000]; int Y[30000],Z[30000]; ll momo(ll a) { return (a%N2+N2)%N2;} void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>Q; N2=2*N; FOR(i,Q) { cin>>X[i]>>Y[i]>>Z[i]; if(X[i][0]=='L') { Lbt.update(1+momo(Y[i]+i+1),Z[i]); } if(X[i][0]=='R') { Rbt.update(1+momo(Y[i]-(i+1)),Z[i]); } if(X[i][0]=='C') { Z[i]--; ll ret=0; x=momo(Y[i]+(i+1)); y=momo(Z[i]+(i+1)); //_P("L %d %d\n",x,y); if(x<=y) ret +=Lbt.total(y+1)-Lbt.total(x); else ret +=Lbt.total(N2+2)-Lbt.total(x) + Lbt.total(y+1); //cout<