#include <bits/stdc++.h>
using namespace std;
bool prime[1000009];
void era() {
  prime[0] = 1;
  prime[1] = 1;
  for (long long i = 2; i < 1000009; i++) {
    if (!prime[i]) {
      for (long long j = i + i; j < 1000009; j += i) prime[j] = 1;
    }
  }
}
long long dp[100009][2];
signed main() {
  era();
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) scanf("%d", &a[i]);
  if (!prime[a[0]]) {
    dp[0][0] = 1;
    dp[0][1] = 1;
  }
  for (long long i = 0; i < n; i++) {
    if (i + 1 < n && a[i] < a[i + 1] && !prime[a[i + 1]])
      dp[i + 1][0] += dp[i][0];
    if (i + 2 < n && a[i] < a[i + 1] && !prime[a[i + 1]])
      dp[i + 1][1] += dp[i][0];
    if (i + 2 < n && a[i] < a[i + 2] && !prime[a[i + 2]])
      dp[i + 2][0] += dp[i][1];
    if (i + 3 < n && a[i] < a[i + 2] && !prime[a[i + 2]])
      dp[i + 2][1] += dp[i][1];
    dp[i + 1][0] %= 1000000007;
    dp[i + 1][1] %= 1000000007;
    dp[i + 2][0] %= 1000000007;
    dp[i + 2][1] %= 1000000007;
  }
  cout << (dp[n - 1][0] + dp[n - 2][1]) % 1000000007 << endl;
}
