#include <bits/stdc++.h>
using namespace std;
const int mm = 1000000007;
long long ans;
int i, j, k, n, a[200001], q[200001], tot;
long long pw(long long b, long long p) {
  long long res = 1;
  for (; p; p >>= 1, b = b * b % mm)
    if (p & 1) res = res * b % mm;
  return res;
}
long long calc(long long a, long long b) {
  long long r1, r2, t, i;
  if (!a || !b) return 1;
  t = a + b;
  r1 = r2 = 1;
  if (a > b) swap(a, b);
  for (i = 1; i <= a; i++) r1 = r1 * (t - i + 1) % mm, r2 = r2 * i % mm;
  return r1 * pw(r2, mm - 2) % mm;
}
long long work(int l, int r) {
  int i, tl, tr;
  long long res = 1;
  for (i = 2; i <= tot; i++) {
    if (l <= q[i] && q[i] <= r) return 0;
    if (q[i] < l) {
      tl = q[i];
      tr = q[i] + a[q[i]] - 1;
      if (tr < r) return 0;
      res = res * calc(l - tl - 1, tr - r) % mm;
    } else {
      tr = q[i];
      tl = q[i] - a[q[i]] + 1;
      if (tl > l) return 0;
      res = res * calc(l - tl, tr - r - 1) % mm;
    }
    l = tl;
    r = tr;
  }
  res = res * calc(l - 1, n - r) % mm;
  return res;
}
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
  scanf("%d", &n);
  for (i = 1, tot = 0; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i]) q[++tot] = i;
  }
  if (!tot) {
    ans = pw(2, n - 1);
    cout << ans << endl;
    return 0;
  }
  sort(q + 1, q + 1 + tot, cmp);
  if (a[q[1]] == 1) {
    ans = work(q[1], q[1]);
  } else {
    ans = 0;
    if (q[1] - a[q[1]] + 1 > 0)
      ans += pw(2, a[q[1]] - 2) * work(q[1] - a[q[1]] + 1, q[1]) % mm;
    if (q[1] + a[q[1]] - 1 <= n)
      ans += pw(2, a[q[1]] - 2) * work(q[1], q[1] + a[q[1]] - 1) % mm;
    ans %= mm;
  }
  cout << ans << endl;
  return 0;
}
