#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const int MAX = 1e6+1;
const lli mod = 1e9+7;

int main(){
	vector<bool> prime(MAX, true);
	prime[0] = prime[1] = false;
	for(int i=2; i*i<MAX; i++){
		if(prime[i]){
			for(int j=i*2; j<MAX; j+=i){
				prime[j] = false;
			}
		}
	}
	
	int n;
	cin >> n;
	vector<int> q(n+1, 0);
	for(int i=1; i<=n; i++){
		cin >> q[i];
	}
	
	vector<vector<lli> > dp(n+1, vector<lli>(2, 0));
	dp[0][0] = 1;
	for(int i=0; i<n; i++){
		if(!prime[q[i+1]]) continue;
		for(int j=0; j<2; j++){
			if(dp[i][j] != 0){
				if(q[i-j] < q[i+1]){
					dp[i+1][0] = (dp[i+1][0] +dp[i][j])%mod;
						if(i+2 <= n){
						dp[i+2][1] = (dp[i+2][1] +dp[i][j])%mod;
					}
				}
			}
		}
	}
	cout << (dp[n][0] +dp[n][1])%mod << endl;
	return 0;
}
