#include <bits/stdc++.h>
using namespace std;
long long fact[100005], ifact[100004], a[100004];
vector<pair<int, int> > v;
int n;
long long power(int i, int j) {
  if (j == 0) return 1;
  long long w1 = power(i, j / 2);
  w1 = (w1 * w1) % 1000000007;
  if (j % 2 == 1) w1 = (w1 * 2LL) % 1000000007;
  return w1;
}
long long combi(long long i, long long j) {
  long long w = fact[i] * ifact[j];
  w %= 1000000007;
  w = w * ifact[i - j];
  w = w % 1000000007;
  return w;
}
long long int modpow(long long int a, long long mo) {
  long long res = 1;
  long long j = mo - 2;
  while (j > 0)
    if (j & 1) {
      res = (res * a) % mo;
      --j;
    } else {
      a = (a * a) % mo;
      j >>= 1;
    }
  return res % mo;
}
long long ans(int ind1, int l, int r) {
  if (ind1 == v.size()) {
    int d = n - (r - l + 1);
    return combi(d, l - 1);
  }
  int ind = v[ind1].second;
  if (ind >= l && ind <= r) return 0;
  if (ind < l) {
    int d = r - l + 1;
    int d1 = l - ind;
    if (a[ind] <= d || a[ind] + ind - 1 > n) return 0;
    long long ans1 = ans(ind1 + 1, ind, ind + a[ind] - 1);
    long long ans2 = combi(a[ind] - 1 - d, d1 - 1);
    return (ans1 * ans2) % 1000000007;
  }
  int d = r - l + 1;
  int d1 = ind - r;
  int w1 = d + d1, w2 = d + d1 + l - 1;
  if (ind - a[ind] + 1 <= 0 || a[ind] <= d) return 0;
  long long ans1 = ans(ind1 + 1, ind - a[ind] + 1, ind);
  long long ans2 = combi(a[ind] - 1 - d, d1 - 1);
  return (ans1 * ans2) % 1000000007;
}
int main() {
  cin >> n;
  fact[0] = 1;
  ifact[0] = modpow(1, 1000000007);
  for (long long i = 1; i <= 100001; i++) {
    fact[i] = (fact[i - 1] * i) % 1000000007;
    long long w = modpow(i, 1000000007);
    ifact[i] = (ifact[i - 1] * w) % 1000000007;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != 0) v.push_back(make_pair(a[i], i));
  }
  if (v.size() == 0) {
    cout << power(2, n - 1) << '\n';
    return 0;
  }
  sort(v.begin(), v.end());
  long long ans1 = 0, ans2 = 0, l1 = -1, r1 = -1, l2 = -1, r2 = -1;
  int ind = v[0].second;
  if (v[0].first >= 2)
    ans1 = power(2, v[0].first - 2);
  else
    ans1 = 1;
  r1 = ind;
  l1 = ind - a[ind] + 1;
  long long w1;
  if (l1 >= 1 && r1 <= n)
    w1 = ans(1, l1, r1);
  else
    w1 = 0;
  ans1 = (ans1 * w1) % 1000000007;
  if (v[0].first >= 2)
    ans2 = power(2, v[0].first - 2);
  else
    ans2 = 1;
  l2 = ind;
  r2 = ind + a[ind] - 1;
  if (l2 >= 1 && r2 <= n)
    w1 = ans(1, l2, r2);
  else
    w1 = 0;
  ans2 = (ans2 * w1) % 1000000007;
  if (v[0].first == 1) {
    ans1 = (ans1 + ans2) % 1000000007;
    ans1 = ans1 * ifact[2];
    ans1 %= 1000000007;
    cout << ans1 << '\n';
    return 0;
  }
  cout << (ans1 + ans2) % 1000000007 << '\n';
}
