#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
char prime[1000005];
void init_prime() {
  fill(prime, prime + 1000005, 1);
  prime[0] = prime[1] = 0;
  for (int x = 2; x <= 1000000; ++x) {
    if (prime[x]) {
      for (int y = x * x; y <= 1000000; y += x) prime[y] = 0;
    }
  }
}
ll N, Q[101010];
ll memo[101010];
int main() {
  init_prime();
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (int j = 1; j <= N; ++j) cin >> Q[j];
  reverse(Q + 1, Q + N + 1);
  fill(memo, memo + N + 1, 0);
  memo[0] = 1;
  memo[1] = prime[Q[1]] ? 1 : 0;
  for (int j = 2; j <= N; ++j) {
    if (prime[Q[j]]) {
      if (Q[j - 1] > Q[j]) {
        memo[j] = (memo[j] + memo[j - 1]) % MOD;
      }
      if (Q[j - 1] > 1 && (j < 3 || (prime[Q[j - 2]] && Q[j - 2] > Q[j]))) {
        memo[j] = (memo[j] + memo[j - 2]) % MOD;
      }
    }
  }
  cout << memo[N] << endl;
  return 0;
}
