#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int MOD = 1000000007;
vector<pair<int, int> > know;
int n, a[N], ans, fac[N], inv[N];
int PowMod(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1LL * ret * a % MOD;
    a = 1LL * a * a % MOD;
    b >>= 1;
  }
  return ret;
}
int C(int n, int m) {
  return 1LL * (1LL * fac[n] * inv[m] % MOD) * inv[n - m] % MOD;
}
void gao(int first) {
  int now = 1, pl = first, pr = first, l, r;
  for (int i = 1; i < know.size(); i++) {
    if (know[i].second > first) {
      r = know[i].second - 1;
      l = r - know[i].first + 2;
    } else {
      l = know[i].second + 1;
      r = l + know[i].first - 2;
    }
    if (pl < l || pr > r) return;
    int lcnt = pl - l, rcnt = r - pr;
    now = (1LL * now * C(lcnt + rcnt, lcnt)) % MOD;
    pl = l;
    pr = r;
    if (know[i].second > first)
      pr++;
    else
      pl--;
  }
  ans = (ans + now) % MOD;
}
int main() {
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = 1LL * fac[i - 1] * i % MOD;
    inv[i] = PowMod(fac[i], MOD - 2);
  }
  while (cin >> n) {
    know.clear();
    ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      if (a[i]) {
        know.push_back(make_pair(a[i], i));
      }
    }
    know.push_back(make_pair(n + 1, n + 1));
    sort(know.begin(), know.end());
    if (know[0].first == 1) {
      gao(know[0].second);
    } else {
      know.insert(know.begin(), make_pair(1, 0));
      for (int i = 1; i <= n; i++) {
        if (a[i] == 0) {
          know[0].second = i;
          gao(i);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
