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

const int M = 1000000007;

int main() {
    int isp[1000010] = {};
    for (int i = 2; i < 1000010; i++) isp[i] = 1;
    for (int i = 2; i * i < 1000010; i++) if (isp[i]) for (int j = i * i; j < 1000010; j += i) isp[j] = 0;

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<long long>> dp(n, vector<long long>(2));
    dp[0][0] = isp[a[0]];
    for (int i = 1; i < n; ++i) {
        if (a[i] > a[i - 1] && isp[a[i]]) {
            dp[i][0] = (dp[i][0] + dp[i - 1][0]) % M;
        }
        if (i > 1 && a[i] > a[i - 2] && isp[a[i]]) {
            dp[i][0] = (dp[i][0] + dp[i - 2][0]) % M;
        }
        dp[i][1] = dp[i - 1][0];
    }
    cout << (dp[n - 1][0] + dp[n - 1][1]) % M << "\n";
    return 0;
}

