#include <bits/stdc++.h>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

bool isp[1111111];

ll dp[100010][2];

void era(){
	isp[0] = isp[1] = true;
	for(int i = 2 ; i < 1000001;i++){
		if(!isp[i]){
			for(int j = 2*i;j < 1000001;j += i){
				isp[j] = true;
			}
		}
	}
}

int main()
{
	era();
	
	//SHOW1d(isp,100);
	
	int n;cin >> n;
	vector<int> v(n);
	REP(i,n){
		cin >> v[i];
	}
	
	dp[0][0] = 1;
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 2;j++){
			if(dp[i][j]){
				if(j == 0){
					if((i == 0 && !isp[v[i]]) ||(i > 1 && !isp[v[i]] && v[i] > v[i-2])){
						dp[i+1][1] = (dp[i+1][1] + dp[i][0]) % MOD;
					}
				}
				else{
					if(!isp[v[i]] && v[i] > v[i-1]){
						dp[i+1][1] = (dp[i+1][1] + dp[i][j]) %MOD;
					}
					dp[i+1][0] = (dp[i+1][0] + dp[i][j]) % MOD;
				}
			}
		}
	}
	
	//REP(i,n+1)cout << dp[i][0] << ' ';cout << endl;
	//REP(i,n+1)cout << dp[i][1] << ' ';cout << endl;
	
	cout << (dp[n][0] + dp[n][1]) % MOD << endl;

	return 0;
}
