#include <iostream>
using namespace std;
typedef long long ll;
#define M 1000000007
int n,q[100005];
ll dp[2][100005];
bool s[1000005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>q[i];
    for(int i=2;i<=1000;i++){
        if(!s[i]){
            for(int j=i*2;j<=1000000;j+=i)s[j]=true;
        }
    }
    if(!s[q[0]])dp[1][1]=1;
    for(int i=1;i<n;i++){
        dp[0][i+1]=dp[1][i];
        if(!s[q[i]]){
            if(i>0&&q[i-1]<q[i])dp[1][i+1]=dp[1][i];
            if(i>1&&q[i-2]<q[i])dp[1][i+1]=(dp[1][i+1]+dp[0][i])%M;
        }
    }
    cout<<(dp[0][n]+dp[1][n])%M<<endl;
}
