#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/


const int N = 1111111;
bool prime[N + 1];
vector<int> primes;

void hurui()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	for (int i = 2; i*i < N; i++)
	{
		if (!prime[i]) continue;
		for (int j = i; i*j < N; j++)
		{
			prime[i*j] = false;
		}
	}
	REP(i, N + 1)
	{
		if (prime[i])
		{
			primes.push_back(i);
		}
	}
}

ll pow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n > 0)
	{
		if (n & 1) res = res * x % mod;
		x = x*x%mod;
		n >>= 1;
	}
	return res;
}

int n;
vi q;
ll dp[111111];

ll solve(int p)
{
	if (dp[p] >= 0) return dp[p];
	if (p == n) return 0;
	if (p == n - 1)
	{
		if (prime[q[p]])	return 1;
		else return 0;
	}
	ll res = 0;
	if (prime[q[p + 1]] && q[p + 1] > q[p])
	{
		res += solve(p + 1);
	}
	if (p + 2 < n && prime[q[p + 2]] && q[p + 2] > q[p])
	{
		res += solve(p + 2);
	}
	if (p + 2 == n)
	{
		res += 1;
	}
	return dp[p] = res % MOD;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	MS(dp, -1);
	hurui();
	cin >> n;
	q.resize(n);
	cin >> q;
	if(prime[q[0]]) cout << solve(0) << endl;
	else cout << 0 << endl;
	return 0;
}
