Under construction

Still being built. Things may change

Šah

Time limit3sMemory limit2048 MB

Summary
Count the squares attacked by at least one knight, rook, or queen on an N by N board, where pieces attack through other pieces and their own square counts.
Level

Easy2 of 10

Topics
Implementation, Matrix, Brute force
Solved
No attempts yet

Problem

Two chess giants, Vito and Patrik, will play a game of chess this year in front of the iconic theater on Jane Street, and the match will decide who is the greatest player of all time. Standard chess has become boring for them, so they changed the rules to make the game more interesting. Only the rules relevant to this task are described here.

The chessboard is a square matrix with NN rows and NN columns. Only the knight, rook, and queen are used. Each piece moves as it does in standard chess. A rook attacks every square in its row and column. A queen attacks every square in its row and column, and also every square along its two diagonals. A knight attacks squares that are two rows and one column away from it, or one row and two columns away. Examples of these moves are shown in the hint.

Note: Each piece also attacks the square it stands on. Pieces attack through other pieces, so a piece attacks squares by the rules above even when another piece lies between them.

Vito wants to practice quick observation. He places MM chess pieces on the board and then finds every attacked square. Your task is to count the attacked squares on the given board.

Input

The first line contains positive integers NN and MM (1≤N≤2001 \le N \le 200, 1≤M≤N21 \le M \le N^2).

Each of the next MM lines contains an uppercase English letter for the piece type, which is N (knight), R (rook), or Q (queen), followed by integers rir_i and cic_i (1≤ri,ci≤N1 \le r_i, c_i \le N), the row and column of that piece.

At most one piece is placed on any square of the board.

Output

Output the number of attacked squares on the board in the first and only line.

Hint

The sketches show the first and second examples. Every attacked square is marked with a dot, except the square where the piece stands.

(a) First example.

(b) Second example.

Examples3

  1. Example 1

    Input
    7 1
    Q 4 4
    
    Expected output
    25
    
  2. Example 2

    Input
    5 1
    N 3 3
    
    Expected output
    9
    
  3. Example 3

    Input
    6 3
    R 1 4
    Q 2 1
    N 5 2
    
    Expected output
    25