object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt

  val numbers = readLine.trim.split(' ').map(_.toInt)
  val mod = 1000000007L
  println(
    calPattern(numbers)
  )
  def calPattern(numbers: Array[Int]): Long = {
    val memo = Array.tabulate(n){_ ⇒ Array.tabulate(2){_ ⇒ None: Option[Long]}}
    val prime = primes(1000000)
    def sub(number: List[Int], position: Int, lastPrime: Int, count: Int = 0): Long = {
      number match {
        case Nil ⇒ 1L
        case p::t ⇒
          memo(position)(count) match {
            case Some(r) ⇒ r
            case None if lastPrime < p ⇒
              (binarySearch(prime, p) match {
                case Some(_) ⇒
                  t match {
                    case e::rest ⇒ (sub(rest, position + 2, p, 1) + sub(t, position + 1, p, 0)) % mod
                    case Nil ⇒ 1L
                  }
                case None ⇒ 0L
              }).also{r ⇒ memo(position)(count) = Some(r)}
            case None ⇒
              memo(position)(count) = Some(0L)
              0L
          }
      }
    }
    sub(numbers.toList, 0, 0)
  }
  def binarySearch(array: Array[Int], target: Int): Option[Int] = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (array(mid) < target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    if (right < array.length && array(right) == target) Some(right)
    else None
  }
  def primes(upper: Int): Array[Int] = {
    val memo = Array.tabulate(upper + 1){_ ⇒ true}
    for (i ← 2 to math.sqrt(upper).toInt){
      if (memo(i)){
        for (j ← i * 2 to upper by i){
          memo(j) = false
        }
      }
    }
    (2 to upper).filter(i ⇒ memo(i)).toArray
  }


  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
