#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e+9 + 7;
long long n, m, l;
string s, t;
long long d[200010], dp[550][550];
long long box[200010];
bool prime[100010];
void hurui() {
  memset((prime), (false), sizeof(prime));
  prime[0] = prime[1] = true;
  for (long long i = (2); i < (100010); i++) {
    if (!prime[i]) {
      for (int j = 2; i * j < 100010; j++) prime[i * j] = true;
    }
  }
}
bool isprime(long long num) { return !prime[num]; }
int main() {
  hurui();
  memset((d), (0), sizeof(d));
  vector<int> vec;
  cin >> n;
  long long p, q;
  p = q = 0;
  for (long long i = (1); i <= (n); i++) {
    cin >> d[i];
    if (isprime(d[i]))
      p++;
    else
      q++;
  }
  bool ex = true;
  for (long long i = (1); i <= (n); i++) {
    if (prime[d[i - 1]] && prime[d[i]] && prime[d[i + 1]])
      ex = false;
    else {
      if (d[i] > d[i + 1])
        vec.push_back(1);
      else if (isprime(d[i - 1]) && isprime(d[i]) && isprime(d[i + 1]))
        vec.push_back(2);
      else if (prime[d[i]] && prime[d[i + 1]]) {
        vec.push_back(1);
      } else if (prime[d[i - 1]] && prime[d[i]]) {
        vec.push_back(1);
      }
    }
  }
  if (ex) {
    long long ans = 1;
    for (long long i = (0); i < (vec.size()); i++) {
      ans *= vec[i];
      ans %= INF;
    }
    cout << (ans) << endl;
  } else {
    puts("0");
  }
  return 0;
}
