#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 100010;
const int MOD = 1000000007;
int N;
int first[MAXN];
long long fact[MAXN], fact_inv[MAXN], inv[MAXN];
long long sum[MAXN];
void init() {
  fact[0] = fact[1] = 1;
  fact_inv[0] = fact_inv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAXN; i++) {
    inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
    fact[i] = fact[i - 1] * i % MOD;
    fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
  }
}
long long take(int a, int b) {
  return fact[a + b] * fact_inv[a] % MOD * fact_inv[b] % MOD;
}
long long mpow(int b, long long exp) {
  long long bit = 1;
  long long v = b;
  long long ans = 1;
  while (bit <= exp) {
    if (exp & bit) ans = ans * v % MOD;
    bit <<= 1;
    v = v * v % MOD;
  }
  return ans;
}
bool none(int a, int b) { return sum[b] - sum[a] == 0; }
long long solve(int a, int b) {
  if (none(a, b)) return mpow(2, b - a - 1);
  int leftmost_set = a, rightmost_set = b - 1;
  while (first[leftmost_set] == 0) leftmost_set++;
  while (first[rightmost_set] == 0) rightmost_set--;
  if (leftmost_set == rightmost_set && first[leftmost_set] == 1)
    return take(leftmost_set - a, b - rightmost_set - 1);
  long long ans = 0;
  if (first[leftmost_set] >= first[rightmost_set]) {
    int na = leftmost_set;
    int nb = na + first[leftmost_set];
    if (nb > rightmost_set && nb <= b)
      ans += solve(na + 1, nb) * take(na - a, b - nb) % MOD;
  }
  if (first[leftmost_set] <= first[rightmost_set]) {
    int nb = rightmost_set + 1;
    int na = nb - first[rightmost_set];
    if (na <= leftmost_set && na >= a)
      ans += solve(na, nb - 1) * take(na - a, b - nb) % MOD;
  }
  return ans % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  init();
  cin >> N;
  for (int i = 0; i < N; i++) cin >> first[i];
  sum[0] = 0;
  for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + first[i];
  cout << solve(0, N) << '\n';
  return 0;
}
