// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX 1000100
int MOD=1000000007;
int sosu[MAX]={1,1,0};
vi sos;
void init(){
	for(int i=2;i*i<=MAX;i++)if(!sosu[i])
	for(int j=i*2;j<MAX;j+=i)sosu[j]=true;
	rep(i,MAX)if(sosu[i]==0)sos.pb(i);
}
int main(){
	init();
	int n;
	cin>>n;
	vi in(n+1,inf);
	rep(i,n)cin>>in[i];
	
	if(n==1){
		cout<<!sosu[in[0]]<<endl;
		return 0;
	}
	
	vi dp(n+1);
	dp[n]=1;
	if(!sosu[in[n-1]])dp[n-1]=1;
	for(int i=n-2;i>=0;i--)if(!sosu[in[i]]){
		if(in[i]<in[i+1])(dp[i]+=dp[i+1])%=MOD;
		if(in[i]<in[i+2])(dp[i]+=dp[i+2])%=MOD;
	}
	cout<<dp[0]<<endl;
}





