#include <bits/stdc++.h>
using namespace std;
long long pwr(long long bse, long long dex, long long m) {
  if (dex == 0)
    return 1;
  else {
    long long tmp = pwr(bse, dex / 2, m);
    if (dex % 2 == 1)
      return tmp % m * tmp % m * bse % m;
    else
      return tmp % m * tmp % m;
  }
}
long long n, first;
long long a[200005];
long long b[200005];
long long push_back[200005];
long long fac[200005];
long long p;
long long bit[200005];
long long pc[200005];
void ins(int first) {
  int pnt = first;
  while (pnt <= n) {
    bit[pnt]++;
    pnt += pnt & -pnt;
  }
}
int sum(int first) {
  int pnt = first, s = 0;
  while (pnt >= 1) {
    s += bit[pnt];
    pnt -= pnt & -pnt;
  }
  return s;
}
int main() {
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++) b[i] = 1;
  first = 0;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    if (a[i] == -1) {
      ++first;
    }
    fac[i] = fac[i - 1] * i % 998244353;
    b[a[i]] = 0;
  }
  long long cnt = 0;
  p = 0;
  push_back[0] = 0;
  for (int i = 1; i <= n; i++) {
    push_back[i] = push_back[i - 1] + b[i];
  }
  pc[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] > -1) {
      p += (sum(a[i])) * fac[first];
      p %= 998244353;
      ins(a[i]);
    }
    pc[i] = pc[i + 1] + b[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) {
      cnt++;
    } else {
      p += push_back[a[i]] * (first - cnt) % 998244353 * fac[first - 1] %
           998244353;
      p %= 998244353;
      p += pc[a[i]] * (cnt) % 998244353 * fac[first - 1] % 998244353;
      p %= 998244353;
    }
  }
  if (first > 1) {
    p += first * (first - 1) % 998244353 * fac[first] % 998244353 *
         pwr(4, 998244353 - 2, 998244353) % 998244353;
    p %= 998244353;
  }
  p *= pwr(fac[first], 998244353 - 2, 998244353);
  p %= 998244353;
  printf("%I64d\n", p);
  return 0;
}
