#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:600000000")
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)4e18;
const string name = "d";
const int NMAX = 101010;
const long long P = 1000000007;
int n, a[NMAX];
long long st[NMAX], ans, f[NMAX];
vector<pair<int, int> > now;
long long solve_empty() { return st[n - 1]; }
int good(int l, int r) {
  if (l < 0 || r >= n) return 0;
  for (int i = l; i <= r; ++i)
    if (a[i] != 0) return 0;
  return 1;
}
long long invert(long long x) {
  int st = P - 2;
  long long res = 1;
  while (st > 0) {
    if (st & 1) res = (res * x) % P;
    x = (x * x) % P;
    st >>= 1;
  }
  return res;
}
long long c(int n, int k) {
  return (((f[n] * invert(f[k])) % P) * invert(f[n - k])) % P;
}
void update(int& l, int& r, int idx, int val, long long& res) {
  int already = r - l + 1;
  if (idx > r) {
    int rfree = idx - r - 1;
    int lfree = val - already - 1 - rfree;
    if (lfree < 0) {
      res = 0;
      return;
    }
    if (!good(l - lfree, l - 1) || !good(r + 1, r + rfree)) {
      res = 0;
      return;
    }
    res = (res * c(rfree + lfree, lfree)) % P;
    l -= lfree, r += rfree + 1;
  } else if (idx < l) {
    int lfree = l - idx - 1;
    int rfree = val - already - 1 - lfree;
    if (rfree < 0) {
      res = 0;
      return;
    }
    if (!good(l - lfree, l - 1) || !good(r + 1, r + rfree)) {
      res = 0;
      return;
    }
    res = (res * c(rfree + lfree, lfree)) % P;
    l -= lfree + 1, r += rfree;
  } else {
    cout << "SMTH WRONG!" << endl;
    exit(0);
  }
}
long long solve() {
  now.clear();
  for (int i = 0; i < (int)n; i++)
    if (a[i] > 0) now.push_back(make_pair(a[i], i));
  sort((now).begin(), (now).end());
  int l = now[0].second, r = now[0].second;
  long long res = 1;
  for (int i = 1; i < (int)now.size(); ++i) {
    update(l, r, now[i].second, now[i].first, res);
    if (res == 0) break;
  }
  int lfree = l;
  int rfree = n - r - 1;
  res = (res * c(rfree + lfree, lfree)) % P;
  return res;
}
int main() {
  for (int i = 0; i < (int)NMAX; i++)
    if (i)
      st[i] = (st[i - 1] * 2) % P;
    else
      st[i] = 1;
  for (int i = 0; i < (int)NMAX; i++)
    if (i)
      f[i] = (f[i - 1] * i) % P;
    else
      f[i] = 1;
  cin >> n;
  int exist = 0, sum = 0;
  ans = 0;
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) exist = 1;
    if (a[i] > 0) sum++;
  }
  if (sum == 0)
    ans = solve_empty();
  else if (exist) {
    ans = solve();
  } else {
    int idx = -1;
    for (int i = 0; i < (int)n; i++)
      if (a[i] > 0 && (idx == -1 || a[idx] > a[i])) idx = i;
    if (good(idx - a[idx] + 1, idx - 1)) {
      int now = 0;
      for (int i = idx - a[idx] + 1; i < idx; ++i) a[i] = ++now;
      ans += (solve() * st[a[idx] - 2]) % P;
      for (int i = idx - a[idx] + 1; i < idx; ++i) a[i] = 0;
    }
    if (good(idx + 1, idx + a[idx] - 1)) {
      int now = 0;
      for (int i = idx + a[idx] - 1; i > idx; --i) a[i] = ++now;
      ans += (solve() * st[a[idx] - 2]) % P;
      for (int i = idx + a[idx] - 1; i > idx; --i) a[i] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
