#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long fac[300001];
long long st(long long x, int n) {
  if (n == 0) {
    return 0;
  }
  if (n == 1) {
    return x;
  }
  if (n % 2 == 0) {
    long long ans = st(x, n / 2);
    return ans * ans % mod;
  }
  return st(x, n - 1) * x % mod;
}
long long rev(long long x) { return st(x, mod - 2); }
vector<long long> a, b, p;
long long ansinv = 0;
void inv(int l, int r) {
  if (l >= r) return;
  if (r - l == 1) {
    if (b[l] > b[r]) ansinv += 1;
    return;
  }
  int m = (l + r) / 2;
  vector<int> c;
  for (int i = l; i <= m; ++i) c.push_back(b[i]);
  sort(c.begin(), c.end());
  for (int i = m + 1; i <= r; ++i) {
    int l1 = -1;
    int r1 = m - l + 1;
    while (r1 - l1 > 1) {
      int m1 = (r1 + l1) / 2;
      if (c[m1] <= b[i])
        l1 = m1;
      else
        r1 = m1;
    }
    ansinv += m - r1 + 1 - l;
  }
  inv(l, m);
  inv(m + 1, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int n;
  cin >> n;
  long long k = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
    if (x != -1) {
      b.push_back(x);
    } else {
      ++k;
    }
  }
  long long ans = 0;
  inv(0, b.size() - 1);
  sort(b.begin(), b.end());
  for (int i = 1; i <= n; ++i) {
    if (!binary_search(b.begin(), b.end(), i)) {
      p.push_back(i);
    }
  }
  fac[0] = 1;
  for (long long i = 1; i <= k; ++i) {
    fac[i] = (fac[i - 1] * i) % mod;
  }
  long long x = 0;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] != -1) {
      long long pos = lower_bound(p.begin(), p.end(), a[i]) - p.begin();
      ans = (ans + (fac[k - 1] * x % mod) * (k - pos) +
             (fac[k - 1] * (k - x) % mod) * pos) %
            mod;
    } else {
      ++x;
    }
  }
  ans = (ans * rev(fac[k])) % mod;
  ans += ansinv;
  ans += ((k * (k - 1)) % mod) * rev(4);
  cout << ans % mod;
  return 0;
}
