#include <bits/stdc++.h>
using namespace std;
long long N;
struct people {
  long long pos, idx;
} peo[100010];
long long invers(long long a);
long long powof2(long long b);
long long combi(long long n, long long m);
long long find(long long st, long long l, long long r, long long ans);
void input();
void solve();
void ext_gcd(long long a, long long b, long long& x, long long& y);
bool comp(people a, people b);
int main() {
  input();
  solve();
}
void input() {
  scanf("%I64d", &N);
  for (long long i = 0; i < N; i++) {
    long long IDX;
    scanf("%I64d", &IDX);
    peo[i].pos = i;
    peo[i].idx = IDX - 1;
  }
}
void ext_gcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return;
  }
  long long xp, yp;
  ext_gcd(b, a % b, xp, yp);
  x = yp;
  y = ((xp - (a / b) * yp) % 1000000007 + 1000000007) % 1000000007;
}
bool comp(people a, people b) { return a.idx < b.idx; }
long long invers(long long a) {
  long long x = 0, y = 0;
  ext_gcd(a, 1000000007, x, y);
  return x;
}
long long powof2(long long b) {
  long long ans = 1;
  for (long long i = 0; i < b; i++) {
    ans = (ans * 2) % 1000000007;
  }
  return ans;
}
long long combi(long long n, long long m) {
  long long ret = 1;
  for (long long i = 1; i <= m; i++) {
    ret = (ret * (n - i + 1)) % 1000000007;
    ret = (ret * invers(i)) % 1000000007;
  }
  return ret;
}
long long find(long long st, long long l, long long r, long long ans) {
  for (long long i = st; i < N; i++) {
    long long pos = peo[i].pos;
    long long idx = peo[i].idx;
    if (l < 0 || r >= N) return 0;
    if (l <= pos && pos <= r) return 0;
    long long lbar, rbar;
    if (pos < l) {
      lbar = pos;
      rbar = pos + idx;
      ans = (ans * combi(idx - (r - l + 1), l - lbar - 1)) % 1000000007;
    } else {
      lbar = pos - idx;
      rbar = pos;
      ans = (ans * combi(idx - (r - l + 1), rbar - r - 1)) % 1000000007;
    }
    l = lbar;
    r = rbar;
  }
  if (l < 0 || r >= N) return 0;
  ans = (ans * combi(N - (r - l + 1), l)) % 1000000007;
  return ans;
}
void solve() {
  sort(peo, peo + N, comp);
  long long cntbad = 0;
  for (long long i = 0; i < N; i++) {
    if (peo[i].idx == -1) cntbad++;
  }
  if (cntbad == N) {
    printf("%I64d\n", powof2(N - 1));
    return;
  }
  long long st = cntbad;
  if (peo[st].idx == 0)
    printf("%I64d\n", find(st + 1, peo[st].pos, peo[st].pos, 1));
  else {
    long long v1 = find(st + 1, peo[st].pos - peo[st].idx, peo[st].pos,
                        powof2(peo[st].idx - 1));
    long long v2 = find(st + 1, peo[st].pos, peo[st].pos + peo[st].idx,
                        powof2(peo[st].idx - 1));
    printf("%I64d\n", (v1 + v2) % 1000000007);
  }
}
