#include <bits/stdc++.h>
using ll = long long;
int const MAXN = 111111;
int const MOD = 1000000007;
int N;
int A[MAXN];
int placed[MAXN];
ll pow_mod(ll a, ll k, ll MOD) {
  if (k < 0) return 1;
  ll res = 1, cur = a;
  while (k) {
    if (k & 1) res = res * cur % MOD;
    k /= 2;
    cur = cur * cur % MOD;
  }
  return res;
}
ll inv(ll a, ll m) { return pow_mod(a, m - 2, m); }
int choose(int n, int k, int MOD) {
  if (k > n) return 0;
  if (k * 2 > n) k = n - k;
  if (k == 0) return 1;
  int res = n;
  for (int i = 2; i <= k; ++i) {
    res = (ll)res * (n - i + 1) % MOD;
    res = (ll)res * inv(i, MOD) % MOD;
  }
  return res;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin >> N;
  bool all_zero = true;
  std::fill(placed, placed + MAXN, -1);
  for (int n = 1; n <= N; ++n) {
    std::cin >> A[n];
    placed[A[n]] = n;
    all_zero &= A[n] == 0;
  }
  if (all_zero) {
    std::cout << pow_mod(2, N - 1, MOD) << std::endl;
    return 0;
  }
  int lo = 1;
  while (placed[lo] == -1) ++lo;
  int cnt = 1, places = 0;
  int l = 1, r = N;
  for (int cur = N; cur > lo; --cur) {
    if (placed[cur] == -1) {
      ++places;
      continue;
    }
    int left, right;
    if (placed[lo] < placed[cur]) {
      right = r - placed[cur];
      left = places - right;
    } else {
      left = placed[cur] - l;
      right = places - left;
    }
    if (left < 0 || right < 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
    for (int i = 0; i < right; ++i) {
      if (A[r--] > 0) {
        std::cout << 0 << std::endl;
        return 0;
      }
    }
    for (int i = 0; i < left; ++i) {
      if (A[l++] > 0) {
        std::cout << 0 << std::endl;
        return 0;
      }
    }
    cnt = (ll)cnt * choose(left + right, right, MOD) % MOD;
    if (placed[lo] < placed[cur])
      --r;
    else
      ++l;
    places = 0;
  }
  int first = 0;
  if (placed[lo] - l >= lo - 1) {
    int here = pow_mod(2, lo - 2, MOD);
    int left = (placed[lo] - l) - (lo - 1);
    int right = r - placed[lo];
    here = (ll)here * choose(left + right, left, MOD) % MOD;
    first = (first + here) % MOD;
  }
  if (r - placed[lo] >= lo - 1 && lo > 1) {
    int here = pow_mod(2, lo - 2, MOD);
    int left = placed[lo] - l;
    int right = (r - placed[lo]) - (lo - 1);
    here = (ll)here * choose(left + right, left, MOD) % MOD;
    first = (first + here) % MOD;
  }
  std::cout << (ll)cnt * first % MOD << std::endl;
}
