toBitarray :: String -> Int -> Int -> [Bool] toBitarray s k fullN = replicate (k - 1) True ++ [c == '1' | i <- [k - 1 .. fullN - 1], let c = s !! (i - k + 1)] min_find :: String -> Int -> Int -> Int min_find s n len = changes where weightMin = (len + 1) `div` 2 fullLen = n + weightMin - 1 bits = toBitarray s weightMin fullLen initialHWeight = length . filter id $ take len bits (_, _, changes) = foldl (update weightMin len) (bits, initialHWeight, if initialHWeight < weightMin then 1 else 0) [1 .. fullLen - len] update wm l (xs, hw, ch) i = let hw' = hw - fromEnum (xs !! (i - 1)) + fromEnum (xs !! (i + l - 1)) in if hw' < wm then (take (i + l - 1) xs ++ [True] ++ drop (i + l) xs, hw' + 1, ch + 1) else (xs, hw', ch) main :: IO () main = do n <- readLn s <- getLine print $ min_find s n 3