#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int n, a[100000 + 1], fac[100000 + 1], seq[100000 + 1], ind[100000 + 1],
    cnt = 0;
inline bool cmp(int x, int y) { return a[x] > a[y]; }
inline int pw(int a, int b) {
  int r = 1;
  while (b > 0) {
    if (b & 1) r = (long long)r * a % mod;
    a = (long long)a * a % mod;
    b >>= 1;
  }
  return r;
}
inline int C(int n, int m) {
  return (long long)fac[n] * pw((long long)fac[m] * fac[n - m] % mod, mod - 2) %
         mod;
}
int solve(int L, int R) {
  if (L > R) return 0;
  int ret = 1, lc = 0, rc = 0, lt = L - 1, rt = n - R;
  for (int i = 1; i <= n && a[seq[i]] > 1; ++i) {
    int cnt = a[seq[i - 1]] - a[seq[i]] - 1;
    if (seq[i] < L) {
      int le = seq[i] - 1 - lc;
      if (le < 0 || le > cnt) return 0;
      ret = (long long)ret * C(cnt, le) % mod;
      lc += le + 1, rc += cnt - le;
    } else {
      int re = n - seq[i] - rc;
      if (re < 0 || re > cnt) return 0;
      ret = (long long)ret * C(cnt, re) % mod;
      rc += re + 1, lc += cnt - re;
    }
  }
  int len = R - L;
  if (lc < lt && rc < rt)
    ret = (long long)ret * C(lt + rt - lc - rc, lt - lc) % mod;
  if (lc > lt && rc > rt)
    ret = 0;
  else if (lc > lt)
    len -= lc - lt;
  else if (rc > rt)
    len -= rc - rt;
  if (len < 0) return 0;
  ret = (long long)ret * pw(2, len) % mod;
  return ret;
}
int main(int argc, char *argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) seq[i] = i;
  sort(seq + 1, seq + n + 1, cmp);
  a[0] = n + 1, fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = (long long)fac[i - 1] * i % mod;
  int p1 = 0, ans = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] == 1)
      p1 = i;
    else if (a[i] > 0)
      ind[++cnt] = i;
  if (p1 != 0)
    ans = solve(p1, p1);
  else {
    int mode = 0, p;
    for (int i = 2; i <= cnt; ++i)
      if (a[ind[i - 1]] < a[ind[i]]) {
        if (mode == 0)
          mode = 2;
        else if (mode == 1)
          mode = 3, p = i - 1;
      } else {
        if (mode == 0)
          mode = 1;
        else if (mode == 2 || mode == 3)
          mode = 4;
      }
    if (mode == 0) {
      if (cnt == 0)
        ans = solve(1, n);
      else
        ans = solve(1, ind[1] - 1) + solve(ind[1] + 1, n);
    } else if (mode == 1) {
      ans = solve(ind[cnt - 1] + 1, ind[cnt] - 1) + solve(ind[cnt] + 1, n);
    } else if (mode == 2) {
      ans = solve(1, ind[1] - 1) + solve(ind[1] + 1, ind[2] - 1);
    } else if (mode == 3) {
      ans =
          solve(ind[p - 1] + 1, ind[p] - 1) + solve(ind[p] + 1, ind[p + 1] - 1);
    }
  }
  printf("%d\n", ans % mod);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
