#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[101010];
bool is_prime[1000001];

ll dp[100001][2];

int main(){

  repl(i,2,1000001)is_prime[i]=true;
  for(ll i=2;i<=1000000;i++){
    if(!is_prime[i])continue;
    for(ll j=i*2;j<=1000000;j+=i){
      is_prime[j]=false;
    }
  }

  cin>>n;
  rep(i,n)cin>>a[i];

  if(!is_prime[a[0]]){
    cout<<0<<endl;
    return 0;
  }

  dp[1][0]=1;
  repl(i,1,n){
    rep(j,2){
      if(j){
        if(is_prime[a[i]]&&a[i-2]<a[i]){
          (dp[i+1][0]+=dp[i][j])%=mod;
        }
      }else{
        if(is_prime[a[i]]&&a[i-1]<a[i]){
          (dp[i+1][0]+=dp[i][j])%=mod;
          (dp[i+1][1]+=dp[i][j])%=mod;
        }else{
          (dp[i+1][1]+=dp[i][j])%=mod;
        }
      }
    }
  }

  cout<<(dp[n][0]+dp[n][1])%mod<<endl;
  return 0;
}

