#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
inline int fpow(int a, int st) {
  if (st < 0) return 1;
  int ans = 1;
  while (st) {
    if (st % 2) ans = (long long)ans * a % 1000000007;
    a = (long long)a * a % 1000000007;
    st /= 2;
  }
  return ans;
}
int a, b, c, d, n, m, k;
int mas[100002], fac[100002], ifac[100002];
bool used[100002];
int cnk(int n, int k) {
  if (n < 0 || k < 0 || k > n) return 0;
  int ans = (long long)fac[n] * ifac[k] % 1000000007;
  return (long long)ans * ifac[n - k] % 1000000007;
}
int solve() {
  vector<pair<int, int> > pos;
  memset(used, 0, n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    if (mas[i] != 0) {
      pos.push_back(make_pair(mas[i], i));
      used[i] = 1;
    }
  }
  sort((pos).begin(), (pos).end());
  int l = pos[0].second, r = pos[0].second;
  int need = pos[0].first - 1;
  for (int _n(l - 1), i(l - need); i <= _n; i++) {
    if (i < 0) return 0;
    if (used[i]) return 0;
  }
  l -= need;
  int ans = fpow(2, need - 1);
  for (int _n(((int)((pos).size()) - 1)), i(1); i <= _n; i++) {
    if (pos[i].second >= l && pos[i].second <= r) return 0;
    int tail = pos[i].first - pos[i - 1].first - 1;
    int dist = -1;
    if (pos[i].second < l) {
      dist = l - pos[i].second - 1;
      if (dist > tail) return 0;
      int rem = tail - dist;
      r += rem;
      l = pos[i].second;
      if (r >= n) return 0;
      ans = (long long)ans * cnk(tail, dist) % 1000000007;
    } else {
      dist = pos[i].second - r - 1;
      if (dist > tail) return 0;
      int rem = tail - dist;
      r = pos[i].second;
      l -= rem;
      if (l < 0) return 0;
      ans = (long long)ans * cnk(tail, dist) % 1000000007;
    }
  }
  int a = l, b = n - r - 1;
  ans = (long long)ans * cnk(a + b, a) % 1000000007;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    scanf("%d", &mas[i]);
  }
  if (*max_element(mas, mas + n) == 0) {
    printf("%d\n", fpow(2, n - 1));
    exit(0);
  }
  fac[0] = ifac[0] = 1;
  for (int _n((100000)), i(1); i <= _n; i++) {
    fac[i] = (long long)fac[i - 1] * i % 1000000007;
    ifac[i] = fpow(fac[i], 1000000007 - 2);
  }
  int ans = solve();
  reverse(mas, mas + n);
  bool ok = 1;
  for (int _n((n)-1), i(0); i <= _n; i++) {
    if (mas[i] == 1) {
      ok = 0;
      break;
    }
  }
  if (ok) {
    ans += solve();
  }
  printf("%d\n", ans % 1000000007);
}
