import Control.Monad
import Control.Monad.ST
import Data.List
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Array.Unboxed
import Data.Array.ST

import qualified Data.ByteString.Char8 as B

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseChar :: Parser Char
parseChar = StateT $ \bs ->
    case B.span (not.isSpace) $ B.dropWhile isSpace bs of
        (c,bs') -> Just(B.head c,bs')

parseInt3 :: Parser (Int,Int,Char)
parseInt3 = liftM3 (,,) parseInt parseInt parseChar

main = do
    (n:k:_)<-map read.words<$>getLine::IO[Int]
    xycs<-unfoldr (runStateT parseInt3) <$> B.getContents::IO[(Int,Int,Char)]
    --
    let sm = mk k xycs
    print $ maximum ([cal1 sm k i j | i<-[0..k-1], j<-[0..k-1]] ++ [cal2 sm k i j | i<-[0..k-1], j<-[0..k-1]])
--
mk :: Int->[(Int,Int,Char)]->UArray (Int,Int) Int
mk k xycs = runSTUArray $ do
    ar <- newArray ((0,0),(k*2-1,k*2-1)) 0::ST s (STUArray s (Int,Int) Int)
    forM_ xycs $ \(x,y,c) -> do
        let xx = flip mod (k*2) $ if c=='B' then x+k else x
        let yy = y `mod` (k*2)
        writeArray ar (xx,yy) =<< (+1) <$> readArray ar (xx,yy)
    forM_ [(i,j)|i<-[0..k*2-1],j<-[1..k*2-1]] $ \(i,j) ->
        writeArray ar (i,j) =<< (+) <$> readArray ar (i,j) <*> readArray ar (i,j-1)
    forM_ [(i,j)|i<-[1..k*2-1],j<-[0..k*2-1]] $ \(i,j) ->
        writeArray ar (i,j) =<< (+) <$> readArray ar (i,j) <*> readArray ar (i-1,j)
    return ar
--
cal1 :: UArray (Int,Int) Int -> Int -> Int -> Int -> Int
cal1 sm k i j = r1 - r2 - r3 + r4 + r5 + r6*2 - r7*2 - r8*2 + r9*2
    where
        r1 = sm ! (k*2-1, k*2-1)
        r2 = sm ! (k*2-1, j+k-1)
        r3 = sm ! (i+k-1, k*2-1)
        r4 = if j==0 then 0 else sm ! (k*2-1, j-1)
        r5 = if i==0 then 0 else sm ! (i-1, k*2-1)
        r6 = sm ! (i+k-1, j+k-1)
        r7 = if i==0 then 0 else sm ! (i-1, j+k-1)
        r8 = if j==0 then 0 else sm ! (i+k-1, j-1)
        r9 = if i==0 || j==0 then 0 else sm ! (i-1, j-1)

cal2 :: UArray (Int,Int) Int -> Int -> Int -> Int -> Int
cal2 sm k i j = r2 + r3 - r4 - r5 - r6*2 + r7*2 + r8*2 - r9*2
    where
        r2 = sm ! (k*2-1, j+k-1)
        r3 = sm ! (i+k-1, k*2-1)
        r4 = if j==0 then 0 else sm ! (k*2-1, j-1)
        r5 = if i==0 then 0 else sm ! (i-1, k*2-1)
        r6 = sm ! (i+k-1, j+k-1)
        r7 = if i==0 then 0 else sm ! (i-1, j+k-1)
        r8 = if j==0 then 0 else sm ! (i+k-1, j-1)
        r9 = if i==0 || j==0 then 0 else sm ! (i-1, j-1)
