{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import Data.Bool

main :: IO ()
main = do
  { s <- getLine
  ; print $ solve s
  }

{- |
>>> solve "BBW"
2
>>> solve "BWBWBW"
6
-}
solve :: String -> Int
solve = hyloL 0 (+) (null . snd) psi . (0,)
  where
    psi (b, 'W':s) = (b, (b, s))
    psi (b, 'B':s) = (0, (succ b, s))

hyloL :: c -> (b -> c -> c) -> (a -> Bool) -> (a -> (b, a)) -> a -> c
hyloL e phi p psi x = bool (case psi x of (y, x') -> phi y (hyloL e phi p psi x')) e (p x)
