#include <bits/stdc++.h>
using namespace std;
int a[100000];
vector<int> p;
long long fact[100001];
long long inv[100001];
long long finv[100001];
void init(int n) {
  int i;
  fact[0] = 1;
  for (i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % 1000000007;
  inv[0] = 1;
  inv[1] = 1;
  for (i = 2; i <= n; i++)
    inv[i] = 1000000007 - (1000000007 / i) * inv[1000000007 % i] % 1000000007;
  finv[0] = 1;
  for (i = 1; i <= n; i++) finv[i] = finv[i - 1] * inv[i] % 1000000007;
}
long long C(int n, int k) {
  return fact[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
long long pow(int x, int p) {
  long long ans = 1;
  for (int i = 0; i < p; i++) ans = ans * x % 1000000007;
  return ans;
}
int next(int s, int t, int m) {
  if (s < 0 || s >= m) return t;
  if (t < 0 || t >= m) return s;
  return a[p[s]] < a[p[t]] ? s : t;
}
int pos(int i, int m, int n) {
  if (i < 0) return -1;
  if (i >= m) return n;
  return p[i];
}
long long solve(int cnt, int l, int r, int n) {
  int s = cnt - 1, t = cnt + 1;
  if (l <= pos(s, p.size(), n) || r >= pos(t, p.size(), n)) return 0;
  long long ans = 1;
  while (!(s == -1 && t == p.size())) {
    int nxt = next(s, t, p.size());
    int w = r - l + 1;
    if (nxt == t) {
      int d = p[nxt] - r - 1;
      if (d > a[p[nxt]] - w - 1) return 0;
      d = a[p[nxt]] - w - 1 - d;
      l -= d;
      if (l <= pos(s, p.size(), n)) return 0;
      r = p[nxt];
      ans = ans * C(a[p[nxt]] - w - 1, d) % 1000000007;
      t++;
    }
    if (nxt == s) {
      int d = l - p[nxt] - 1;
      if (d > a[p[nxt]] - w - 1) return 0;
      d = a[p[nxt]] - w - 1 - d;
      r += d;
      if (r >= pos(t, p.size(), n)) return 0;
      l = p[nxt];
      ans = ans * C(a[p[nxt]] - w - 1, d) % 1000000007;
      s--;
    }
  }
  ans = ans * C(n - (r - l + 1), l) % 1000000007;
  return ans;
}
int main() {
  int n, i;
  scanf("%d", &n);
  init(n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) p.push_back(i);
  }
  if (p.size() == 0) {
    printf("%I64d\n", pow(2, n - 1));
    return 0;
  }
  if (p.size() == 1) {
    if (a[p[0]] == 1)
      printf("%I64d\n", C(n - 1, p[0]));
    else {
      int t = a[p[0]] - 1;
      long long vl = (p[0] >= t ? C(n - t - 1, p[0] - t) : 0);
      long long vr = (n - p[0] - 1 >= t ? C(n - t - 1, p[0]) : 0);
      printf("%I64d\n", pow(2, t - 1) * (vl + vr) % 1000000007);
    }
    return 0;
  }
  int cnt = 0;
  while (cnt + 1 < p.size() && a[p[cnt]] > a[p[cnt + 1]]) cnt++;
  for (i = cnt; i + 1 < p.size(); i++)
    if (a[p[i]] > a[p[i + 1]]) {
      puts("0");
      return 0;
    }
  int l, r;
  long long ans;
  if (a[p[cnt]] == 1) {
    l = p[cnt];
    r = p[cnt];
    ans = solve(cnt, l, r, n);
  } else {
    l = p[cnt] - (a[p[cnt]] - 1);
    r = p[cnt];
    ans = solve(cnt, l, r, n);
    l = p[cnt];
    r = p[cnt] + (a[p[cnt]] - 1);
    ans = (ans + solve(cnt, l, r, n)) % 1000000007;
  }
  printf("%I64d\n", ans * pow(2, r - l - 1) % 1000000007);
  return 0;
}
