object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val s = sc.next()

  val mod = 1000000007
  def times(a: Long, b: Long): Long = (a * b) % mod

  def toIntList(s: List[Char]): List[Int] = {
    s match {
      case c1 :: c2 :: rest if c1 == c2 => 2 :: toIntList(rest)
      case _ :: rest => 1 :: toIntList(rest)
      case Nil => Nil
    }
  }

  val t = toIntList(s.toList)
  var ans = 3L * t.head

  if (t.length >= 2) {
    ans = t.sliding(2).map{ case List(a1, a2) => (a1, a2) match {
      case (1, 1) => 2L
      case (1, 2) => 2L
      case (2, 1) => 1L
      case (2, 2) => 3L
    }}.foldLeft(ans)(times)
  }

  println(ans)
}
