import Data.List (group)

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  s1 <- group <$> getLine :: IO [String]
  s2 <- group <$> getLine :: IO [String]
  let s = zipWith (\x y-> if x==y then 1 else 2) s1 s2
  let f x (l, a) | x == 1 && l == 1 = (x, a*2`mod`1000000007)
                 | x == 1 && l == 2 = (x, a)
                 | x == 2 && l == 1 = (x, a*2`mod`1000000007)
                 | otherwise = (x, a*3)
  print $ foldr f (0, 1) s
