import Control.Arrow
import Data.List

main :: IO ()
main = interact $ show . day12 . map parse . lines

parse :: String -> (String, [Int])
parse = second (read . ('[' :) . (++ "]") . tail) . break (== ' ')

day12 :: [(String, [Int])] -> Int
day12 = sum . map (uncurry (countArr 0))

part2ify :: (String, [Int]) -> (String, [Int])
part2ify (s, xs) = (intercalate "?" $ replicate 5 s, concat $ replicate 5 xs)

countArr :: Int -> String -> [Int] -> Int
countArr 0 [] [] = 1
countArr _ [] [] = 0
countArr _ ss [] = fromEnum $ not $ any (=='#') ss
countArr streak [] [i] = fromEnum $ streak==i
countArr streak (s:ss) (i:is)
  | s=='.' && streak == 0 = countArr 0 ss (i:is)
  | s=='.' && streak == i = countArr 0 ss is
  | s=='.' = 0
  | s=='#' = countArr (succ streak) ss (i:is)
  | s=='?' = countArr streak ('.':ss) (i:is) + countArr streak ('#':ss) (i:is)
countArr _ _ _ = 0
