#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, maxn = 100010;
struct clan {
  long long val, idx;
  clan() {}
  clan(long long _a, long long _b) {
    val = _a;
    idx = _b;
  }
};
vector<clan> v;
long long n, fact[maxn], li[maxn], ri[maxn], lc[maxn], rc[maxn];
bool cmp(const clan &a, const clan &b) { return a.val < b.val; }
long long f(long long x, long long y) {
  if (!y) return 1;
  long long s = f(x, y >> 1);
  s = (s * s) % mod;
  if (y & 1) s = (s * x) % mod;
  return s;
}
long long calc(long long idx, bool b1, bool b2) {
  long long l1, l2, r1, r2;
  if (!b1)
    l1 = li[idx], r1 = v[idx].idx;
  else
    l1 = v[idx].idx, r1 = ri[idx];
  if (!b2)
    l2 = li[idx - 1], r2 = v[idx - 1].idx;
  else
    l2 = v[idx - 1].idx, r2 = ri[idx - 1];
  if (l1 < 0 || l1 > n || r1 < 1 || r1 > n) return 0;
  if (l2 < 1 || l2 > n || r1 < 1 || r2 > n) return 0;
  if (l2 < l1 || r2 > r1) return 0;
  if (l1 == l2 && r1 == r2) return 0;
  long long res, x, y;
  x = r1 - r2 - 1;
  y = l2 - l1 - 1;
  if (b1) swap(x, y);
  if (!b2)
    res = lc[idx - 1];
  else
    res = rc[idx - 1];
  res = (((res * fact[x + y + 1]) % mod) *
         ((f(fact[x], mod - 2) * f(fact[y + 1], mod - 2)) % mod)) %
        mod;
  if (res < 0) printf("haha\n");
  return res;
}
int main() {
  scanf("%I64d", &n);
  v.push_back(clan(n + 1, 0));
  for (long long i = 1; i <= n; i++) {
    long long x;
    scanf("%I64d", &x);
    if (x) v.push_back(clan(x, i));
  }
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % mod;
  sort(v.begin(), v.end(), cmp);
  if (v[0].val == 1) {
    lc[0] = 1;
    li[0] = v[0].idx;
    rc[0] = 0;
    ri[0] = v[0].idx;
  } else {
    lc[0] = f(2, v[0].val - 2);
    li[0] = v[0].idx - v[0].val + 1;
    rc[0] = f(2, v[0].val - 2);
    ri[0] = v[0].idx + v[0].val - 1;
  }
  for (long long i = 1; i < v.size(); i++) {
    li[i] = v[i].idx - v[i].val + 1;
    ri[i] = v[i].idx + v[i].val - 1;
    lc[i] = (calc(i, 0, 0) + calc(i, 0, 1)) % mod;
    rc[i] = (calc(i, 1, 0) + calc(i, 1, 1)) % mod;
  }
  printf("%I64d\n", rc[v.size() - 1]);
  return 0;
}
