import Data.List import Control.Monad main = do d <- readLn cs <- concat . words <$> getContents let gs = (map length . group) (replicate 14 'x' ++ cs ++ replicate 14 'x') ans = do guard (length gs > 2) let ansh = let (_:h:_) = gs in h + d anst = let (_:t:_) = reverse gs in t + d ansi = map (\t -> if null t then d else let [x,y,z] = t in if d>=y then x+y+z else max x z + d) (windows3 (init (tail gs))) pure (maximum [ansh, anst, maximum ansi]) print (maybe d id ans) windows3 xs = [g | (i,g) <- zip [0..] (zipWith3 (\x y z -> [x,y,z]) xs (drop 1 xs) (drop 2 xs)), even i]