Under construction

Still being built. Things may change

Settlement Office

Interview

Time limit1sMemory limit256 MB

Summary
Report each row or column sum in a grid holding x plus y, zeroing that row or column after each query.
Level

Easy3 of 10

Topics
Hash map, Math
Solved
No attempts yet

Problem

Garison and Andreson work at a settlement office and want to predict the future. They are given a large n×nn \times n square grid. At the start the element at (x,y)(x, y) holds x+yx + y (1≤x,y≤n1 \le x, y \le n).

Two kinds of queries arrive.

  • R r: print the sum of every value in row rr, then set all of row rr to 0.
  • C c: print the sum of every value in column cc, then set all of column cc to 0.

Write a program that reports the result of each query in order.

Input

The first line has the grid size nn and the number of queries qq (1≤n≤1061 \le n \le 10^6, 1≤q≤1051 \le q \le 10^5).

Each of the next qq lines has one query, either R r (1≤r≤n1 \le r \le n) or C c (1≤c≤n1 \le c \le n).

Output

Print the result of the ii-th query on the ii-th line (1≤i≤q1 \le i \le q).

Examples5

  1. Example 1

    Input
    3 7
    R 2
    C 3
    R 2
    R 1
    C 2
    C 1
    R 3
    
    Expected output
    12
    10
    0
    5
    5
    4
    0
    
  2. Example 2

    Input
    1 3
    R 1
    C 1
    R 1
    
    Expected output
    2
    0
    0
    
  3. Example 3

    Input
    2 4
    C 1
    R 1
    C 2
    R 2
    
    Expected output
    5
    3
    4
    0
    
  4. Example 4

    Input
    4 8
    R 1
    R 2
    R 3
    R 4
    C 1
    C 2
    C 3
    C 4
    
    Expected output
    14
    18
    22
    26
    0
    0
    0
    0
    
  5. Example 5

    Input
    5 6
    C 3
    C 3
    R 5
    C 1
    R 5
    R 2
    
    Expected output
    30
    0
    32
    14
    0
    17