import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {

    val l: List[Int] = StdIn.readLine().toList.map(_.toString.toInt)
    println(solve(l, false))

  }

  def solve(l: List[Int], smallEnough: Boolean): Int = {

    val r = 1000000007
    l match {
      case Nil => 1
      case 0 :: t =>
        if (smallEnough) {
          solve(t, true) * 3 % r
        } else {
          solve(t, false)
        }
      case _ :: t =>
        if (smallEnough) {
          solve(t, true) * 3 % r
        } else {
          (solve(t, false) * 2 + solve(t, true)) % r
        }
    }

  }

}
