#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
lint extGcd(lint a, lint b, lint &x, lint &y) {
  lint ret = a;
  if (b) {
    ret = extGcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else
    x = 1, y = 0;
  return ret;
}
lint modInv(lint a, lint m) {
  lint x, y;
  extGcd(a, m, x, y);
  return (m + x % m) % m;
}
long long fact[111111];
long long two[111111];
long long modFact(long long n, long long p, long long &e) {
  e = 0;
  if (!n) return 1;
  long long res = modFact(n / p, p, e);
  e += n / p;
  if (n / p % 2) return res * (p - fact[n % p]) % p;
  return res * fact[n % p] % p;
}
long long modComb(long long n, long long k, long long p) {
  if (n < 0 || k < 0 || n < k) return 0;
  long long e1, e2, e3;
  long long a1 = modFact(n, p, e1);
  long long a2 = modFact(k, p, e2);
  long long a3 = modFact(n - k, p, e3);
  if (e1 > e2 + e3) return 0;
  return a1 * modInv(a2 * a3 % p, p) % p;
}
int x[111111], n;
const int mod = 1000000007;
vector<pair<int, int> > T;
long long play(int l, int r) {
  long long add = 1;
  for (int i = 0; i < T.size(); i++) {
    int x = T[i].second;
    int has = r - l + 1;
    int in = T[i].first - 1 - has;
    if (x < l) {
      if (l - in > x + 1)
        add *= 0;
      else
        add = add * modComb(in, l - x - 1, mod) % mod;
      l = x;
      r = l + has + in;
    } else {
      if (r + in < x - 1)
        add *= 0;
      else
        add = add * modComb(in, x - r - 1, mod) % mod;
      r = x;
      l = r - has - in;
    }
  }
  add = add * modComb(n - (r - l + 1), l - 1, mod);
  return add;
}
void solve() {
  fact[0] = 1;
  two[0] = 1;
  int i;
  for (i = 1; i <= 100000; i++) fact[i] = fact[i - 1] * i % mod;
  for (i = 1; i <= 100000; i++) two[i] = two[i - 1] * 2 % mod;
  while (cin >> n) {
    T.clear();
    int i;
    for (i = 1; i <= n; i++) {
      scanf("%d", &x[i]);
      if (x[i]) T.push_back(make_pair(x[i], i));
    }
    sort(T.begin(), T.end());
    int l = n;
    int r = 1;
    int wa = 0;
    for (i = 0; !wa && i < T.size(); i++) {
      if (T[i].second > l && T[i].second < r)
        wa = 1;
      else
        l = min(T[i].second, l), r = max(T[i].second, r);
    }
    if (wa) {
      printf("0\n");
      continue;
    }
    if (T.empty()) {
      long long ret = 0;
      for (i = 1; i <= n; i++) {
        ret = (ret + modComb(n - 1, i - 1, mod)) % mod;
      }
      cout << ret << endl;
      continue;
    }
    if (T[0].first == 1) {
      int l = T[0].second, r = T[0].second;
      long long add = 1;
      for (i = 1; i < T.size(); i++) {
        int x = T[i].second;
        int has = r - l + 1;
        int in = T[i].first - 1 - has;
        if (x < l) {
          if (l - in > x + 1)
            add *= 0;
          else
            add = add * modComb(in, l - x - 1, mod) % mod;
          l = x;
          r = l + has + in;
        } else {
          if (r + in < x - 1)
            add *= 0;
          else
            add = add * modComb(in, x - r - 1, mod) % mod;
          r = x;
          l = r - has - in;
        }
      }
      add = add * modComb(n - (r - l + 1), l - 1, mod);
      cout << add << endl;
      continue;
    }
    int s = T[0].second;
    int l1 = 1, r1 = s - 1;
    int l2 = s + 1, r2 = n;
    for (i = 1; i < T.size(); i++) {
      if (T[i].second < s) l1 = max(l1, T[i].second + 1);
      if (T[i].second > s) r2 = min(r2, T[i].second - 1);
    }
    long long ans = 0;
    if (l1 <= r1 && l1 >= 1 && r1 <= n) {
      for (i = l1; i <= r1; i++) ans = (ans + play(i, i)) % mod;
    }
    if (l2 <= r2 && l2 >= 1 && r2 <= n)
      for (i = l2; i <= r2; i++) ans = (ans + play(i, i)) % mod;
    ans %= mod;
    cout << ans << endl;
  }
}
int main() {
  solve();
  return 0;
}
