import Data.List main = do d <- readLn cs <- concat . words <$> getContents let gs = (map length . group) cs ans = case (length gs, head cs) of (1, 'o') -> 14 (1, 'x') -> d (2, 'o') -> min 14 (last gs + d) (2, 'x') -> min 14 (head gs + d) (3, 'o') -> let [x,y,z] = gs in if d>=y then x+y+z else max x z + d (3, 'x') -> let [x,y,z] = gs in max (y + min x d) (y + min z d) (_, 'o') -> maximum (iFilter even (zipWith3 (\x y z -> if d>=y then x+y+z else max x z + d) gs (drop 1 gs) (drop 2 gs))) (_, 'x') -> maximum (iFilter odd (zipWith3 (\x y z -> if d>=y then x+y+z else max x z + d) gs (drop 1 gs) (drop 2 gs))) print ans iFilter p xs = [x | (i,x) <- zip [0..] xs, p i]