#include <iostream>
#define int long long
using namespace std;

int n;
int q[100000];
bool isPrime[1000001];

void setPrime(int n) {
	int i, j;
	for (i = 2; i <= n; i++) isPrime[i] = true; isPrime[0] = isPrime[1] = false;
	for (i = 2; i <= n; i++) {
		if (isPrime[i]) {
			for (j = i * 2; j <= n; j += i)
				isPrime[j] = false;
		}
	}
}

int dp[100001];
int mod = 1000000007;

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> q[i];
	setPrime(1000000);
	
	if (!isPrime[q[0]]) { cout << 0 << endl; return 0; }
	
	dp[0] = 1;
	for (i = 0; i < n; i++) {
		if (i + 1 == n || (isPrime[q[i + 1]] && q[i] < q[i + 1])) {
			dp[i + 1] += dp[i];
			dp[i + 1] %= mod;
		}
		if (i == n - 1) continue;
		if (i + 2 == n || (isPrime[q[i + 2]] && q[i] < q[i + 2])) {
			dp[i + 2] += dp[i];
			dp[i + 2] %= mod;
		}
	}
	cout << dp[n] << endl;
	return 0;
}
