#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int n, a[N], ada[N], p, q, bit[N], f[N];
vector<int> v;
void update(int pos) {
  for (int i = pos; i < N; i += (i & -i)) {
    bit[i]++;
  }
}
int query(int pos) {
  int ret = 0;
  for (int i = pos; i; i -= (i & -i)) {
    ret += bit[i];
  }
  return ret;
}
int poww(int x, int e) {
  int ret = 1;
  while (e) {
    if (e & 1) {
      ret = 1ll * ret * x % mod;
    }
    x = 1ll * x * x % mod;
    e >>= 1;
  }
  return ret;
}
void add(int &x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  f[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = 1ll * i * f[i - 1] % mod;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != -1) {
      ada[a[i]] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!ada[i]) {
      v.push_back(i);
    }
  }
  int sz = (int)v.size(), sum = 0;
  int ct = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) {
      if (sz) {
        add(p, 1ll * sum * f[sz - 1] % mod);
      }
      if (sz >= 2 && ct) {
        int now = (1ll * sz * (sz - 1) / 2) % mod * ct % mod * f[sz - 2] % mod;
        add(p, now);
      }
      ct++;
    } else {
      int less = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
      add(sum, less);
      add(p, 1ll * (query(n) - query(a[i])) * f[sz] % mod);
      update(a[i]);
      if (sz) {
        int now = 1ll * (sz - less) * ct % mod * f[sz - 1] % mod;
        add(p, now);
      }
    }
  }
  q = f[sz];
  cout << 1ll * p * poww(q, mod - 2) % mod << "\n";
}
