#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 1000000007;
int jie[maxn << 1], jie1[maxn << 1], er[maxn];
int mm(int n, int m) {
  long long s = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      s = s * k;
      s %= mod;
    }
    k = k * k;
    k %= mod;
    m >>= 1;
  }
  return s;
}
void init() {
  er[0] = 1;
  for (int i = 1; i < maxn; i++) {
    er[i] = er[i - 1] * 2;
    er[i] %= mod;
  }
  jie[0] = jie1[0] = 1;
  for (int i = 1; i < maxn; i++) {
    jie[i] = ((long long)jie[i - 1] * i) % mod;
    jie1[i] = mm(jie[i], mod - 2);
  }
}
int zuhe(int n, int m) {
  long long s;
  s = jie[n];
  s = s * jie1[m];
  s %= mod;
  s = s * jie1[n - m];
  s %= mod;
  return s;
}
int vis[maxn];
int a[maxn];
int pre[maxn];
int dp[maxn][2];
int s[maxn];
int main() {
  int i, n;
  int ss = 0;
  cin >> n;
  int p;
  init();
  for (i = 1; i <= n; i++) {
    scanf("%d", &p);
    if (p == 0) continue;
    a[p] = i;
  }
  for (i = 1; i <= n; i++) {
    if (a[i - 1] != 0)
      pre[i] = i - 1;
    else
      pre[i] = pre[i - 1];
    if (a[i] != 0) vis[a[i]] = 1;
  }
  for (i = 1; i <= n; i++) s[i] = s[i - 1] + vis[i];
  if (s[n] == 0) {
    cout << er[n - 1] << endl;
    return 0;
  }
  for (i = 1; i <= n; i++) {
    if (a[i] != 0) {
      if (pre[i] == 0) {
        if (a[i] >= i && s[a[i]] - s[a[i] - i] == 1) {
          if (i > 1)
            dp[i][0] = er[i - 2];
          else
            dp[i][0] = 1;
        }
        if (i == 1) continue;
        if (a[i] + i - 1 <= n && s[a[i] + i - 1] - s[a[i]] == 0) {
          if (i > 1)
            dp[i][1] = er[i - 2];
          else
            dp[i][1] = 1;
        }
        continue;
      }
      if (a[i] > a[pre[i]]) {
        if (a[i] < i) continue;
        if (a[pre[i]] >= a[i] - i + 1) {
          if (a[pre[i]] + pre[i] - 1 < a[i]) {
            if (s[a[i]] - s[a[i] - i] -
                    (s[a[pre[i]] + pre[i] - 1] - s[a[pre[i]] - 1]) ==
                1) {
              int x, y;
              x = a[i] - (a[pre[i]] + pre[i]);
              y = a[pre[i]] - (a[i] - i + 1);
              int w = zuhe(x + y, x);
              dp[i][0] += (((long long)dp[pre[i]][1] * w)) % mod;
              dp[i][0] %= mod;
            }
          }
        }
        if (a[i] - i + 1 <= a[pre[i]] - pre[i] + 1) {
          if (s[a[i]] - s[a[i] - i] - (s[a[pre[i]]] - s[a[pre[i]] - pre[i]]) ==
              1) {
            int x, y;
            x = a[i] - a[pre[i]] - 1;
            y = a[pre[i]] - pre[i] + 1 - (a[i] - i + 1);
            int w = zuhe(x + y, x);
            dp[i][0] += (((long long)dp[pre[i]][0] * w)) % mod;
            dp[i][0] %= mod;
          }
        }
      } else {
        if (a[i] + i - 1 > n) continue;
        if (a[pre[i]] + pre[i] - 1 <= a[i] + i - 1) {
          if (s[a[i] + i - 1] - s[a[i] - 1] -
                  (s[a[pre[i]] + pre[i] - 1] - s[a[pre[i]] - 1]) ==
              1) {
            int x, y;
            x = -a[i] + (a[pre[i]]) - 1;
            y = a[i] + i - 1 - (a[pre[i]] + pre[i] - 1);
            int w = zuhe(x + y, x);
            dp[i][1] += ((long long)dp[pre[i]][1] * w) % mod;
            dp[i][1] %= mod;
          }
        }
        if (a[pre[i]] - pre[i] + 1 > a[i]) {
          if (s[a[i] + i - 1] - s[a[i] - 1] -
                  (s[a[pre[i]]] - s[a[pre[i]] - pre[i]]) ==
              1) {
            int x, y;
            x = a[pre[i]] - pre[i] - a[i];
            y = a[i] + i - 1 - a[pre[i]];
            int w = zuhe(x + y, x);
            dp[i][1] += ((long long)dp[pre[i]][0] * w) % mod;
            dp[i][1] %= mod;
          }
        }
      }
    }
  }
  int w = 0;
  for (i = n; a[i] == 0; i--) {
  }
  if (a[i] + i - 1 <= n) {
    int x, y;
    x = a[i] - 1;
    y = n - (a[i] + i - 1);
    w = zuhe(x + y, x);
    ss += ((long long)dp[i][1] * w) % mod;
    ss %= mod;
  }
  if (a[i] >= i) {
    int x, y;
    x = n - a[i];
    y = a[i] - i;
    w = zuhe(x + y, x);
    ss += ((long long)dp[i][0] * w) % mod;
    ss %= mod;
  }
  printf("%d\n", ss);
}
