#arc089b. [arc089_b]Checker

[arc089_b]Checker

Problem Statement

AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side KK. Here, a checked pattern of side KK is a pattern where each square is painted black or white so that each connected component of each color is a KK ×× KK square. Below is an example of a checked pattern of side 33:

cba927b2484fad94fb5ff7473e9aadef.png

AtCoDeer has NN desires. The ii-th desire is represented by xix_i, yiy_i and cic_i. If cic_i is B, it means that he wants to paint the square (xi,yi)(x_i,y_i) black; if cic_i is W, he wants to paint the square (xi,yi)(x_i,y_i) white. At most how many desires can he satisfy at the same time?

Constraints

  • 11 NN 10510^5
  • 11 KK 10001000
  • 00 xix_i 10910^9
  • 00 yiy_i 10910^9
  • If ii jj, then (xi,yi)(x_i,y_i) (xj,yj)(x_j,y_j).
  • cic_i is B or W.
  • NN, KK, xix_i and yiy_i are integers.

Input

Input is given from Standard Input in the following format:

NN KK x1x_1 y1y_1 c1c_1 x2x_2 y2y_2 c2c_2 :: xNx_N yNy_N cNc_N

Output

Print the maximum number of desires that can be satisfied at the same time.


Sample Input 1

4 3
0 1 W
1 2 W
5 3 B
5 4 B

Sample Output 1

4

He can satisfy all his desires by painting as shown in the example above.


Sample Input 2

2 1000
0 0 B
0 1 W

Sample Output 2

2

Sample Input 3

6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W

Sample Output 3

4