#include <bits/stdc++.h>
using namespace std;
struct Node {
  int rank, id;
  Node() {}
  Node(int rank, int id) : rank(rank), id(id) {}
  friend bool operator<(const Node &a, const Node &b) {
    return a.rank < b.rank;
  }
} know[100010];
long long fact[100010], antifact[100010];
int n, tot;
long long power(long long p, long long n) {
  long long ans = 1;
  for (; n; n >>= 1, p = p * p % 1000000007)
    if (n & 1) ans = ans * p % 1000000007;
  return ans;
}
long long Anti(long long p) { return power(p, 1000000007 - 2); }
void read() {
  scanf("%d", &n);
  know[++tot] = Node(n + 1, 0), know[++tot] = Node(n + 2, n + 1);
  for (int i = 1, p; i <= n; ++i) {
    scanf("%d", &p);
    if (p) know[++tot] = Node(p, i);
  }
  sort(know + 1, know + tot + 1);
  fact[0] = 1, antifact[0] = 1;
  for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i % 1000000007, antifact[i] = Anti(fact[i]);
}
long long C(int n, int m) {
  return fact[n] * antifact[m] % 1000000007 * antifact[n - m] % 1000000007;
}
long long Brute(int st) {
  long long sum = 1;
  int l = st, r = st, now = 1;
  for (int i = 1; i <= tot; ++i) {
    if (know[i].id == st)
      continue;
    else if (know[i].id > st) {
      sum = sum * C(know[i].rank - now - 1, know[i].id - r - 1) % 1000000007;
      l = l - ((know[i].rank - now) - (know[i].id - r)), r = know[i].id,
      now = know[i].rank;
    } else {
      sum = sum * C(know[i].rank - now - 1, l - know[i].id - 1) % 1000000007;
      r = r + ((know[i].rank - now) - (l - know[i].id)), l = know[i].id,
      now = know[i].rank;
    }
  }
  return sum;
}
bool check(int L, int R) {
  for (int i = 2; i <= n; ++i)
    if (know[i].id >= L && know[i].id <= R) return false;
  return true;
}
void work() {
  long long ans = 0;
  if (tot == 2)
    cout << power(2, n - 1) << endl;
  else if (know[1].rank == 1)
    cout << Brute(know[1].id) << endl;
  else {
    if (know[1].id - know[1].rank + 1 >= 1 &&
        check(know[1].id - know[1].rank + 1, know[1].id - 1))
      ans = (ans + Brute(know[1].id - 1) * power(2, know[1].rank - 2)) %
            1000000007;
    if (know[1].id + know[1].rank - 1 <= n &&
        check(know[1].id + 1, know[1].id + know[1].rank - 1))
      ans = (ans + Brute(know[1].id + 1) * power(2, know[1].rank - 2)) %
            1000000007;
    cout << ans << endl;
  }
}
int main() {
  read();
  work();
  return 0;
}
