#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <class T1, class T2>
void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
using Pi = pair<long long, long long>;
using Tapris = tuple<long long, long long, long long>;
using vint = vector<long long>;
const long long inf = 1LL << 55;
const long long mod = 1e9 + 7;
void enum_prime(long long N, vector<bool> &is_p) {
  is_p.resize(N, true);
  is_p[0] = is_p[1] = false;
  for (long long i = 2; i * i <= N; i++) {
    if (!is_p[i]) continue;
    for (long long j = i + i; j <= N; j += i) is_p[j] = false;
  }
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  const long long MAX_Q = 1000000;
  vector<bool> is_p;
  enum_prime(MAX_Q, is_p);
  long long n;
  cin >> n;
  vint q(n);
  for (long long i = (long long)(0); i < (long long)(n); i++) cin >> q[i];
  if (!is_p[q[0]]) {
    cout << 0 << endl;
    return 0;
  } else {
    bool flag = true;
    for (long long i = (long long)(0); i < (long long)(n - 1); i++) {
      if (!is_p[q[i]] && !is_p[q[i + 1]]) flag = false;
    }
    if (!flag) {
      cout << 0 << endl;
      return 0;
    }
  }
  vector<vint> dp(2, vint(n + 1, -1));
  dp[0][1] = 1;
  dp[1][1] = 0;
  for (long long i = (long long)(1); i < (long long)(n); i++) {
    if (is_p[q[i]]) {
      if (i > 1 && is_p[q[i - 1]] && is_p[q[i - 2]]) {
        if (q[i - 1] == q[i] && q[i - 2] >= q[i]) {
          cout << 0 << endl;
          return 0;
        }
      }
      if (is_p[q[i - 1]] && q[i - 1] > q[i]) {
        dp[0][i + 1] = 0;
        dp[1][i + 1] = dp[0][i];
      } else if (is_p[q[i - 1]] && q[i - 1] == q[i]) {
        dp[0][i + 1] = dp[1][i];
        dp[1][i + 1] = dp[0][i];
      } else {
        dp[0][i + 1] = (dp[0][i] + dp[1][i]) % mod;
        dp[1][i + 1] = dp[0][i];
      }
    } else {
      dp[0][i + 1] = 0;
      dp[1][i + 1] = dp[0][i];
    }
  }
  cout << (dp[0][n] + dp[1][n]) % mod << endl;
  return 0;
}
