#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-12;
const double PI = acos(-1.0);
const double angcst = PI / 180.0;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qmul(long long a, long long b) {
  long long r = 0;
  while (b) {
    if (b & 1) r = (r + a) % mod;
    b >>= 1;
    a = (a + a) % mod;
  }
  return r;
}
long long qpow(long long a, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % mod;
    n >>= 1;
    a = (a * a) % mod;
  }
  return r;
}
long long qpow(long long a, long long n, long long p) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % p;
    n >>= 1;
    a = (a * a) % p;
  }
  return r;
}
const int MAX_N = 1e5 + 10;
long long fac[MAX_N + 1], inv[MAX_N + 1];
void init() {
  fac[0] = 1;
  for (int i = 1; i <= MAX_N; i++) fac[i] = fac[i - 1] * i % mod;
  inv[MAX_N] = qpow(fac[MAX_N], mod - 2);
  for (int i = MAX_N - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
long long C(long long m, long long n) {
  return fac[m] * inv[m - n] % mod * inv[n] % mod;
}
struct node {
  int id, pos;
  bool operator<(const node& a) const { return id < a.id; }
} br[MAX_N];
int cnt = 0;
int n;
int ar[MAX_N];
long long ans = 0;
void deal(int p1) {
  int l = p1, r = p1, tot, ned;
  int p = (br[1].id == 1 ? 2 : 1), pid = 1;
  long long ansd = 1;
  while (p <= cnt) {
    if (br[p].pos < l) {
      ned = l - br[p].pos - 1;
      tot = br[p].id - pid - 1;
      if (tot < ned) return;
      l = br[p].pos;
      r += tot - ned;
    } else if (br[p].pos > r) {
      ned = br[p].pos - r - 1;
      tot = br[p].id - pid - 1;
      if (tot < ned) return;
      l -= tot - ned;
      r = br[p].pos;
    } else
      return;
    ansd = ansd * C(tot, ned) % mod;
    pid = br[p].id;
    p++;
  }
  ansd = ansd * C((n - r) + (l - 1), l - 1) % mod;
  ans = (ans + ansd) % mod;
}
void solve() {
  cin >> n;
  int l = 1, r = n;
  for (int i = (1); i <= (n); i++) {
    cin >> ar[i];
    if (ar[i]) {
      br[++cnt] = {ar[i], i};
      l = max(l, i - ar[i] + 1);
      r = min(r, i + ar[i] - 1);
    }
  }
  sort(br + 1, br + 1 + cnt);
  for (int p = (l); p <= (r); p++) deal(p);
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  { solve(); }
  return 0;
}
