Under construction

Still being built. Things may change

Color Inversion on a Huge Chessboard

Time limit4sMemory limit1024 MB

Summary
After each row or column flip on an n by n checkerboard, report how many same-colored connected areas there are.
Level

Medium6 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

A set of square cells is arranged in a chessboard-like pattern with nn horizontal rows and nn vertical columns. Rows are numbered 11 through nn from top to bottom, and columns are numbered 11 through nn from left to right.

Initially, the cells are colored like a chessboard. The cell in row ii and column jj is black if i+ji + j is odd and white if i+ji + j is even.

Color-inversion operations are applied one after another. Each operation is one of the following two.

Invert colors of a row: Given a row number, invert the colors of all cells in that row. White cells in the row become black, and black cells become white.

Invert colors of a column: Given a column number, invert the colors of all cells in that column. White cells in the column become black, and black cells become white.

After each operation, count the number of areas. An area is a group of cells of the same color that are directly or indirectly connected. Two cells are directly connected when they share an edge.

Input

The input consists of a single test case in the following format.

nn qq

operation_1operation\_1

⋮\vdots

operation_qoperation\_q

The integer nn is the number of rows and columns (1≤n≤5×1051 \le n \le 5 \times 10^5). The integer qq is the number of operations (1≤q≤5×1051 \le q \le 5 \times 10^5). The following qq lines give the operations in order. Each line has one of the following forms.

  • ROW ii: invert the colors of row ii (1≤i≤n1 \le i \le n).
  • COLUMN jj: invert the colors of column jj (1≤j≤n1 \le j \le n).

Output

Output qq lines. The kk-th line contains the number of areas after the kk-th operation.

Hint

Figure F.1. Illustration of the first sample input.

Examples2

  1. Example 1

    Input
    3 3
    ROW 2
    COLUMN 3
    ROW 2
    
    Expected output
    3
    2
    6
    
  2. Example 2

    Input
    200000 2
    ROW 1
    ROW 1
    
    Expected output
    39999800000
    40000000000