import Data.List ( elemIndices ) main :: IO () main = do s <- reverse . dropWhile (/= 'w') . reverse . dropWhile (/= 'c') <$> getLine putStrLn . show $ solve s -- given an arg as "" or "c .. w" solve :: [Char] -> Int solve s = if null s || length ys == 1 then -1 else minimum zs where xs = elemIndices 'c' s ys = map succ $ elemIndices 'w' s zs = f ys xs f :: [Int] -> [Int] -> [Int] f _ [] = [] f [x] _ = [] f yss@(y1:y2:ys) xss@(x:xs) = if y1 > x then (y2 - x) : f yss xss else f (y2:ys) xss