#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const int N = 1e5 + 9;
long long p[N], f[N];
struct D {
  int x;
  int c;
  vector<int> u;
  vector<long long> v;
  bool operator<(const D &o) const { return x < o.x; }
};
void exGcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  long long _x, _y;
  exGcd(b, a % b, _x, _y);
  x = _y, y = _x - a / b * _y;
}
long long inv(long long a, long long p = Mod) {
  long long x, y;
  exGcd(a, p, x, y);
  return ((x % p) + p) % p;
}
long long C(long long n, long long m, long long p) {
  return f[n] * inv(f[m]) % Mod * inv(f[n - m]) % Mod;
}
int main() {
  int n;
  scanf("%d", &n);
  p[0] = f[0] = 1;
  for (int i = 1; i <= n; ++i)
    p[i] = 2 * p[i - 1] % Mod, f[i] = i * f[i - 1] % Mod;
  vector<D> d;
  bool ok = 1;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    if (x) {
      D t;
      t.x = x;
      t.c = i;
      if (i - x + 1 >= 1) t.u.push_back(i - x + 1), t.v.push_back(0);
      if (x > 1 && i + x - 1 <= n) t.u.push_back(i), t.v.push_back(0);
      if (t.u.empty()) {
        ok = 0;
      }
      d.push_back(t);
    }
  }
  if (!ok) return cout << "0" << endl, 0;
  sort(d.begin(), d.end());
  long long ans = 0;
  if (d.empty())
    ans = p[n - 1];
  else {
    int z = d.size() - 1;
    D t;
    t.x = n;
    t.c = 1;
    t.u.push_back(1);
    t.v.push_back(0);
    d.push_back(t);
    ++z;
    for (int i = 0; i < d[0].u.size(); ++i) d[0].v[i] = p[max(d[0].x - 2, 0)];
    for (int i = 1; i < d.size(); ++i) {
      for (int j = 0; j < d[i].u.size(); ++j) {
        d[i].v[j];
        for (int k = 0; k < d[i - 1].u.size(); ++k) {
          int x = d[i].x, y = d[i].u[j], ox = d[i - 1].x, oy = d[i - 1].u[k];
          if (i == z)
            ;
          else if (y == d[i].c)
            --x, ++y;
          else
            --x;
          if (oy >= y && oy <= y + x - ox) {
            d[i].v[j] += C(x - ox, oy - y, Mod) * d[i - 1].v[k];
            d[i].v[j] %= Mod;
          }
        }
      }
    }
    ans = d[z].v[0];
  }
  cout << ans << endl;
  return 0;
}
