import Data.Array.IO
import Control.Applicative
import Data.List
import Control.Monad

main = do
    [n,k] <- map read.words <$> getLine
    xs <- map (format.words) <$> getLineN n :: IO [[Int]]
    let xs' = map (convert k) xs
    putStrLn.show.maximum $ map (count k xs') [(x,y) | x <- [0..2*k-1], y <- [0..2*k-1]] where
        format [x,y,c] = if c == "W" then [read x, read y,0] else [read x,read y,1]

convert :: Int -> [Int] -> (Int,Int)
convert k [x,y,0] = (x `mod` (2*k),y `mod` (2*k))
convert k [x,y,1] = ((x+k) `mod` (2*k),y `mod` (2*k))

count k xs (bx,by) = length $ filter ((==True).g) xs where
    g (px,py) = (abs (px-bx) < k || abs (px-bx) > k+bx) && (abs (py-by) < k || abs (py-by) > k+by)

getLineN :: Int -> IO [String]
getLineN n = replicateM n getLine