#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, MaxN = 1000001;
int n;
int fact[MaxN], pwr2[MaxN];
void get_fact() {
  fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = ((long long)fact[i - 1] * i) % MOD;
}
void get_pwr2() {
  pwr2[0] = 1;
  for (int i = 1; i <= n; i++) pwr2[i] = (pwr2[i - 1] * 2) % MOD;
}
int pow_mod(int a, int n) {
  if (!n) return 1;
  int val = pow_mod(a, n / 2);
  val = ((long long)val * val) % MOD;
  if (n % 2 == 1) val = ((long long)val * a) % MOD;
  return val;
}
int inv_mod(int a) { return pow_mod(a, MOD - 2); }
int binom(int n, int k) {
  if (k < 0 || k > n) return 0;
  int val = fact[n];
  val = ((long long)val * inv_mod(fact[k])) % MOD;
  val = ((long long)val * inv_mod(fact[n - k])) % MOD;
  return val;
}
int pos[MaxN];
int main() {
  scanf("%d", &n);
  get_fact();
  get_pwr2();
  for (int i = 0; i < n; i++) {
    int v;
    scanf("%d", &v);
    if (v) pos[n - v + 1] = i + 1;
  }
  int n1 = 0, k1 = 0, v1 = 1, n2 = 0, k2 = 0, v2 = 0;
  for (int i = 1; i <= n; i++) {
    if (!pos[i]) continue;
    int L1 = pos[i], R1 = i - L1, NV1 = 0, R2 = n - pos[i] + 1, L2 = i - R2,
        NV2 = 0;
    if (R1 >= 0) {
      NV1 = ((long long)v1 * binom(i - n1 - 1, L1 - k1 - 1) +
             (long long)v2 * binom(i - n2 - 1, L1 - k2 - 1)) %
            MOD;
    }
    if (L2 >= 0) {
      NV2 = ((long long)v1 * binom(i - n1 - 1, L2 - k1) +
             (long long)v2 * binom(i - n2 - 1, L2 - k2)) %
            MOD;
    }
    n1 = n2 = i;
    v1 = NV1;
    v2 = NV2;
    k1 = L1;
    k2 = L2;
  }
  int res = ((long long)(v1 + v2) * pwr2[n - n1]) % MOD;
  printf("%d\n", (int)(((long long)res * inv_mod(2)) % MOD));
}
