#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll a[100100];
ll dp[2][1001000];
map<ll, ll> id;
bool used[1001000];

vector<int> prime;
bool is_prime[1001000];

int sieve(int n) {//n以下の素数の数を返す
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = 1;
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime.push_back(i);
			id[i] = prime.size() - 1;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = 0;
		}
	}
	return p;
}

int main() {
	sieve(1001000);
	cin >> n;
	rep(i, n)cin >> a[i];
	if (!is_prime[a[0]])cout << 0 << endl;
	else {
		dp[0][0] = 1;
		FOR(i, 1, n) {
			if (is_prime[a[i]]) {
				if (i > 1 && a[i] > a[i - 2])dp[0][i] = (dp[0][i] + dp[1][i - 1]) % MOD;
				if (a[i] > a[i - 1])dp[0][i] = (dp[0][i] + dp[0][i - 1]) % MOD;
				if (is_prime[a[i - 1]])dp[1][i] = (dp[1][i] + dp[0][i - 1]) % MOD;
			}
			else {
				if (is_prime[a[i - 1]])dp[1][i] = (dp[1][i] + dp[0][i - 1]) % MOD;
			}
		}
		cout << mod_add(dp[0][n - 1], dp[1][n - 1]) << endl;
	}
}
