#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

const ll MOD = (1e9+7);

#define MAX_NUM 1000000
bool era[MAX_NUM+1]={false};

void makeERA(){
    for(int i=2;i<MAX_NUM;i++){
        if(era[i]==true){
            int x=MAX_NUM/i;
            for(int j=2;j<=x;j++){
                era[i*j]=false;
            }
        }
    }
    era[2]=true;
}

int main(){
    for(int i=0;i<MAX_NUM;i++)era[i]=true;
    era[0]=false;era[1]=false;
    makeERA();
    
    int n;
    cin>>n;
    vector<int> q(n);
    rep(i,n)cin>>q[i];
    
    
    static ll dp[100001][2];
    rep(i,100001)rep(j,2)dp[i][j] = 0;
    if(era[q[0]]){
        dp[0][0] = 1;
        dp[1][1] = 1;
    }
    
    
    for(int i=1;i<n;i++){
        rep(j,2){
            rep(l,2){
                if( era[q[i-j]] == false )dp[i][j] = 0;
                else{
                    if(i-1-j-l>=0 && q[i-j]>q[i-1-j-l]){
//                        cout<<i<<" "<<j<<" = "<<i-1-j<<" "<<l<<endl;
                        (dp[i][j] += dp[i-1-j][l])%=MOD;
                    }
                }
            }
        }
    }
    
    cout<<(dp[n-1][0] + dp[n-1][1])%MOD<<endl;
}

