#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &i : v) is >> i;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  const string delimiter = "\n";
  for (int i = (int)(0); i < (int)(v.size()); i++) {
    os << v[i];
    if (i != v.size() - 1) os << delimiter;
  }
  return os;
}
const int N = 1111111;
bool prime[N + 1];
vector<int> primes;
void hurui() {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!prime[i]) continue;
    for (int j = i; i * j < N; j++) {
      prime[i * j] = false;
    }
  }
  for (int i = (int)(0); i < (int)(N + 1); i++) {
    if (prime[i]) {
      primes.push_back(i);
    }
  }
}
long long pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
int n;
vector<int> q;
long long dp[111111];
long long solve(int p) {
  if (dp[p] >= 0) return dp[p];
  if (p == n) return 0;
  if (p == n - 1) {
    if (prime[q[p]])
      return 1;
    else
      return 0;
  }
  long long res = 0;
  if (prime[q[p + 1]] && q[p + 1] > q[p]) res += solve(p + 1);
  if (p + 2 < n && prime[q[p + 2]] && q[p + 2] > q[p]) res += solve(p + 2);
  if (p + 2 == n) return 1;
  return dp[p] = res % MOD;
}
int main() {
  cin.sync_with_stdio(false);
  cout << fixed << setprecision(10);
  memset(dp, -1, sizeof(dp));
  hurui();
  cin >> n;
  q.resize(n);
  cin >> q;
  cout << solve(0) << endl;
  return 0;
}
