import sys def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 Q = int(input[ptr]) ptr += 1 groups = [] for _ in range(Q): query = input[ptr] ptr += 1 y = int(input[ptr]) ptr += 1 z = int(input[ptr]) ptr += 1 if query == 'C': current_time = _ + 1 # queries are 1-indexed y_query = y z_query = z total = 0 for group in groups: t0, y0, direction, count = group if t0 > current_time: continue k = current_time - t0 pos = y0 dir = 1 if direction == 'R' else -1 for _ in range(k): if dir == 1: if pos < N - 1: pos += 1 else: dir = -1 else: if pos > 0: pos -= 1 else: dir = 1 if y_query <= pos < z_query: total += count print(total) else: direction = query t0 = _ + 1 # queries are 1-indexed groups.append((t0, y, direction, z)) if __name__ == '__main__': main()