#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
const int mod = 1000000007;
struct Int {
  unsigned x;
  int mpow(Int a, int k) {
    Int res = 1;
    while (k) {
      if (k & 1) res = res * a;
      a = a * a;
      k >>= 1;
    }
    return res.x;
  }
  int inverse(Int a) { return mpow(a, mod - 2); }
  Int() : x(0) {}
  Int(long long sig) {
    int sigt = sig % mod;
    if (sigt < 0) sigt += mod;
    x = sigt;
  }
  int get() const { return (int)x; }
  Int& operator+=(Int that) {
    if ((x += that.x) >= mod) x -= mod;
    return *this;
  }
  Int& operator-=(Int that) {
    if ((x += mod - that.x) >= mod) x -= mod;
    return *this;
  }
  Int& operator*=(Int that) {
    x = (unsigned long long)x * that.x % mod;
    return *this;
  }
  Int& operator=(Int that) {
    x = that.x;
    return *this;
  }
  Int& operator/=(Int that) {
    x = (unsigned long long)x * inverse(that.x) % mod;
    return *this;
  }
  Int& operator-() {
    x = mod - x;
    if (x == mod) x = 0;
    return *this;
  }
  bool operator==(Int that) { return x == that.x; }
  bool operator!=(Int that) { return x != that.x; }
  Int operator+(Int that) const { return Int(*this) += that; }
  Int operator-(Int that) const { return Int(*this) -= that; }
  Int operator*(Int that) const { return Int(*this) *= that; }
  Int operator/(Int that) const { return Int(*this) /= that; }
};
Int mpow(Int a, int k) {
  Int res = 1;
  while (k) {
    if (k & 1) res = res * a;
    a = a * a;
    k >>= 1;
  }
  return res;
}
namespace std {
ostream& operator<<(ostream& out, const Int& a) {
  out << a.get();
  return out;
}
istream& operator>>(istream& in, Int& a) {
  in >> a.x;
  return in;
}
};  // namespace std
int n;
vector<pair<int, int> > decc;
Int inv[100005];
Int C(int a, int b) {
  if (b < 0 || b > a) return 0;
  Int res = 1;
  for (int i = 0; i < (b); ++i) {
    res *= a - i;
    res *= inv[i + 1];
  }
  return res;
}
Int solve(int l, int r) {
  Int res = 1;
  for (int i = 1; i < decc.size(); ++i) {
    int pos = decc[i].second, place = decc[i].first - decc[i - 1].first - 1;
    if (l <= pos && pos <= r) return 0;
    if (r < pos) {
      res *= C(place, pos - r - 1);
      l -= place - (pos - r - 1);
      r = pos;
    } else {
      res *= C(place, l - pos - 1);
      r += place - (l - pos - 1);
      l = pos;
    }
  }
  if (l < -1 || r > n) return 0;
  ;
  ;
  return res;
}
int main() {
  for (int i = 1; i <= 100004; ++i) inv[i] = Int(1) / i;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    int a;
    scanf("%d", &a);
    if (a > 0) decc.push_back(make_pair(a - 1, i));
  }
  decc.push_back(make_pair(n, -1));
  decc.push_back(make_pair(n + 1, n));
  sort((decc).begin(), (decc).end());
  Int res = 0;
  if (decc[0].first > 0) {
    res += solve(decc[0].second - decc[0].first, decc[0].second) *
           mpow(2, decc[0].first - 1);
    res += solve(decc[0].second, decc[0].second + decc[0].first) *
           mpow(2, decc[0].first - 1);
  } else {
    res += solve(decc[0].second, decc[0].second);
  }
  cout << res << endl;
  return 0;
}
