package q3xx; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Q383 { static InputStream is; static PrintWriter out; static String INPUT = ""; static void solve() { int n = ni(), Q = ni(); long[] ft = new long[2*n+1]; long all = 0; for(int i = 0;i < Q;i++){ char x = nc(); int y = ni(), z = ni(); if(x == 'R'){ int pos = (y-i)%(2*n); if(pos < 0)pos+=2*n; addFenwick(ft, pos, z); all += z; }else if(x == 'L'){ int pos = (n+(n-1-y)-i)%(2*n); if(pos < 0)pos+=2*n; addFenwick(ft, pos, z); all += z; }else if(x == 'C'){ long ret = 0; // R { int l = (y-i)%(2*n); if(l < 0)l+=2*n; int r = (z-1-i)%(2*n); if(r < 0)r+=2*n; if(l <= r){ ret += sumFenwick(ft, r) - sumFenwick(ft, l-1); }else{ ret += sumFenwick(ft, r) + all - sumFenwick(ft, l-1); } } // L { int l = (n+(n-1-(z-1))-i)%(2*n); if(l < 0)l+=2*n; int r = (n+(n-1-y)-i)%(2*n); if(r < 0)r+=2*n; if(l <= r){ ret += sumFenwick(ft, r) - sumFenwick(ft, l-1); }else{ ret += sumFenwick(ft, r) + all - sumFenwick(ft, l-1); } } out.println(ret); } } } public static long sumFenwick(long[] ft, int i) { long sum = 0; for(i++;i > 0;i -= i&-i)sum += ft[i]; return sum; } public static void addFenwick(long[] ft, int i, long v) { if(v == 0)return; int n = ft.length; for(i++;i < n;i += i&-i)ft[i] += v; } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); long G = System.currentTimeMillis(); tr(G-S+"ms"); } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static char nc() { return (char)skip(); } private static int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }