#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
bool isprime(long long x) {
  if (x == 2) return true;
  if (x < 2 || x % 2 == 0) return false;
  long long i = 3;
  long long sqrtx = sqrt(x);
  while (i <= sqrtx) {
    if (x % i == 0) return false;
    i += 2;
  }
  return true;
}
vector<long long> eratos(long long max) {
  vector<long long> primeVec;
  vector<bool> isprime;
  double sqrtmax = sqrt(max);
  isprime.resize(max + 1);
  isprime[0] = false;
  isprime[1] = false;
  for (long long i = 2; i < max + 1; i++) {
    isprime[i] = true;
  }
  for (long long i = 2; i < sqrtmax; i++) {
    if (isprime[i]) {
      for (int j = 0; i * (j + 2) < max + 1; ++j) {
        isprime[i * (j + 2)] = false;
      }
    }
  }
  for (long long i = 0; i < max + 1; i++) {
    if (isprime[i]) primeVec.push_back(i);
  }
  return primeVec;
}
int pre_prime = 0;
long long ans = 0;
int n;
vector<int> q;
bool flag = false;
long long kaijou(long long n) {
  long long ret = 1;
  for (long long i = 0; i < n; i++) {
    ret = ret * 2 % 1000000007;
  }
  return ret;
}
signed main() {
  cin >> n;
  q.resize(n);
  for (long long i = 0; i < n; i++) cin >> q[i];
  if (n == 1) {
    if (!isprime((long long)q[0]) || q[0] < pre_prime) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    int cnt = -1;
    if (!isprime((long long)q[i]) || q[i] < pre_prime) {
      if (flag == true) {
        cout << 0 << endl;
        return 0;
      }
      flag = true;
      if (cnt <= 1) {
        ans = ans + 1 % 1000000007;
      } else if (cnt == 2) {
        ans = ans + 2 % 1000000007;
      } else if (cnt % 2 == 0) {
        ans = (ans + kaijou(n / 2)) % 1000000007;
      } else {
        ans = (ans + kaijou(n / 2) * 2 % 1000000007) % 1000000007;
      }
      cnt = -1;
    } else {
      cnt++;
      if (i == n - 1) {
        if (cnt <= 1) {
          ans = ans + 1 % 1000000007;
        } else if (cnt == 2) {
          ans = ans + 2 % 1000000007;
        } else if (cnt % 2 == 0) {
          ans = (ans + kaijou(n / 2)) % 1000000007;
        } else {
          ans = (ans + kaijou(n / 2) * 2 % 1000000007) % 1000000007;
        }
      }
      pre_prime = q[i];
      flag = false;
    }
  }
  cout << ans << endl;
}
