#include<bits/stdc++.h>
#define int long long
using namespace std;
 
bool prime[1000009];
 
void era(){
    prime[0]=1;
    prime[1]=1;
    for(int i=2;i<1000009;i++){
        if(!prime[i]){
            for(int j=i+i;j<1000009;j+=i) prime[j]=1;
        }
    }
}
 
int dp[100009];
 
signed main(){
    era();
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    if(!prime[a[0]])dp[0]=1;
    for(int i=0;i<n-1;i++){
        if(!prime[a[i]]&&!prime[a[i+1]]&&a[i]<a[i+1])dp[i+1]+=dp[i];
        if(i<n-2&&!prime[a[i]]&&!prime[a[i+2]]&&a[i]<a[i+2])dp[i+2]+=dp[i];
        dp[i+1]%=1000000007;
        dp[i+2]%=1000000007;
    }
    cout<<(dp[n-1]+dp[n-2])%1000000007<<endl;
}
