#include <bits/stdc++.h>
template <typename T>
void MACRO_VAR_Scan(T& t) {
  std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
  std::cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
  t.resize(n);
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {
  first.resize(n);
  MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T>
void MACRO_VEC_ROW_Scan(int p, T& t) {
  std::cin >> t[p];
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {
  std::cin >> first[p];
  MACRO_VEC_ROW_Scan(p, rest...);
}
template <typename T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <typename T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
void CHECKTIME(std::function<void()> f) {
  auto start = std::chrono::system_clock::now();
  f();
  auto end = std::chrono::system_clock::now();
  auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))
                 .count();
  std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n";
}
template <class T>
std::vector<std::vector<T>> VV(int n, int m, T init = T()) {
  return std::vector<std::vector<T>>(n, std::vector<T>(m, init));
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<ll, ll>;
using PAIRLL = std::pair<ll, ll>;
constexpr ll INFINT = 1 << 30;
constexpr ll INFINT_LIM = (1LL << 31) - 1;
constexpr ll INFLL = 1LL << 60;
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
constexpr double EPS = 1e-9;
constexpr ll MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template <class T, size_t N>
void FILL(T (&a)[N], const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, size_t N, size_t M, class T>
void FILL(ARY (&a)[N][M], const T& val) {
  for (auto& b : a) FILL(b, val);
}
template <class T>
void FILL(std::vector<T>& a, const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, class T>
void FILL(std::vector<std::vector<ARY>>& a, const T& val) {
  for (auto& b : a) FILL(b, val);
}
std::vector<ll> Eratosthenes(ll n) {
  std::vector<ll> num(n + 1, 0);
  num[0] = num[1] = -1;
  ll cnt = 0;
  for (ll i = 2; i * i < n; ++i) {
    if (num[i] == 0) {
      for (ll j = 2; (i + 1) * j <= n; ++j) {
        num[i * j] = -1;
      }
      num[i] = cnt++;
    }
  }
  return num;
}
ll dp[2][2][78500];
ll solve() {
  ll n;
  MACRO_VAR_Scan(n);
  ;
  std::vector<ll> q(n);
  for (auto& i : q) std::cin >> i;
  ;
  auto p(Eratosthenes(1000001));
  if (p[q[0]] == -1) return 0;
  dp[1][0][p[q[0]]] = 1;
  ll mi = p[q[0]], ma = p[q[0]];
  for (ll i = (1); i < (n); ++i) {
    ll nmi = INFINT, nma = -INFINT;
    for (ll j = 0; j < ll(2); ++j) {
      if (p[q[i]] == -1 && j == 1) continue;
      for (ll k = (mi); k < (ma + 1); ++k) {
        if (dp[i & 1][j][k] == 0) continue;
        if (p[q[i]] == -1) {
          (dp[1 - i % 2][1][k] += dp[i % 2][j][k]) %= MOD;
          CHMIN(nmi, k);
          CHMAX(nma, k);
        } else {
          if (k >= p[q[i]]) {
            if (j == 0) {
              (dp[1 - i % 2][1][k] += dp[i % 2][j][k]) %= MOD;
              CHMIN(nmi, k);
              CHMAX(nma, k);
            }
          } else {
            if (j == 0) {
              (dp[1 - i % 2][1][k] += dp[i % 2][j][k]) %= MOD;
              CHMIN(nmi, k);
              CHMAX(nma, k);
            }
            (dp[1 - i % 2][0][p[q[i]]] += dp[i % 2][j][k]) %= MOD;
            CHMIN(nmi, p[q[i]]);
            CHMAX(nma, p[q[i]]);
          }
        }
      }
    }
    if (nmi > nma) return 0;
    mi = nmi;
    ma = nma;
    FILL(dp[i % 2], 0LL);
  }
  ll ans = 0;
  for (ll j = 0; j < ll(2); ++j)
    for (ll k = 0; k < ll(ma + 1); ++k) {
      (ans += dp[n % 2][j][k]) %= MOD;
    }
  return ans;
};
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  std::cout << (solve());
  std::cout << "\n";
  ;
  return 0;
}
