#include <bits/stdc++.h>
using namespace std;
void print(vector<int> input) {
  for (int i : input) cout << i << ",";
}
const long long int p = 998244353;
vector<int> merge(vector<int> left, vector<int> right,
                  long long int* inv_count) {
  vector<int> output;
  int i = 0, j = 0;
  while (i < left.size() && j < right.size()) {
    if (left[i] <= right[j])
      output.push_back(left[i++]);
    else {
      output.push_back(right[j++]);
      *inv_count += (left.size() - i);
      *inv_count %= p;
    }
  }
  for (; i < left.size(); i++) output.push_back(left[i]);
  for (; j < right.size(); j++) output.push_back(right[j]);
  return output;
}
vector<int> merge_sort(vector<int> input, long long int* inv_count) {
  if (input.size() < 2) return input;
  vector<int> left, right;
  int middle = input.size() / 2;
  for (int i = 0; i < middle; i++) left.push_back(input[i]);
  for (int i = middle; i < input.size(); i++) right.push_back(input[i]);
  return merge(merge_sort(left, inv_count), merge_sort(right, inv_count),
               inv_count);
}
long long int factMod(long long int k) {
  if (k == 0)
    return 1;
  else
    return (factMod(k - 1) * k) % p;
}
long long int expMod(long long int n, long long int k) {
  if (k == 0)
    return 1;
  else if (k % 2 == 0) {
    long long int a = expMod(n, k / 2);
    return (a * a) % p;
  } else {
    long long int a = expMod(n, k / 2);
    return (((a * a) % p) * n) % p;
  }
}
long long int numero(vector<int> a, int n) {
  if (a[0] > n) return 0;
  if (a[a.size() - 1] <= n) return a.size();
  int mini = 0;
  int maxi = a.size() - 1;
  while (mini - maxi < -1) {
    int med = mini + (maxi - mini) / 2;
    if (a[med] <= n)
      mini = med;
    else
      maxi = med;
  }
  return mini + 1;
}
long long int invMod(long long int n) { return expMod(n, p - 2); }
int main() {
  long long int n;
  cin >> n;
  int a[n];
  bool aparece[n];
  for (int i = 0; i < int(n); i++) aparece[i] = false;
  vector<int> libres;
  int b[n];
  for (int i = 0; i < int(n); i++) b[i] = 0;
  int cant = 0;
  for (int i = 0; i < int(n); i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1)
      aparece[a[i] - 1] = true;
    else
      cant++;
  }
  for (int i = 0; i < int(n); i++)
    if (!aparece[i]) libres.push_back(i + 1);
  int canti = cant;
  for (int i = 0; i < int(n); i++) {
    if (a[i] == -1) {
      canti--;
    }
    b[i] = canti;
  }
  sort(libres.begin(), libres.end());
  long long int res = 0;
  long long int k = libres.size();
  for (int i = 0; i < int(n); i++) {
    if (a[i] == -1) continue;
    long long int resi;
    if (libres.size() == 0)
      resi = 0;
    else
      resi = numero(libres, a[i]);
    res += (k - resi) * (k - b[i]) + resi * b[i];
    res %= p;
  }
  res *= invMod(k);
  res %= p;
  long long int resi = (k * (k - 1)) % p;
  resi *= invMod(4);
  resi %= p;
  res += resi;
  res %= p;
  vector<int> yaestan;
  for (int i = 0; i < int(n); i++)
    if (a[i] != -1) yaestan.push_back(a[i]);
  resi = 0;
  merge_sort(yaestan, &resi);
  res += (resi % p);
  res %= p;
  cout << res << endl;
  return 0;
}
