#include <bits/stdc++.h>
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;

int n;
long long q[1000010];
bool b[1000010];
long long memo[100010][2];

long long solve(int i = 0, int prevIsE = true) {
	int pear = 1, berry = 1;
	bool flaga = false, flagb = false;
	if (i == n) {
		return 1;
	}
	if (memo[i][prevIsE] != -1) {
		return memo[i][prevIsE];
	}
//	cout << i << " " << b[q[i]] << " " << q[i - 1 - prevIsE] << " " << q[i] << endl;
	if (i != 0 && b[q[i]] && q[i - 1 - prevIsE] < q[i]
	 || i == 0 && b[q[i]]) {
//	if (sosu[q[i]] && prevSosu < q[i]) {
//		cout << i << " is q" << endl;
		pear = pear * solve(i + 1, false) % MOD;
		flaga = true;
	}
	if (!prevIsE) {
//		cout << i << " is e" << endl;
		berry = berry * solve(i + 1, true) % MOD;
		flagb = true;
	}
	pear *= flaga;
	berry *= flagb;
//	cout << i << " " << pear + berry << endl;
	return memo[i][prevIsE] = (pear + berry) % MOD;
}


signed main() {
	cin >> n;
	rep (i, n) {
		cin >> q[i];
		b[q[i]] = true;
		for (int j = 2; j * j <= q[i]; j++) b[q[i]] = b[q[i]] && (q[i] % j != 0);
	}
	rep (i, 100010) rep (j, 2) memo[i][j] = -1;
	cout << solve() << endl;
	return 0;
}
