#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long n;
long long perm[200003];
long long pow(long long a, long long b) {
  if (b == 0) return 1;
  long long mid = pow(a, b >> 1);
  if (b & 1) return mid * mid % MOD * a % MOD;
  return mid * mid % MOD;
}
void read() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> perm[i];
}
long long bit[200003];
long long get(long long pos) {
  if (pos == 0) return 0;
  long long ans = 0;
  for (pos; pos >= 1; pos -= pos & -pos) ans += bit[pos];
  return ans;
}
void update(long long pos) {
  for (pos; pos <= n; pos += pos & -pos) bit[pos]++;
}
bool is[200003];
long long fact[200003];
long long dp[200003];
void solve() {
  for (long long i = 1; i <= n; i++)
    if (perm[i] != -1) is[perm[i]] = true;
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
  vector<long long> missing;
  for (long long i = 1; i <= n; i++)
    if (!is[i]) missing.push_back(i);
  long long q = fact[missing.size()];
  long long p = 0;
  for (long long i = n; i >= 1; i--)
    if (perm[i] != -1) {
      p = (p + get(perm[i] - 1)) % MOD;
      update(perm[i]);
    }
  p = p * fact[missing.size()] % MOD;
  long long cnt1 = 0, cnt2 = missing.size();
  if (missing.size() > 0)
    for (long long i = 1; i <= n; i++) {
      if (perm[i] != -1) {
        long long bigger, smaller;
        bigger = missing.end() -
                 upper_bound(missing.begin(), missing.end(), perm[i]);
        smaller = missing.size() - bigger;
        p = (p + cnt2 * smaller % MOD * fact[missing.size() - 1] % MOD) % MOD;
        p = (p + cnt1 * bigger % MOD * fact[missing.size() - 1] % MOD) % MOD;
      } else {
        cnt1++;
        cnt2--;
      }
    }
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 1;
  for (long long i = 3; i <= missing.size(); i++)
    dp[i] =
        (i * dp[i - 1] % MOD + (i * (i - 1) / 2) % MOD * fact[i - 1] % MOD) %
        MOD;
  p = (p + dp[missing.size()]) % MOD;
  cout << p * pow(q, MOD - 2) % MOD << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
