#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

const int MAX_P = 1000000; //max
bool prime[MAX_P+1];

void Eratosthenes(void){
  for(int i=2;i<=MAX_P;i++)
    prime[i]=true;
  
  for(int i=2;i*i<=MAX_P;i++)
    if(prime[i])  
      for(int j=i;i*j<=MAX_P;j++)
        prime[i*j]=false;
}


int dp[SIZE][2];


int main(){
  int n;
  int q[SIZE];
  
  Eratosthenes();

  scanf("%d",&n);

  for(int i=1;i<=n;i++){
    scanf("%d",q+i);
  }
  q[0] = 1;

  dp[0][0] = 1;
  
  for(int i=0;i<n;i++){
    if(prime[q[i+1]]){
      if(i < n-1){
        if(q[i] < q[i+1])            dp[i+2][1] = (dp[i+2][1] + dp[i][0])%mod;
        if(i > 0 && q[i-1] < q[i+1]) dp[i+2][1] = (dp[i+2][1] + dp[i][1])%mod;
      }
      if(q[i] < q[i+1])              dp[i+1][0] = (dp[i+1][0] + dp[i][0])%mod;
      if(i > 0 && q[i-1] < q[i+1])   dp[i+1][0] = (dp[i+1][0] + dp[i][1])%mod;
    } 
  }

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


