#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1010000

enum Type{
	prime,
	mult,
};

bool is_prime[NUM];
ll table[100001];
ll dp[100001][2];

int main(){

	for(int i = 0; i < NUM; i++)is_prime[i] = true;

	is_prime[0] = false;
	is_prime[1] = false;

	for(int i = 2; i <= sqrt(NUM); i++){
		if(is_prime[i]){
			for(int k = 2*i; k < NUM; k += i){
				is_prime[k] = false;
			}
		}
	}

	int N;
	scanf("%d",&N);

	for(int i = 0; i < N; i++)scanf("%lld",&table[i]);

	if(!is_prime[table[0]]){
		printf("0\n");
		return 0;
	}

	for(int i = 0; i < N; i++){
		dp[i][prime] = 0;
		dp[i][mult] = 0;
	}

	dp[0][prime] = 1;

	for(int i = 1; i <= N-1; i++){
		dp[i][mult] += dp[i-1][prime];

		if(is_prime[table[i]]){

			if(table[i-1] < table[i] && is_prime[table[i-1]] == true){
				dp[i][prime] += dp[i-1][prime];
			}

			if(i >= 2 && table[i-2] < table[i] && is_prime[table[i-2]] == true){
				dp[i][prime] += dp[i-1][mult];
			}
		}
		dp[i][mult] %= MOD;
		dp[i][prime] %= MOD;
	}

	ll ans = dp[N-1][prime]+dp[N-1][mult];
	ans %= MOD;

	printf("%lld\n",ans);

	return 0;
}

