#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const long long mod = 1000000007;
const int maxn = 100005;
long long fact[maxn], invFact[maxn];
long long powmod(long long x, long long n, long long m = mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
long long C(long long n, long long k) {
  long long res = (((fact[n] * invFact[k]) % mod) * invFact[n - k]) % mod;
  return res;
}
long long K(int len) {
  if (len == 0) return 1;
  long long res = 0;
  for (int i = 0; i < len; i++) {
    res = (res + C(len - 1, i)) % mod;
  }
  return res;
}
pair<int, int> a[maxn];
int b[maxn];
int main() {
  fact[0] = 1;
  invFact[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    invFact[i] = powmod(fact[i], mod - 2);
  }
  int n;
  scanf("%d", &n);
  bool any = false;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].first);
    b[i] = a[i].first;
    any |= a[i].first;
    a[i].second = i;
    if (a[i].first == 0) a[i].first = 1e9;
  }
  if (!any) {
    cout << K(n);
    return 0;
  }
  sort(a, a + n);
  long long ans = 0;
  for (int dir = 0; dir < 2; dir++) {
    int len = a[0].first - 1;
    long long curr = 1;
    if (len == 0 && dir == 1) break;
    int left, right;
    if (dir == 0) {
      right = a[0].second - 1;
      left = right - len + 1;
    } else {
      left = a[0].second + 1;
      right = left + len - 1;
    }
    if (left < 0 || right >= n) continue;
    bool good = true;
    for (int i = left; i <= right; i++) {
      if (b[i]) {
        good = false;
      }
    }
    if (!good) continue;
    curr = (curr * K(len)) % mod;
    if (dir == 0)
      right++;
    else
      left--;
    int prv = a[0].first;
    for (int i = 1; i < n; i++) {
      if (a[i].first == 1e9) break;
      len = a[i].first - prv - 1;
      int lcnt = 0;
      if (a[i].second > right) {
        for (int j = right + 1; j <= a[i].second - 1; j++) {
          if (len <= 0 || b[j]) {
            good = false;
            break;
          }
          len--;
          right = j;
        }
        for (int j = 0; j < len; j++) {
          left--;
          if (left < 0 || b[left]) {
            good = false;
            break;
          }
          lcnt++;
        }
        right++;
      } else {
        for (int j = left - 1; j >= a[i].second + 1; j--) {
          if (len <= 0 || b[j]) {
            good = false;
            break;
          }
          len--;
          left = j;
          lcnt++;
        }
        for (int j = 0; j < len; j++) {
          right++;
          if (right >= n || b[right]) {
            good = false;
            break;
          }
        }
        left--;
      }
      if (!good) break;
      len = a[i].first - prv - 1;
      curr = (curr * C(len, lcnt)) % mod;
      prv = a[i].first;
    }
    if (!good) continue;
    int cnt = (n - 1) - right + left;
    curr = (curr * C(cnt, left)) % mod;
    ans = (ans + curr) % mod;
  }
  cout << ans << endl;
  return 0;
}
