using System; using System.Collections.Generic; class program { public static void Main() { var str = Console.ReadLine().Split(' '); var N = int.Parse(str[0]); var Q = int.Parse(str[1]); Pool pool = new Pool(N); for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); string x = str[0]; int y = int.Parse(str[1]); long z = long.Parse(str[2]); if (x.Equals("C")) { Console.WriteLine(pool.outputSum(y, (int)z)); } else { pool.add(x, y, z); } pool.next(); } } } public class Pool { private int length; private List flist; public Pool(int N) { this.length = N; this.flist = new List(); } public void add(string direction, int position, long num) { flist.Add(new Fish(direction, position, num, this.length)); } public void next() { foreach(Fish fish in flist){ fish.next(); } } public long outputSum(int left, int right) { long sum = 0; foreach (Fish fish in flist) { int posi = fish.getPosition(); if (left <= posi && posi < right) { sum += fish.getNum(); } } return sum; } } public class Fish { private string direction; private int position; private long num; private int length; public Fish(string direction, int position, long num, int length) { this.direction = direction; this.position = position; this.num = num; this.length = length; } public void next() { if (direction.Equals("R")) { if (position + 1 == length) { direction = "L"; } else { position++; } } else { if (position - 1 < 0) { direction = "R"; } else { position--; } } } public long getNum() { return this.num; } public int getPosition() { return this.position; } }