#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const lint mod=1e9+7;
const int K=1e6+10;

int pr[K];
void init(){
  rep(i,K)if(i>=2)pr[i]=1;
  for(int i=2;i<K;++i){
    if(!pr[i])continue;
    for(int j=2;j*i<K;++j)pr[i*j]=0;
  }
}

const int N=110000;
lint dp[N];

int main(){
  init();
  int n;
  cin>>n;
  vi q(n+1);
  rep(i,n)cin>>q[i];
  q[n]=K;
  dp[n]=1;
  for(int i=n-1;i>=0;--i){
    if(pr[q[i]]&&q[i]<q[i+1]){
      dp[i]=(dp[i]+dp[i+1])%mod;
    }
    if(i<n-1&&pr[q[i]]&&q[i+1]>=2&&q[i]<q[i+2]){
      dp[i]=(dp[i]+dp[i+2])%mod;
    }
  }
  cout<<dp[0]<<endl;
}

