#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define mod 1000000007
using namespace std;

bool prime[1000010];
long long dp[1000000];
int q[1000000];

int main(){
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,1000000){
		for(int j=2*i;j<1000000;j+=i)prime[j]=false;
	}
	int n;
	cin>>n;
	rep(i,n)cin>>q[i];
	dp[1]=(prime[q[0]]?1:0);
	loop(i,1,n+1){
		dp[i]%=mod;
		if(prime[q[i+1]]&&q[i-1]<q[i+1])dp[i+2]+=dp[i];
		if(prime[q[i]]&&q[i-1]<q[i])dp[i+1]+=dp[i];
	}
	cout<<(dp[n]+dp[n-1])%mod<<endl;
	return 0;
}
