#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline string tostr(const T& x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
const long double EPS = 1e-14;
const int INF = 1000 * 1000 * 1000;
const char CINF = 102;
const long long LINF = INF * 1ll * INF;
const long double DINF = 1e200;
const long double PI = 3.1415926535897932384626433832795L;
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
int n;
vector<pair<int, int> > pos;
const long long mod = INF + 7;
long long powmod(long long a, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = r * a % mod;
    p >>= 1;
    a = a * a % mod;
  }
  return r;
}
long long C(int n, int k) {
  long long r = 1;
  for (int i = n - k + 1; i <= n; ++i) {
    r = r * i % mod * powmod(n - i + 1, mod - 2) % mod;
  }
  return r;
}
long long doit(int a, int b, int t) {
  long long res = 1;
  for (int i = 1; i < ((int)(pos).size()); ++i) {
    int p = pos[i].second;
    int d = pos[i].first;
    int aa, bb;
    if (p < a) {
      aa = p + 1;
      bb = b + ((d - t) - (a - p));
      if (bb < b || bb > n) return 0;
    } else if (p >= b) {
      bb = p;
      aa = a - ((d - t) - (p + 1 - b));
      if (aa > a || aa < 0) return 0;
    } else
      return 0;
    res = res * C(a - aa + bb - b, a - aa) % mod;
    if (p < a)
      --aa;
    else
      ++bb;
    a = aa;
    b = bb;
    t = d;
  }
  if (a < 0 || b > n) return 0;
  res = res * C(a + n - b, a) % mod;
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    int a;
    scanf("%d", &a);
    if (a) pos.push_back(make_pair(a, i));
  }
  sort((pos).begin(), (pos).end());
  if (!((int)(pos).size())) {
    cout << powmod(2, n - 1);
    return 0;
  }
  long long res;
  if (pos[0].first == 1) {
    res = doit(pos[0].second, pos[0].second + 1, 1);
  } else {
    res = (doit(pos[0].second, pos[0].second + pos[0].first, pos[0].first) *
               powmod(2, pos[0].first - 2) +
           doit(pos[0].second - pos[0].first + 1, pos[0].second + 1,
                pos[0].first) *
               powmod(2, pos[0].first - 2)) %
          mod;
  }
  cout << res;
  return 0;
}
