#include <bits/stdc++.h>
using namespace std;
const long long base = 1000000007;
const long long MAXN = 100010;
long long fact[MAXN], inv[MAXN], two[MAXN];
long long mod(long long x) { return (x % base + base) % base; }
long long extGcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGcd(b, a % b, x, y);
  long long t = x;
  x = y;
  y = t - a / b * y;
  return d;
}
long long inverse(long long a, long long base) {
  long long x, y;
  extGcd(a, base, x, y);
  return x;
}
long long C(int n, int m) {
  if (n < m) {
    return 0;
  }
  return fact[n] * inv[m] % base * inv[n - m] % base;
}
void init() {
  fact[0] = inv[0] = two[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    two[i] = two[i - 1] * 2 % base;
    fact[i] = fact[i - 1] * i % base;
    inv[i] = inverse(fact[i], base);
  }
}
map<int, int> ind;
int n;
long long gao(int st, int end, long long ans) {
  if (st < 0 || end > n) {
    ans = 0;
  }
  map<int, int>::iterator it = ind.begin();
  ++it;
  while (it != ind.end()) {
    int num = it->first;
    int pos = it->second;
    ++it;
    if (st < 0 || end > n || ans == 0 || st <= pos && pos <= end) {
      return 0;
    }
    if (end < pos) {
      ans = mod(ans * C(num - end + st - 2, pos - end - 1));
      st = pos - num + 1;
      end = pos;
    } else {
      ans = mod(ans * C(num - end + st - 2, st - pos - 1));
      st = pos;
      end = pos + num - 1;
    }
  }
  return ans;
}
int main() {
  init();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    if (num > 0) {
      ind[num] = i;
    }
  }
  ind[n + 1] = n;
  int num = ind.begin()->first;
  int pos = ind.begin()->second;
  if (num == 1) {
    cout << mod(gao(pos, pos, 1)) << endl;
  } else {
    cout << mod(gao(pos, pos + num - 1, two[num - 2]) +
                gao(pos - num + 1, pos, two[num - 2]))
         << endl;
  }
}
