import Control.Applicative
import Data.List

cut = 1000000007

searchtate0 :: Integer -> String -> String ->[Integer]
searchtate0 count [] ss2 = []
searchtate0 count (s1:ss1) (s2:ss2)
    |s1 == s2 = count:(searchtate0 (count+1) ss1 ss2)
    |otherwise = searchtate0 (count+1) ss1 ss2

searchtate = searchtate0 0

solver0 [x]=1
solver0 (x:y:xs) = (2*3^(max (((y-x-1)`div`2)-1) 0))* (solver0 (y:xs)) `mod` cut

sol2 (x:xs)
    |x==0 = 3
    |otherwise = 6

main :: IO ()
main = do
    getLine
    s1 <-  getLine
    s2 <-  getLine
    putStrLn $ show $ ((sol2 $ searchtate s1 s2)*(solver0 $ searchtate s1 s2))`mod` cut

