main = do
  getLine
  dominoes <- getLine >>= return . (0:) . f

  print $ h dominoes

  where
    -- 1: vertical, 2: horizontal
    f (x:y:xs) = if x/=y then 1 : (f (y:xs)) else 2 : (f xs)
    f (x:[]) = [1]
    f [] = []

    g :: Int -> Int -> Integer
    g 0 1 = 3
    g 0 2 = 6
    g 1 1 = 2
    g 1 2 = 2
    g 2 1 = 1
    g 2 2 = 3

    h [] = 1
    h (_:[]) = 1
    h (x:y:xs) = ((g x y) * (h (y:xs))) `mod` (10^9+7)
