Two chess giants, Vito and Patrik, will play a game of chess this year in front of
the iconic theater on Jane Street, finally proving who is the greatest player \(of\) all
time. However, as standard chess has become boring for them, they decided to
modify the rules of the game to make it more interesting. We will mention only
the rules that are relevant to this task.
The chessboard will be a square matrix with \(N\) rows and \(N\) columns. Only the
chess pieces knight, rook, and queen will be used. The pieces behave in the
same way as in standard chess. A rook attacks a square if it is in the same row or column as that rook. A
queen also attacks all squares in the same row and column, but in addition to that, it attacks all squares
along the same diagonals. Knights attack squares that are two rows and one column away or vice versa.
Examples of these moves can be seen in the explanations of the examples.
Note: Each piece also attacks the square on which it is placed. Additionally, pieces attack through other
pieces, i.e., a piece attacks squares according to the rules stated above regardless of whether there is
another piece between the square and the attacking piece.
Vito is preparing for the long-awaited showdown and needs your help. He has decided to practice his quick
observation skills. He will do this by placing \(M\) chess pieces on the board and then determining all the
squares that are attacked. Your task is to determine the number of attacked squares on the given board.
The first line contains pozitive integers \(N\) and \(M\) (\(1 \le N \le 200\), \(1 \le M \le N\) ^{2}).
In the next \(M\) lines, each line contains a single uppercase letter of the English alphabet, representing
the type of piece, which can be one of ’N’, ’R’, and ’Q’, corresponding to knight, rook, and queen,
respectively, and integers \(r_{i}\) and \(c_{i}\) (\(1 \le r_{i}\), \(c_{i} \le N\)), representing the row and column where that piece is
located.
At most one piece can be placed on any square of the board.
In the first and only line, you need to output the number of attacked squares on the board.
| 서브태스크 | 점수 | 설명 |
|---|---|---|
1 | 13점 | All pieces on the board are rooks. |
2 | 19점 | Each piece on the board is either a rook or a queen. |
3 | 18점 | No additional constraints. |
7 1
Q 4 4255 1
N 3 396 3
R 1 4
Q 2 1
N 5 225Clarification of the first and second example: In the sketches, examples are shown. All attacked
squares are marked with a dot, except the one on which the piece is located.
(a) first example
(b) second example