#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(iinclude<snt i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

typedef pair<int, P> speP;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int h, w;
char mp[50][50];
int d[50][50];
void solve() {
	int n;
	cin >> n;
	vector<int> a(n+1);
	rep(i, n)cin >> a[i+1];
	vector<ll> dp(n+1), dp2(n+1);
	vector<int> isprime(1000001, 1);
	isprime[0] = isprime[1] = 0;
	for (int i = 2; i <= 1000000; ++i) {
		if (!isprime[i])continue;
		for (int j = 2 * i; j <= 1000000; j += i) {
			isprime[j] = false;
		}
	}
	dp[0] = 1;
	rep(i, n) {
		dp[i + 1] += dp2[i];
		if (a[i + 1] > a[i] && isprime[a[i + 1]])(dp2[i + 1] += dp2[i])%=mod;
		if (i >= 1 && a[i + 1] > a[i - 1] && isprime[a[i + 1]])(dp2[i + 1] += dp[i]) %= mod;
		if (i ==0  && isprime[a[i + 1]])dp2[i + 1] += dp[i];
	}
	cout << (dp[n] + dp2[n]) % mod << endl;

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	stop
		return 0;
}
