#include <string>
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;

const int MOD=1e9+7;
const int INF=1e10;
const int MAX_N = 1123456;
bool isPrime[MAX_N];
void e(){
  REP(i,MAX_N){
    isPrime[i]=true;
  }
  isPrime[0]=isPrime[1]=false;
  REP(i,MAX_N){
    if(isPrime[i]){
      for(int j = i+i;j<MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
}
bool Is_Prime(int n){
  return isPrime[n];
}
int dp[100005];
signed main(){
  e();
  int n;
  cin>>n;
  vector<int> q(n);
  REP(i,n)cin>>q[i];
  if(Is_Prime(q[0]))dp[0]=1;
  REP(i,n){
    //cout<<dp[i]<<endl;
    if(i+2<n&&q[i]<q[i+2]&&Is_Prime(q[i+2])){
      dp[i+2]+=dp[i];
      dp[i+2]%=MOD;
    }
    if(i+1<n&&q[i]<q[i+1]&&Is_Prime(q[i+1])){
      dp[i+1]+=dp[i];
      dp[i+1]%=MOD;
    }
  }
  cout<<(dp[n-1]+dp[n-2])%MOD<<endl;
  return 0;
}

