#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007 
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
long long dp[300000][2] = {};
int sosuu(int now) {
	for (int q = 2; q <= sqrt(now); ++q) {
		if (now%q == 0) return 0;
	}
	return 1;
}
int main() {
	int n;
	cin >> n;
	vector<int> a;
	a.push_back(0);
	REP(i, n) {
		int b;
		cin >> b;
		a.push_back(b);
	}
	dp[0][0] = 1;
	dp[1][1] = -1;
	n++;
	for (int i = 1; i < n; ++i) {
		if (sosuu(a[i]) == 1) {
			//back 2
			if (sosuu(a[i-1]) == 1&&a[i - 1] < a[i]) {
				dp[i][0] += dp[i - 1][0];
			}
			if (i >= 2 && sosuu(a[i - 2]) == 1 && a[i - 2] < a[i]) {
				dp[i][0] += dp[i - 1][1];
			}
			dp[i][0] %= MAX_MOD;
		}
		dp[i][1] += dp[i - 1][0];
		dp[i][1] %= MAX_MOD;
	}
	cout << (dp[n - 1][0] + dp[n - 1][1]) % MAX_MOD << endl;
	return 0;
}
