#include <iostream>
using namespace std;

long long dp[100009], n, a[100009], mod = 1000000007;
bool prime[1000009];

int main() {
	for (int i = 2; i <= 1000004; i++) prime[i] = true;
	for (int i = 2; i <= 1000; i++) {
		for (int j = i*i; j <= 1000000; j += i) prime[j] = false;
	}
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	if (prime[a[1]] == false) {
		cout << "0" << endl;
		return 0;
	}
	a[n + 1] = 1000003;
	dp[1] = 1;
	for (int i = 1; i <= n; i++) {
		if (a[i + 1] > a[i] && prime[a[i + 1]] == true) dp[i + 1] += dp[i];
		if (a[i + 2] > a[i] && prime[a[i + 2]] == true) dp[i + 2] += dp[i];
		dp[i + 1] %= mod; dp[i + 2] %= mod;
	}
	cout << dp[n + 1] << endl;
	return 0;
}
