#include <bits/stdc++.h>
using namespace std;
int N, a[100010], sum[100010];
long long P[100010], inv[100010], Pinv[100010];
long long func(int L, int R) {
  long long ans = 0, p, q;
  if (sum[L] == sum[R]) {
    long long two = 1;
    for (int i = 0; i < R - L - 1; i++) two = two * 2 % 1000000007ll;
    return two;
  }
  for (p = L; p < R; p++)
    if (a[p] != 0) break;
  for (q = R - 1; q >= L; q--)
    if (a[q] != 0) break;
  if (p == q && a[p] == 1)
    return (P[p - L + R - p - 1] * Pinv[p - L] % 1000000007ll *
            Pinv[R - p - 1] % 1000000007ll);
  if (a[p] >= a[q]) {
    int L2 = p, R2 = L2 + a[p];
    if (R2 > q && R2 <= R)
      ans += func(L2 + 1, R2) * (P[L2 - L + R - R2] * Pinv[L2 - L] %
                                 1000000007ll * Pinv[R - R2] % 1000000007ll);
  }
  if (a[p] <= a[q]) {
    int R2 = q + 1, L2 = R2 - a[q];
    if (L2 >= L && L2 <= p)
      ans += func(L2, R2 - 1) * (P[L2 - L + R - R2] * Pinv[L2 - L] %
                                 1000000007ll * Pinv[R - R2] % 1000000007ll);
  }
  return ans % 1000000007ll;
}
int main(void) {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + ((a[i] == 0) ? 0 : 1);
  inv[1] = P[0] = P[1] = Pinv[0] = Pinv[1] = 1;
  for (int i = 2; i < 100010; i++) {
    inv[i] = (1000000007ll - 1000000007ll / i) * inv[1000000007ll % i] %
             1000000007ll;
    P[i] = P[i - 1] * i % 1000000007ll;
    Pinv[i] = Pinv[i - 1] * inv[i] % 1000000007ll;
  }
  cout << func(0, N) << endl;
  return 0;
}
