#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 . 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.
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