Language: C++

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
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());
        long zero = 1; int zero_prime = 0;
        long one = 0; int one_prime = 0;

        for (int i = 0; i < N; i++)
        {
            if (one == 0 && (!is_prime[Q[i]] || Q[i] < zero_prime))
            {
                Console.WriteLine(0);
                return;
            }
            if (is_prime[Q[i]])
            {
                //oneの後に0を置くとき、zero_primeはone_primeになる
                if (one_prime < 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
                {
                    zero = one;
                    one = 0;
                }
            }
            else
            {
                zero = one;
                one = 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); } }
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Linq;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.IO;
      |       ^~~~~~
a.cc:5:7: error: expected nested-name-specifier before 'System'
    5 | using System.Globalization;
      |       ^~~~~~
a.cc:6:7: error: expected nested-name-specifier before 'System'
    6 | using System.Diagnostics;
      |       ^~~~~~
a.cc:7:14: error: 'System' does not name a type
    7 | using Pair = System.Collections.Generic.KeyValuePair<int, int>;
      |              ^~~~~~
a.cc:17:5: error: 'Scanner' does not name a type
   17 |     Scanner cin = new Scanner();
      |     ^~~~~~~
a.cc:77:5: error: 'List' does not name a type
   77 |     List<int> prime;
      |     ^~~~
a.cc:78:9: error: expected unqualified-id before '[' token
   78 |     bool[] is_prime;
      |         ^
a.cc:94:8: error: expected unqualified-id before '[' token
   94 |     int[] P;
      |        ^
a.cc:108:2: error: expected ';' after class definition
  108 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Program::Main()':
a.cc:13:9: error: 'Console' was not declared in this scope
   13 |         Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
      |         ^~~~~~~
a.cc:13:28: error: expected type-specifier before 'StreamWriter'
   13 |         Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
      |                            ^~~~~~~~~~~~
a.cc:14:22: error: expected ';' before '.' token
   14 |         new Program().Solve();
      |                      ^
a.cc: In member function 'void Program::Solve()':
a.cc:22:17: error: 'cin' was not declared in this scope
   22 |         int N = cin.Nextint;
      |                 ^~~
a.cc:23:9: error: 'var' was not declared in this scope
   23 |         var Q = cin.Scanint;
      |         ^~~
a.cc:24:16: error: 'Q' was not declared in this scope
   24 |         eratos(Q.Max());
      |                ^
a.cc:30:31: error: 'is_prime' was not declared in this scope; did you mean 'one_prime'?
   30 |             if (one == 0 && (!is_prime[Q[i]] || Q[i] < zero_prime))
      |                               ^~~~~~~~
      |                               one_prime
a.cc:32:17: error: 'Console' was not declared in this scope
   32 |                 Console.WriteLine(0);
      |                 ^~~~~~~
a.cc:35:17: error: 'is_prime' was not declared in this scope; did you mean 'one_prime'?
   35 |             if (is_prime[Q[i]])
      |                 ^~~~~~~~
      |                 one_prime
a.cc:71:9: error: 'Console' was not declared in this scope
   71 |         Console.WriteLine((one + zero) % mod);
      |         ^~~~~~~
a.cc: In member function 'void Program::eratos(int)':
a.cc:81:9: error: 'prime' was not declared in this scope
   81 |         prime = new List<int>();
      |         ^~~~~
a.cc:81:21: error: 'List' does not name a type
   81 |         prime = new List<int>();
      |                     ^~~~
a.cc:81:26: error: expected primary-expression before 'int'
   81 |         prime = new List<int>();
      |                          ^~~
a.cc:82:9: error: 'is_prime' was not declared in this scope
   82 |         is_prime = new bool[n + 1];
      |         ^~~~~~~~
a.cc: In member function 'void Program::phi(int)':
a.cc:97:9: error: 'P' was not declared in this scope
   97 |         P = new int[n + 1];
      |         ^
a.cc:101:17: error: 'is_prime' was not declared in this scope
  101 |             if (is_prime[i])
      |                 ^~~~~~~~
a.cc: At global scope:
a.cc:112:5: error: 'string' does not name a type
  112 |     string[] s; int i;
      |     ^~~~~~
a.cc:113:9: error: expected unqualified-id before '[' token
  113 |     char[] cs = new char[] { ' ' };
      |         ^
a.cc:114:11: error: expected ':' before 'Scanner'
  114 |     public Scanner() { s = new string[0]; i = 0; }
      |           ^~~~~~~~
      |           :
a.cc:115:11: error: expected ':' before 'string'
  115 |     public string[] Scan { get { return Console.ReadLine().Split(); } }
      |           ^~~~~~~
      |           :
a.cc:115:12: error: 'string' does not name a type
  115 |     public string[] Scan { get { return Console.ReadLine().Split(); } }
      |            ^~~~~~
a.cc:116:11: error: expected ':' before 'int'
  116 |     public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
      |           ^~~~
      |           :
a.cc:116:15: error: expected unqualified-id before '[' token
  116 |     public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
      |               ^
a.cc:117:11: error: expected ':' before 'long'
  117 |     public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
      |           ^~~~~
      |           :
a.cc:117:16: error: expected unqualified-id before '[' token
  117 |     public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
      |                ^
a.cc:118:11: error: expected ':' before 'double'
  118 |     public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
      |           ^~~~~~~
      |           :
a.cc:118:18: error: expected unqualified-id before '[' token
  118 |     public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
      |                  ^
a.cc:119:11: error: expected ':' before 'string'
  119 |     public string Next
      |           ^~~~~~~
      |           :
a.cc:119:12: error: 'string' does not name a type
  119 |     public string Next
      |            ^~~~~~
a.cc:131:11: error: expected ':' before 'int'
  131 |     public int Nextint { get { return int.Parse(Next); } }
      |           ^~~~
      |           :
a.cc:131:58: error: expected ';' at end of member declaration
  131 |     public int Nextint { get { return int.Parse(Next); } }
      |                                                          ^
      |                                                           ;
a.cc:132:11: error: expected ':' before 'long'
  132 |     public long Nextlong { get { return long.Parse(Next); } }
      |           ^~~~~
      |           :
a.cc:132:61: error: expected ';' at end of member declaration
  132 |     public long Nextlong { get { return long.Parse(Next); } }
      |                                                             ^
      |                                                              ;
a.cc:133:11: error: expected ':' before 'double'
  133 |     public double Nextdouble { get { return double.Parse(Next); } }
      |           ^~~~~~~
      |           :
a.cc:133:67: error: expected ';' at end of member declaration
  133 |     public double Nextdouble { get { return double.Parse(Next); } }
      |                                                                   ^
      |                                                                    ;
a.cc:134:2: error: expected ';' after class definition
  134 | }
      |  ^
      |  ;
a.cc:131:26: error: 'get' was not declared in this scope
  131 |     public int Nextint { get { return int.Parse(Next); } }
      |                          ^~~
a.cc:131:30: error: expected '}' before '{' token
  131 |     public int Nextint { get { return int.Parse(Next); } }
      |                              ^
a.cc:131:24: note: to match this '{'
  131 |     public int Nextint { get { return int.Parse(Next); } }
      |                        ^
a.cc:131:30: error: cannot convert '<brace-enclosed initializer list>' to 'int' in initialization
  131 |     public int Nextint { get { return int.Parse(Next); } }
      |                              ^
a.cc:131:30: error: expected ';' before '{' token
a.cc:132:28: error: 'get' was not declared in this scope
  132 |     public long Nextlong { get { return long.Parse(Next); } }
      |                            ^~~
a.cc:132:32: error: expected '}' before '{' token
  132 |     public long Nextlong { get { return long.Parse(Next); } }
      |                                ^
a.cc:132:26: note: to match this '{'
  132 |     public long Nextlong { get { return long.Parse(Next); } }
      |                          ^
a.cc:132:32: error: cannot convert '<brace-enclosed initializer list>' to 'long int' in initialization
  132 |     public long Nextlong { get { return long.Parse(Next); } }
      |                                ^
a.cc:132:32: error: expected ';' before '{' token
a.cc:133:32: error: 'get' was not declared in this scope
  133 |     public double Nextdouble { get { return double.Parse(Next); } }
      |                                ^~~
a.cc:133:36: error: expected '}' before '{' token
  133 |     public double Nextdouble { get { return double.Parse(Next); } }
      |                                    ^
a.cc:133:30: note: to match this '{'
  133 |     public double Nextdouble { get { return double.Parse(Next); } }
      |                              ^
a.cc:133:36: error: cannot convert '<brace-enclosed initializer list>' to 'double' in initialization
  133 |     public double Nextdouble { get { return double.Parse(Next); } }
      |                                    ^
a.cc:133:36: error: expected ';' before '{' token
a.cc: In constructor 'Scanner::Scanner()':
a.cc:114:24: error: 's' was not declared in this scope
  114 |     public Scanner() { s = new string[0]; i = 0; }
      |                        ^
a.cc:114:32: error: 'string' does not name a type
  114 |     public Scanner() { s = new string[0]; i = 0; }
      |                                ^~~~~~