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

ll dp[100003];
const int max_n=1000001;
bool is_prime[max_n];
int sieve(int n){
    int p=0;
    rep(i,n+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    FOR(i,2,n+1){
        if(is_prime[i]){
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
        }
    }
    return p;
}
int q[100001];
const int mod=1000000007;
int main(){
    int n;
    cin>>n;
    sieve(1000000);
    dp[0]=1;
    rep(i,n) cin>>q[i];
    rep(i,n){
        if(i+2<=n&&is_prime[q[i]]&&(i+2==n||q[i+2]>q[i])){
            dp[i+2]+=dp[i];
            dp[i+2]%=mod;
        }
        if(is_prime[q[i]]&&(i+1==n||q[i+1]>q[i])){
            dp[i+1]+=dp[i];
            dp[i+1]%=mod;
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}
