import Data.List

main = do
    _ <- getLine
    ss <- lines <$> getContents
    let s = normalize (ss!!0) (ss!!1)
    print . (`mod` 1000000007) . foldl' (*) (unit (head s)) $ zipWith solve s (drop 1 s)

normalize [] [] = []
normalize (x:xs) (y:ys)
    | x == y = 1:normalize xs ys
    | otherwise = 2:normalize (drop 1 xs) (drop 1 ys)

unit 1 = 3
unit 2 = 6

solve 2 2 = 3
solve 2 1 = 1
solve 1 2 = 2
solve 1 1 = 2
