/*  -*- coding: utf-8 -*-
 *
 * 2870.cc: The Diversity of Prime Factorization
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_P = 1000000;
const int MOD = 1000000007;

/* typedef */

/* global variables */

bool primes[MAX_P + 1];
int qs[MAX_N], dp[MAX_N][2];

/* subroutines */

void gen_primes(int maxp) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  for (int p = 2; p * p <= maxp; p++)
    if (primes[p])
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
}

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  gen_primes(MAX_P);

  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", qs + i);

  if (! primes[qs[0]]) {
    puts("0");
    return 0;
  }

  dp[0][0] = 1;
  for (int i = 1; i < n; i++) {
    if (primes[qs[i]]) {
      if (primes[qs[i - 1]] && qs[i - 1] < qs[i])
	addmod(dp[i][0], dp[i - 1][0]);
      if (i >= 2 && primes[qs[i - 2]] && qs[i - 2] < qs[i])
	addmod(dp[i][0], dp[i - 1][1]);
    }

    dp[i][1] = dp[i - 1][0];
  }
  //for (int i = 0; i < n; i++) printf("%d,%d ", dp[i][0], dp[i][1]);

  printf("%d\n", (dp[n - 1][0] + dp[n - 1][1]) % MOD);
  return 0;
}

