#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

void enum_prime(int N, vector<bool>& is_p)
{
  is_p.resize(N+1, true);
  is_p[0] = is_p[1] = false;
  for(int i = 2; i*i <= N; i++) {
    if(!is_p[i]) continue;
    for(int 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 int MAX_Q = 1000000;

  vector<bool> is_p;
  enum_prime(MAX_Q, is_p);

  int n;
  cin >> n;

  vint q(n);
  rep(i, n) cin >> q[i];

  if(!is_p[q[0]]) {
    cout << 0 << endl;
    return 0;
  }

  vector<vint> dp(2, vint(n+1, 0));
  dp[0][0] = 1;
  dp[1][0] = 0;
  reps(i, 1, n) {
    if(is_p[q[i]]) {
      if(q[i-1] < q[i]) (dp[0][i] += dp[0][i-1]) %= mod;
      if(i>1&&q[i-2] < q[i]) (dp[0][i] += dp[1][i-1]) %= mod;
    }
    (dp[1][i] += dp[0][i-1]) %= mod;
  }
  cout << (dp[0][n-1]+dp[1][n-1])%mod << endl;

  return 0;
}

