#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
ll n,dp[100005][2],a[100005];
bool p[1000005];
int main(void){
    for(int i=2;i<=1000;i++)if(!p[i])for(int j=i*2;j<=1000000;j+=i)p[j]=true;
    scanf("%lld",&n);
    for(int i=0;i<n;i++)scanf("%lld",a+i);
    if(!p[a[0]])dp[1][0]=1;
    for(int i=1;i<n;i++){
        dp[i+1][1]=(dp[i+1][1]+dp[i][0])%M;
        if(!p[a[i]]&&a[i-1]<a[i])dp[i+1][0]=(dp[i+1][0]+dp[i][0])%M;
        if(i>1&&!p[a[i]]&&a[i-2]<a[i])dp[i+1][0]=(dp[i+1][0]+dp[i][1])%M;
    }
    cout<<(dp[n][0]+dp[n][1])%M<<endl;
}

