#include <bits/stdc++.h>
using namespace std;

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  unsigned v;
  modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; }
  m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; }
  m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; }
  m& operator/=(m r) { return *this *= power(r, M - 2); }
  friend m operator+(m l, m r) { return l += r; }
  friend m operator-(m l, m r) { return l -= r; }
  friend m operator*(m l, m r) { return l *= r; }
  friend m operator/(m l, m r) { return l /= r; }
  friend bool operator==(m l, m r) { return l.v == r.v; }
  friend string to_string(m a) { return to_string(a.v); }
};

template <class T> struct fenwick {
  const int n;
  vector<T> t;
  fenwick(int _n) : n(_n), t(n + 1) {}
  void add(int i, T a) { for (++i; i <= n; i += i & -i) t[i] += a; }
  T sum(int i) const {
    T s = 0;
    for (; i; i -= i & -i) s += t[i];
    return s;
  }
  T sum(int l, int r) const { return sum(r) - sum(l); }
  int kth(T k) const {
    int i = 0;
    for (int w = 1 << __lg(n); w; w >>= 1)
      if (i + w <= n and t[i + w] <= k) k -= t[i += w];
    return i;
  }
};

constexpr long long mod = 1e9 + 7;
using mint = modular<mod>;

vector<mint> fact, inv_fact, minv;
void prepare(int n) {
  fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
  for (int i = 0; i <= n; ++i) fact[i] = i ? i * fact[i - 1] : 1;
  inv_fact[n] = power(fact[n], mod - 2);
  for (int i = n; i; --i) inv_fact[i - 1] = i * inv_fact[i];
  for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}
template<> mint& mint::operator/=(mint r) {
  return *this *= r.v < minv.size() ? minv[r.v] : power(r, mod - 2);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto&& e : p) {
    cin >> e;
    --e;
  }
  prepare(max(n, 2));
  vector<mint> ex(n);
  {
    fenwick<mint> ft(n);
    for (int i = n; i--; ) {
      if (p[i] != -1) {
        ex[i] += ft.sum(p[i]);
        ft.add(p[i], 1);
      }
    }
  }
  {
    vector<int> lt(n, 1);
    for (int e : p) {
      if (e != -1) {
        lt[e] = 0;
      }
    }
    lt.insert(begin(lt), 0);
    for (int i = 0; i < n; ++i) {
      lt[i + 1] += lt[i];
    }
    int cnt = 0;
    for (int i = n; i--; ) {
      if (p[i] != -1) {
        ex[i] += lt[p[i]] * minv[lt[n]] * cnt;
      } else {
        ++cnt;
      }
    }
  }
  {
    vector<int> geq(n, 1);
    for (int e : p) {
      if (e != -1) {
        geq[e] = 0;
      }
    }
    geq.push_back(0);
    for (int i = n; i--; ) {
      geq[i] += geq[i + 1];
    }
    fenwick<mint> ft(n);
    for (int i = n; i--; ) {
      if (p[i] == -1) {
        ex[i] += ft.sum(n);
      } else {
        ft.add(p[i], geq[p[i]] * minv[geq[0]]);
      }
    }
  }
  {
    int cnt = 0;
    for (int i = n; i--; ) {
      if (p[i] == -1) {
        ex[i] += minv[2] * cnt;
        ++cnt;
      }
    }
  }
  mint res;
  for (int i = 0; i < n; ++i) {
    res += ex[i] * fact[n - i - 1];
  }
  res += 1;
  res *= fact[count(begin(p), end(p), -1)];
  cout << res.v << '\n';
}


Measured memory_bytes: 16048