#include <bits/stdc++.h>
template <class T>
std::ostream& operator<<(std::ostream& out, std::vector<T>& dat) {
  for (int i = 0; i < dat.size(); ++i) {
    out << dat[i];
    if (i < dat.size() - 1) out << ' ';
  }
  return out;
}
long long MOD = 998244353;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long gcdExtended(long long a, long long b) {
  long long s = 0;
  long long t = 1;
  long long r = b;
  long long sOld = 1;
  long long tOld = 0;
  long long rOld = a;
  while (r != 0) {
    long long q = rOld / r;
    long long rNew = rOld - q * r;
    rOld = r;
    r = rNew;
    long long sNew = sOld - q * s;
    sOld = s;
    s = sNew;
    long long tNew = tOld - q * t;
    tOld = t;
    t = tNew;
  }
  return sOld;
}
std::vector<long long> merge(std::vector<long long>& left,
                             std::vector<long long>& right,
                             long long* inv_count) {
  std::vector<long long> output;
  long long 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);
    }
  }
  for (; i < left.size(); i++) output.push_back(left[i]);
  for (; j < right.size(); j++) output.push_back(right[j]);
  return output;
}
std::vector<long long> merge_sort(std::vector<long long>& input,
                                  long long* inv_count) {
  if (input.size() < 2) return input;
  std::vector<long long> left, right;
  long long middle = input.size() / 2;
  for (long long i = 0; i < middle; i++) left.push_back(input[i]);
  for (long long i = middle; i < input.size(); i++) right.push_back(input[i]);
  auto L = merge_sort(left, inv_count);
  auto R = merge_sort(right, inv_count);
  return merge(L, R, inv_count);
}
long long countInversions(std::vector<long long>& dat) {
  long long out = 0;
  merge_sort(dat, &out);
  return out;
}
void solve(int testID) {
  int N;
  std::cin >> N;
  std::vector<int> dat(N);
  std::set<int> found;
  std::vector<long long> x;
  for (int k = 0; k < N; ++k) {
    std::cin >> dat[k];
    if (dat[k] != -1) {
      found.insert(dat[k]);
      x.push_back(dat[k]);
    }
  }
  long long existingInversions = countInversions(x);
  existingInversions %= MOD;
  std::vector<int> missing;
  missing.push_back(-50);
  for (int k = 1; k <= N; ++k) {
    if (found.count(k) == 0) missing.push_back(k);
  }
  if (missing.size() == 1) {
    std::cout << existingInversions << '\n';
    return;
  }
  long long M = missing.size() - 1;
  long long out = 0;
  long long outStep = 0;
  for (int k = 0; k < N; ++k) {
    if (dat[k] > 0) {
      int lo = 0;
      int hi = missing.size();
      while (hi - lo > 1) {
        int curr = (lo + hi) / 2;
        if (missing[curr] < dat[k])
          lo = curr;
        else
          hi = curr;
      }
      int numMissingBelow = lo;
      outStep += numMissingBelow;
    } else {
      out += outStep;
    }
  }
  outStep = 0;
  for (int k = N - 1; k >= 0; --k) {
    if (dat[k] > 0) {
      int lo = 0;
      int hi = missing.size();
      while (hi - lo > 1) {
        int curr = (lo + hi) / 2;
        if (missing[curr] < dat[k])
          lo = curr;
        else
          hi = curr;
      }
      int numMissingBelow = lo;
      outStep += M - numMissingBelow;
    } else {
      out += outStep;
    }
  }
  long long numA = out;
  long long denomA = M;
  long long numB = (M * (M - 1)) / 2;
  long long denomB = 2;
  long long num = numA * denomB + numB * denomA;
  long long denom = denomA * denomB;
  long long g = gcd(num, denom);
  num /= g;
  denom /= g;
  num += existingInversions * denom;
  num %= MOD;
  denom %= MOD;
  long long denomInverse = gcdExtended(denom, MOD);
  while (denomInverse < 0) denomInverse += MOD;
  long long outFinal = (num * denomInverse) % MOD;
  std::cout << outFinal << std::endl;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(14);
  gcdExtended(6, 11);
  solve(0);
  return 0;
}
