#pragma warning disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();
    int mod = 1000000007;

    void Solve()
    {
        int N = cin.Nextint;
        var Q = cin.Scanint;
        eratos(Q.Max());

        if (!is_prime[Q[0]])
        {
            Console.WriteLine(0);
            return;
        }

        var dp = new long[N, 2];
        dp[0, 1] = 1;
        for (int i = 1; i < N; i++)
        {
            dp[i, 0] = dp[i - 1, 1];
            if (is_prime[Q[i]] && Q[i - 1] < Q[i]) dp[i, 1] += dp[i - 1, 1];
            if (is_prime[Q[i]] && i - 2 >= 0 && Q[i - 2] < Q[i]) dp[i, 1] += dp[i - 1, 0];
            dp[i, 1] %= mod;
        }
        Console.WriteLine((dp[N - 1, 0] + dp[N - 1, 1]) % mod);

        //long zero = 1; int zero_prime = 0;
        //long one = 0; int one_prime = 0;

        //for (int i = 1; i < N; i++)
        //{
        //    long tmp = one;
        //    if (is_prime[Q[i]])
        //    {
        //        if (Q[i - 1] < Q[i] && Q[i - 2] < Q[i])
        //        {
        //            long tmp = one;
        //            one = (zero + one) % mod;
        //            zero = tmp;
        //            zero_prime = one_prime;
        //            one_prime = Q[i];
        //        }
        //        else if (zero_prime < Q[i])
        //        {
        //            long tmp = one;
        //            one = zero;
        //            zero = tmp;
        //            zero_prime = one_prime;
        //            one_prime = Q[i];
        //        }
        //        else if (one_prime < Q[i])
        //        {
        //            zero = one;
        //            one_prime = Q[i];
        //        }
        //        else
        //        {
        //            zero = one;
        //            one = 0;
        //            one_prime = 0;
        //        }
        //    }

        //    //Console.WriteLine(one + " " + zero);
        //}

        //Console.WriteLine((one + zero) % mod);

    }



    List<int> prime;
    bool[] is_prime;
    void eratos(int n)
    {
        prime = new List<int>();
        is_prime = new bool[n + 1];
        for (int i = 0; i <= n; i++) is_prime[i] = true;
        is_prime[0] = is_prime[1] = false;
        for (int i = 0; i <= n; i++)
        {
            if (is_prime[i])
            {
                prime.Add(i);
                for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
            }
        }
    }
    //int[] P;
    //void phi(int n)
    //{
    //    P = new int[n + 1];
    //    for (int i = 0; i <= n; i++) P[i] = i;
    //    for (int i = 2; i <= n; i++)
    //    {
    //        if (is_prime[i])
    //        {
    //            P[i] -= P[i] / i;
    //            for (int j = 2 * i; j <= n; j += i) P[j] -= P[j] / i;
    //        }
    //    }
    //}
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return Console.ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}



Measured memory_bytes: 20344