#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct prime_num{
    int number;
    bool if_prime_num;
};

vector<prime_num> prime_nums;

long dp[int(2e5)];

long choose(int now){
    if(dp[now] != -1){
        return dp[now];
    }else if(now >= int(prime_nums.size()) - 1){
        return dp[now] = 1;
    }else if(!prime_nums[now].if_prime_num && prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = choose(now + 1);
    }else if(!prime_nums[now].if_prime_num){
        return dp[now] = 0;
    }else if(!prime_nums[now + 1].if_prime_num && prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = choose(now + 1);
    }else if(!prime_nums[now + 1].if_prime_num){
        return dp[now] = 0;
    }else if(now == int(prime_nums.size()) - 2 && prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = 2;
    }else if(now == int(prime_nums.size()) - 2){
        return dp[now] = 1;
    }else if(prime_nums[now].number < prime_nums[now + 1].number && prime_nums[now].number < prime_nums[now + 2].number){
        return dp[now] = (choose(now + 1) + choose(now + 2)) % long(1e9 + 7);
    }else if(prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = choose(now + 1);
    }else if(prime_nums[now].number < prime_nums[now + 2].number){
        return dp[now] = choose(now + 2);
    }else{
        return dp[now] = 0;
    }
}

int main(){
    int N;
    cin >> N;
    int if_prime[int(2e6)];
    fill(if_prime, if_prime + int(2e6), -1);
    if_prime[0] = 0;
    if_prime[1] = 0;
    for(int i = 2; i * i <= int(2e6); i++){
        if(if_prime[i] == -1){
            if_prime[i] = 1;
            for(int j = i * 2; j < int(2e6); j += i){
                if_prime[j] = 0;
            }
        }
    }
    int nums[N];
    for(int i = 0; i < N; i++){
        cin >> nums[i];
    }
    if(!if_prime[nums[0]]){
        cout << 0 << endl;
        return 0;
    }
    prime_nums.push_back({nums[0], true});
    for(int i = 1; i < N; i++){
        if(!if_prime[nums[i - 1]] && !if_prime[nums[i]]){
            cout << 0 << endl;
            return 0;
        }else if(!if_prime[nums[i]] && prime_nums.empty()){
            cout << 0 << endl;
            return 0;
        }else if(!if_prime[nums[i]]){
            prime_num insert_item = {prime_nums.back().number, false};
            prime_nums.pop_back();
            prime_nums.push_back(insert_item);
        }else{
            prime_nums.push_back({nums[i], true});
        }
    }
    fill(dp, dp + int(2e5), -1);
    cout << choose(0) << endl;
}

