#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 1000 * 1000 + 10;
long long arr[N], bit[N], t[N], t2[N];
int n;
void add(int i) {
  for (i++; i <= n + 2; i += (i & -i)) bit[i]++;
}
long long get(int i) {
  long long sm = 0;
  for (i++; i > 0; i -= (i & -i)) sm += bit[i];
  return sm;
}
long long pw(long long p, long long r) {
  if (r == 0) return 1;
  return (pw((p * p) % mod, r / 2) * ((r % 2) ? p : 1)) % mod;
}
int main() {
  cin >> n;
  long long num = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] != -1) {
      t[arr[i]]++;
      t2[arr[i]]++;
      num++;
    }
  }
  num = n - num;
  long long ans = 0;
  ans = num * (num - 1) % mod * pw(4, mod - 2) % mod;
  for (int i = 0; i < n; i++)
    if (arr[i] != -1) {
      ans += get(n) - get(arr[i]);
      ans %= mod;
      add(arr[i]);
    }
  for (int i = n; i >= 1; i--) {
    t[i] = 1 - t[i];
    t[i] += t[i + 1];
  }
  for (int i = 1; i < n + 1; i++) {
    t2[i] = 1 - t2[i];
    t2[i] += t2[i - 1];
  }
  long long x = 0;
  long long pww = pw(num, mod - 2);
  for (int i = 0; i < n; i++) {
    if (arr[i] == -1)
      x++;
    else {
      ans += (((t[arr[i]] * x) % mod) * pww) % mod;
      ans %= mod;
    }
  }
  x = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] == -1)
      x++;
    else {
      ans += (((t2[arr[i]] * x) % mod) * pww) % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}
