#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& o) {
  out << "(" << o.first << "," << o.second << ")";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T> V) {
  for (int i = 0; i < V.size(); i++) {
    out << V[i];
    if (i != V.size() - 1) out << " ";
  }
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<vector<T> > Mat) {
  for (int i = 0; i < Mat.size(); i++) {
    if (i != 0) out << endl;
    out << Mat[i];
  }
  return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const map<S, T> mp) {
  out << "{ ";
  for (auto it = mp.begin(); it != mp.end(); it++) {
    out << it->first << ":" << it->second;
    if (mp.size() - 1 != distance(mp.begin(), it)) out << ", ";
  }
  out << " }";
  return out;
}
bool is_prime[1000005];
const long long MOD = 1e9 + 7;
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
void init() {
  for (int i = 1; i < 1000005; i++) {
    is_prime[i] = IsPrime(i);
  }
}
long long solve() {
  long long N;
  cin >> N;
  vector<long long> q(N);
  for (auto& in : q) cin >> in;
  if (!is_prime[q[0]]) return 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (!is_prime[q[i]])
      cnt++;
    else
      cnt = 0;
    if (cnt == 2) return 0;
  }
  vector<long long> dp(N + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (is_prime[q[i]]) {
      if ((q[i] < q[i + 1])) {
        (dp[i + 1] += dp[i]) %= MOD;
      }
      if ((q[i] < q[i + 2])) {
        (dp[i + 2] += dp[i]) %= MOD;
      }
    }
  }
  return dp[N];
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  init();
  cout << solve() << endl;
  return 0;
}
