import qualified Data.ByteString.Lazy.Char8 as C combi :: Integral a => a -> a combi n = n * (n - 1) `div` 2 solve :: Integral a => C.ByteString -> a solve = snd . C.foldr sol (0, 0) where sol c (w, x) | c == 'w' = (w + 1, x) | c == 'c' && w > 0 = (w, x + combi w) | otherwise = (w, x) main :: IO () main = print . solve =<< C.getContents