#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

void enum_prime(int N, vector<bool>& is_p)
{
    is_p.resize(N, true);
    is_p[0] = is_p[1] = false;
    for(int i = 2; i*i <= N; i++) {
        if(!is_p[i]) continue;
        for(int j = i+i; j <= N; j+=i) is_p[j] = false;
    }
}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cout << fixed << setprecision(12);
    
    const int MAX_Q = 1000000;
    
    vector<bool> is_p;
    enum_prime(MAX_Q, is_p);
    
    int n;
    cin >> n;
    vint q(n);
    rep(i, n) cin >> q[i];
    sort(all(q));
    if(!is_p[q[0]]) {
        cout << 0 << endl;
        return 0;
    } else {
        bool flag = true;
        rep(i, n-1) {
            if(!is_p[q[i]] && !is_p[q[i+1]]) flag = false;a
        }
        if(!flag) {
            cout << 0 << endl;
            return 0;
        }
    }
    
    vector<vint> dp(2, vint(n+1, -1));
    dp[0][1] = 1;
    dp[1][1] = 0;
    reps(i, 1, n) {
        if(is_p[q[i]]) {
            if(i > 1 && is_p[q[i-1]] && is_p[q[i-2]]) {
                if(q[i-1] == q[i] && q[i-2] >= q[i]) {
                    cout << 0 << endl;
                    return 0;
                }
            }
            if(is_p[q[i-1]] && q[i-1] > q[i]) {
                dp[0][i+1] = 0;
                dp[1][i+1] = dp[0][i];
            } else if(is_p[q[i-1]] && q[i-1] == q[i]) {
                dp[0][i+1] = dp[1][i];
                dp[1][i+1] = dp[0][i];
            } else {
                dp[0][i+1] = (dp[0][i]+dp[1][i])%mod;
                dp[1][i+1] = dp[0][i];
            }
        } else {
            dp[0][i+1] = 0;
            dp[1][i+1] = dp[0][i];
        }
    }
    cout << (dp[0][n]+dp[1][n])%mod << endl;
    
    return 0;
}


