#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int fac[100005], invfac[100005], A[100005], N, n;
pair<int, int> P[100005];
int fastExp(int a, int p) {
  if (!p) return 1;
  if (p & 1) return ((long long)fastExp(a, p - 1) * a) % MOD;
  int v = fastExp(a, p >> 1);
  return ((long long)v * v) % MOD;
}
int binomial(int r, int c) {
  long long ret = ((long long)fac[r] * invfac[c]) % MOD;
  ret = (ret * invfac[r - c]) % MOD;
  return ret;
}
int sim(int l, int r) {
  int ret = 1;
  for (int i = 1; i < n; ++i) {
    if (l <= P[i].second && P[i].second <= r) return 0;
    int nl, nr, dpos;
    if (P[i].second < l) {
      dpos = l - P[i].second - 1;
      nl = P[i].second;
      nr = nl + P[i].first - 1;
    } else {
      dpos = P[i].second - r - 1;
      nr = P[i].second;
      nl = nr - P[i].first + 1;
    }
    int dv = P[i].first - P[i - 1].first - 1;
    if (dpos > dv) return 0;
    ret = ((long long)ret * binomial(dv, dpos)) % MOD;
    l = nl;
    r = nr;
  }
  if (l < 1 || r > N) return 0;
  ret = ((long long)ret * binomial(N - P[n - 1].first, l - 1)) % MOD;
  return ret;
}
int getAns() {
  if (!n) return fastExp(2, N - 1);
  if (P[0].first == 1) return sim(P[0].second, P[0].second);
  int ret = 0;
  int l = P[0].second - P[0].first + 1;
  int r = P[0].second + P[0].first - 1;
  if (l >= 1) ret += sim(l, P[0].second);
  if (r <= N) ret += sim(P[0].second, r);
  return ((long long)ret * fastExp(2, P[0].first - 2)) % MOD;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i <= N; ++i) {
    fac[i] = i ? ((long long)fac[i - 1] * i) % MOD : 1;
    invfac[i] = fastExp(fac[i], MOD - 2);
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    if (A[i]) P[n++] = make_pair(A[i], i);
  }
  sort(P, P + n);
  int ans = getAns();
  printf("%d\n", ans);
}
