Scanf.scanf "%d %s %s" (fun n s1 s2 ->
    let ( *@) a b = (a * b) mod 1_000_000_007 in
    let rec loop i prev acc =
        if i = n then acc else
            match prev, s1.[i] = s2.[i] with
            | true,  true  -> loop (i + 1) true  (acc *@ 2)
            | true,  false -> loop (i + 2) false (acc *@ 2)
            | false, true  -> loop (i + 1) true   acc
            | false, false -> loop (i + 2) false (acc *@ 3)
    in
    Printf.printf "%d\n" @@
        if s1.[0] = s2.[0] then loop 1 true 3
                           else loop 2 false 6
)