#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  const Int MAX = 1e6+10;
  vector<Int> p(MAX,0);
  for(Int i=2;i<MAX;i++){
    if(p[i]) continue;
    for(Int j=i+i;j<MAX;j+=i) p[j]=1;
  }
  Int n;
  cin>>n;
  vector<Int> q(n);
  for(Int i=0;i<n;i++) cin>>q[i];

  vector<Int> dp(n+1,0);
  const Int MOD = 1e9+7;
  dp[0]=!p[q[0]];
  for(Int i=0;i<n;i++){
    if(i+1==n) (dp[i+1]+=dp[i])%=MOD;
    if(i+2==n) (dp[i+2]+=dp[i])%=MOD;

    if(i+1<n&&!p[q[i+1]]&&q[i]<q[i+1]) (dp[i+1]+=dp[i])%=MOD;
    if(i+2<n&&!p[q[i+2]]&&q[i]<q[i+2]) (dp[i+2]+=dp[i])%=MOD;
  }

  cout<<dp[n]<<endl;
  return 0;
}

