#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][2];
 
signed main(){
    era();
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)scanf("%ld",&a[i]);
    if(!prime[a[0]]){
        dp[0][0]=1;
        dp[0][1]=1;
    }
    for(int i=0;i<n;i++){
 
        // 1
 
        if( i+1<n && a[i]<a[i+1] &&!prime[a[i+1]] )dp[i+1][0] += dp[i][0];
        if( i+2<n && a[i]<a[i+1] &&!prime[a[i+1]] )dp[i+1][1] += dp[i][0];
 
        // 2
 
        if( i+2<n && a[i]<a[i+2] &&!prime[a[i+2]] )dp[i+2][0] += dp[i][1];
        if( i+3<n && a[i]<a[i+2] &&!prime[a[i+2]] )dp[i+2][1] += dp[i][1];
 
        dp[i+1][0]%=1000000007;
        dp[i+1][1]%=1000000007;
        dp[i+2][0]%=1000000007;
        dp[i+2][1]%=1000000007;
    }
    cout<<(dp[n-1][0]+dp[n-2][1])%1000000007<<endl;
}
