#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n;
int a[1 << 17];
int f[1 << 17];
vector<pair<int, int> > b;
void read() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i]) {
      b.push_back(make_pair(a[i], i));
    }
  }
}
int mul(long long a, long long b) { return (a * b) % mod; }
int pw(int a, int b) {
  if (b == 0) return 1;
  if (b & 1) return mul(a, pw(a, b - 1));
  int c = pw(a, b / 2);
  return mul(c, c);
}
int inv(int x) { return pw(x, mod - 2); }
int ch(int n, int m) {
  if (n < m) return 0;
  return mul(f[n], inv(mul(f[m], f[n - m])));
}
int go(int i, int l, int r) {
  if (r < l) return 1;
  if (i == (int)b.size()) {
    return pw(2, r - l);
  }
  int len = b[i].first - 1;
  int ans = 0, cur;
  if (i + 1 == (int)b.size()) {
    if (b[i].second - len >= l) {
      cur = go(i + 1, b[i].second - len, b[i].second - 1);
      cur = mul(cur, ch(r - l - len, b[i].second - len - l));
      ans = (ans + cur) % mod;
    }
    if (b[i].second + len <= r && b[i].first != 1) {
      cur = go(i + 1, b[i].second + 1, b[i].second + len);
      cur = mul(cur, ch(r - l - len, r - (b[i].second + len)));
      ans = (ans + cur) % mod;
    }
  } else {
    if (b[i + 1].second < b[i].second) {
      if (b[i].second - len < l) {
        ans = 0;
      } else {
        ans = go(i + 1, b[i].second - len, b[i].second - 1);
        ans = mul(ans, ch(r - l - len, b[i].second - len - l));
      }
    } else {
      if (b[i].second + len > r) {
        ans = 0;
      } else {
        ans = go(i + 1, b[i].second + 1, b[i].second + len);
        ans = mul(ans, ch(r - l - len, r - (b[i].second + len)));
      }
    }
  }
  return ans;
}
void solve() {
  f[0] = 1;
  for (int i = 1; i < (1 << 17); i++) {
    f[i] = mul(f[i - 1], i);
  }
  int ans;
  sort(b.rbegin(), b.rend());
  if ((int)b.size() == 0) {
    ans = pw(2, n - 1);
  } else {
    ans = go(0, 0, n - 1);
  }
  printf("%d\n", ans);
}
int main() {
  read();
  solve();
  return 0;
}
