atcoder#ARC089B. [ABC086D] Checker
[ABC086D] Checker
Score : points
Problem Statement
AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side is a pattern where each square is painted black or white so that each connected component of each color is a square. Below is an example of a checked pattern of side :
AtCoDeer has desires.
The -th desire is represented by , and .
If is B
, it means that he wants to paint the square black; if is W
, he wants to paint the square white.
At most how many desires can he satisfy at the same time?
Constraints
- If , then .
- is
B
orW
. - , , and are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum number of desires that can be satisfied at the same time.
4 3
0 1 W
1 2 W
5 3 B
5 4 B
4
He can satisfy all his desires by painting as shown in the example above.
2 1000
0 0 B
0 1 W
2
6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W
4