import Data.List import Control.Monad main = do n <- readLn :: IO Int a <- replicateM n readLn :: IO [Int] print $ solve a md :: Int md = 10^9 + 7 type Stat = (Int, Int, Int, Int) solve :: [Int] -> Int solve a = let b = foldl' g [((i, j, i, j), 1) | i <- [0,1], j <- [0,1]] a in modsum . map snd . filter (\((h1, h2, x, y), _) -> h1 == x && h2 == y) $ b where g :: [(Stat, Int)] -> Int -> [(Stat, Int)] g acc a = compress (acc >>= f a) f :: Int -> (Stat, Int) -> [(Stat, Int)] f a ((h1, h2, x, y), cnt) = [((h1, h2, y, z), cnt) | z <- [0, 1], rule x y z == a] compress :: [(Stat, Int)] -> [(Stat, Int)] compress a = map f . groupBy (\x y -> fst x == fst y) $ a where f :: [(Stat, Int)] -> (Stat, Int) f x = let key = fst (head x); val = modsum . map snd $ x in (key, val) modsum :: [Int] -> Int modsum = foldl' (\x y -> (x + y) `mod` md) 0 rule :: Int -> Int -> Int -> Int rule 0 0 0 = 0 rule 0 0 1 = 1 rule 0 1 0 = 1 rule 0 1 1 = 1 rule 1 0 0 = 0 rule 1 0 1 = 1 rule 1 1 0 = 1 rule 1 1 1 = 0