#include <bits/stdc++.h>
using namespace std;
long long int modulo = 1e9 + 7;
long long int eleva(long long int b, long long int e) {
  if (e == 0) return 1;
  if (e % 2 == 0) return eleva(b * b % modulo, e / 2);
  return b * eleva(b * b % modulo, e / 2) % modulo;
}
long long int inverso(long long int x) { return eleva(x, modulo - 2); }
int n;
vector<pair<int, int> > v;
long long int fact[200000];
long long int invfact[200000];
long long int expo[200000];
long long int combi(int n, int k) {
  return fact[n] * invfact[k] % modulo * invfact[n - k] % modulo;
}
long long int calcula(int i1, int i2) {
  long long int c = 1;
  if (i2 > i1) c = expo[i2 - i1 - 1];
  for (int i = 1; i < int(v.size()); i++) {
    if (v[i].second >= i1 and v[i].second <= i2) return 0;
    if (v[i].second < i1) {
      int metele = i1 - v[i].second - 1;
      int meteri = v[i].first - v[i - 1].first - 1 - metele;
      if (meteri < 0) return 0;
      if (i2 + meteri >= n) return 0;
      c = c * combi(metele + meteri, metele) % modulo;
      i1 = i1 - metele - 1;
      i2 = i2 + meteri;
    } else {
      int meteri = v[i].second - i2 - 1;
      int metele = v[i].first - v[i - 1].first - 1 - meteri;
      if (metele < 0) return 0;
      if (i1 - metele < 0) return 0;
      c = c * combi(metele + meteri, metele) % modulo;
      i1 = i1 - metele;
      i2 = i2 + meteri + 1;
    }
  }
  int meteri = n - 1 - i2;
  int metele = i1;
  c = c * combi(metele + meteri, metele) % modulo;
  return c;
}
int main() {
  ios::sync_with_stdio(false);
  fact[0] = invfact[0] = expo[0] = 1;
  for (int i = 1; i < 200000; i++) {
    fact[i] = fact[i - 1] * i % modulo;
    invfact[i] = inverso(fact[i]);
    expo[i] = 2 * expo[i - 1] % modulo;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    if (x > -1) v.push_back(pair<int, int>(x, i));
  }
  sort(v.begin(), v.end());
  long long int sol = 0;
  if (int(v.size()) == 0)
    sol = expo[n - 1];
  else {
    if (v[0].second + v[0].first < n)
      sol += calcula(v[0].second, v[0].second + v[0].first);
    if (v[0].first > 0 and v[0].second - v[0].first >= 0)
      sol += calcula(v[0].second - v[0].first, v[0].second);
    sol %= modulo;
  }
  cout << sol << endl;
}
