output_description: Print the maximum number of desires that can be satisfied at the same time.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      x_1 y_1 c_1
      x_2 y_2 c_2
      :
      x_N y_N c_N
attempt: # import time
  
  # 入力部
  N, K = map(int, input().split())
  data_list = []
  for i in range(N):
      x, y, c = input().split()
      x, y = int(x), int(y)
      data_list.append([x, y, c])
  
  # start = time.time()
  
  # スコア行列[K, K]
  # 白チェッカー左下を(x, y)としたときの正解数-誤答数
  score_matrix = [[0 for x in range(K + 1)] for y in range(K + 1)]
  
  # time1 = time.time()
  
  # 白チェッカー左下が(0, 0)のときの希望の数
  base_hope = 0
  for data in data_list:
      x, y, c = data[0] // K, data[1] // K, data[2]
      x_coord, y_coord = data[0] % K, data[1] % K
      # 正解
      if ((x + y) % 2 == 0 and c == "W") or ((x + y) % 2 == 1 and c == "B"):
          score_matrix[y_coord + 1][x_coord + 1] += 1
          base_hope += 1
      # 誤答
      else:
          score_matrix[y_coord + 1][x_coord + 1] -= 1
  
  # time2 = time.time()
  
  # スコア行列の二次元累積和を求める O(K^2)
  xy = [(x, y) for x in range(1, K + 1) for y in range(1, K + 1)]
  for x, y in xy:
      accum = (
          score_matrix[y][x]
          + score_matrix[y][x - 1]
          + score_matrix[y - 1][x]
          - score_matrix[y - 1][x - 1]
      )
      score_matrix[y][x] = accum
  
  # time3 = time.time()
  
  # 希望行列を累積和に基づき計算していく O(K^2)
  # 同時に最大値を計算
  max_hope = 0
  for x, y in xy:
      diff = (
          score_matrix[K - 1][x - 1]
          + score_matrix[y - 1][K - 1]
          - 2 * score_matrix[y - 1][x - 1]
      )
      hope = base_hope - diff
      true_hope = max(hope, N - hope)
      if true_hope > max_hope:
          max_hope = true_hope
  
  print(max_hope)
  
problem_description: Statement
  
  AtCoDeer is thinking of painting an infinite two-dimensional grid in a
  _checked pattern of side K_. Here, a checked pattern of side K is a pattern
  where each square is painted black or white so that each connected component
  of each color is a K × K square. Below is an example of a checked pattern of
  side 3:
  
  ![cba927b2484fad94fb5ff7473e9aadef.png](https://img.atcoder.jp/arc089/cba927b2484fad94fb5ff7473e9aadef.png)
  
  AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If
  c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i
  is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires
  can he satisfy at the same time?
samples: [{"input": "4 3\n    0 1 W\n    1 2 W\n    5 3 B\n    5 4 B", "output": "4\n    \n\nHe can satisfy all his desires by painting as shown in the example above.\n\n* * *"}, {"input": "2 1000\n    0 0 B\n    0 1 W", "output": "2\n    \n\n* * *"}, {"input": "6 2\n    1 2 B\n    2 1 W\n    2 2 B\n    1 0 B\n    0 6 W\n    4 5 W", "output": "4"}]