main = do
    getLine
    s1 <- getLine
    let (p,c,cs) | length s1 == 1 = (True,3,[])
                 | x == y = (False,6,xs)
                 | x /= y = (True,3,(y:xs))
                 where (x:y:xs) = s1
    print $ solve p c cs

solve _ c [] = c
solve p c (x:[]) | p = (c * 2) `mod` 1000000007
                 | otherwise = c
solve p c (x:y:xs) | p && x == y = solve (not p) ((c*2) `mod` 1000000007) xs
                   | not p && x == y = solve p ((c*3) `mod` 1000000007) xs
                   | p = solve p ((c*2) `mod` 1000000007) (y:xs)
                   | otherwise = solve (not p) c (y:xs)