#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long gcd(long long a, long long b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long invmod(long long a, long long modulo) {
  long long x, y;
  gcd(a, modulo, x, y);
  return (x + modulo * modulo) % modulo;
}
long long cnk(long long n, long long k) {
  if (k > n) return 0;
  if (2 * k > n) k = n - k;
  long long ans = 1;
  for (int i = 0; i < k; i++) {
    ans = (ans * (n - i)) % mod;
    ans = (ans * invmod(i + 1, mod)) % mod;
  }
  return ans;
}
int main() {
  int n, m;
  scanf("%d", &n);
  std::vector<int> a(n);
  std::vector<std::pair<int, int> > q;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) {
      q.push_back(make_pair(a[i], i));
    }
  }
  sort((q).begin(), (q).end());
  if (q.size() == 0) {
    long long ans = 1;
    for (int i = 0; i < n - 1; i++) {
      ans = (ans * 2) % mod;
    }
    cout << ans << endl;
    return 0;
  }
  long long anstot = 0;
  for (int alf = 0; alf < 2; alf++) {
    if (q[0].first == 1) alf++;
    long long ans = 1;
    for (int i = 0; i < q[0].first - 2; i++) ans = (ans * 2) % mod;
    int l, r;
    l = q[0].second;
    r = q[0].second;
    int cur = q[0].first;
    int s = q[0].second;
    if (alf == 0)
      r += q[0].first - 1;
    else
      l -= q[0].first - 1;
    for (int i = 1; i < q.size(); i++) {
      int nx = q[i].first;
      int pos = q[i].second;
      if (pos > s) {
        if (r >= pos) {
          ans = 0;
          break;
        }
        if (pos - r > nx - cur) {
          ans = 0;
          break;
        }
        ans = (ans * cnk(nx - cur - 1, pos - r - 1)) % mod;
        r = pos;
        cur = nx;
        l = pos - nx + 1;
      } else {
        if (l <= pos || l - pos > nx - cur) {
          ans = 0;
          break;
        }
        ans = (ans * cnk(nx - cur - 1, l - pos - 1)) % mod;
        l = pos;
        cur = nx;
        r = pos + nx - 1;
      }
    }
    if (l < 0 || r > n - 1)
      ans = 0;
    else
      ans = (ans * cnk(n - cur, l)) % mod;
    anstot += ans;
  }
  anstot = (anstot) % mod;
  cout << anstot;
}
