#include <bits/stdc++.h>

using namespace std;

vector< bool > get_prime(int n) {
  vector< bool > prime(n + 1, true);

  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;

  for(int i = 2; i * i <= n; i++) {
    if(prime[i]) {
      for(int j = i + i; j <= n; j += i) prime[j] = false;
    }
  }

  return (prime);
}

auto table = get_prime(1000000);
const int mod = 1e9 + 7;

int N, Q[100000];
int dp[100000];

int rec(int idx) {
  if(idx == N) return 1;
  if(~dp[idx]) return dp[idx];
  if(!table[Q[idx]]) return dp[idx] = 0;
  int ret = 0;
  if(idx + 1 == N || Q[idx] < Q[idx + 1]) {
    (ret += rec(idx + 1)) %= mod;
  }
  if(idx + 1 < N) {
    if(Q[idx + 1] > 1) {
      if(idx + 2 == N || Q[idx] < Q[idx + 2]) {
        (ret += rec(idx + 2)) %= mod;
      }
    }
  }
  return dp[idx] = ret;
}

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> Q[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0) << endl;
}
