#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1};
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
const int N = 200 * 1000 + 13;
long long n;
long long p[N], gt[N];
bool used[N];
long long power(long long a, long long b, long long m) {
  if (a == 0 and b == 0) return 1;
  if (a == 0) return 0;
  if (b == 0) return 1;
  if (b == 1) return a;
  long long x = power(a, b / 2, m);
  x *= x;
  x %= m;
  if (b % 2 != 0) {
    x *= a;
    x %= m;
  }
  return x;
}
long long f[N];
void upd(long long x) {
  for (long long i = x; i < N; i |= i + 1) ++f[i];
}
long long get(long long x) {
  long long sum = 0;
  for (long long i = x; i >= 0; i = (i & (i + 1)) - 1) sum += f[i];
  return sum;
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] != -1) {
      used[p[i]] = true;
    }
  }
  long long cur = 0;
  for (long long i = n; i >= 1; --i) {
    gt[i] = cur;
    cur += !used[i];
  }
  long long ans = 0;
  ans = cur * (cur - 1);
  ans %= 998244353;
  ans *= power(4, 998244353 - 2, 998244353);
  ans %= 998244353;
  long long inv = power(cur, 998244353 - 2, 998244353);
  long long lft = 0;
  for (long long i = 0; i < n; i++) {
    if (p[i] == -1)
      ++lft;
    else {
      long long x = gt[p[i]] * inv;
      x %= 998244353;
      x *= lft;
      x %= 998244353;
      ans += x;
      ans %= 998244353;
    }
  }
  long long rgh = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (p[i] == -1)
      ++rgh;
    else {
      long long x = (cur - gt[p[i]]) * inv;
      x %= 998244353;
      x *= rgh;
      x %= 998244353;
      ans += x;
      ans %= 998244353;
    }
  }
  long long tmp = 0;
  for (long long i = 0; i < n; i++) {
    if (p[i] == -1) continue;
    ans = ans + tmp - get(p[i]) + 998244353;
    ans %= 998244353;
    upd(p[i]);
    ++tmp;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
