#include <bits/stdc++.h>
using namespace std;
long long n, a[200200], Res;
long long Before[200200], After[200200], Cnt;
bool in[200200];
vector<long long> v;
vector<long long> numbers;
long long Smaller[200200], Larger[200200];
long long seg[5 * 200200];
void Update(long long node, long long st, long long en, long long idx);
long long Query(long long node, long long st, long long en, long long left,
                long long right);
long long mul(long long a, long long b) { return (a * b) % 998244353; }
long long add(long long a, long long b) { return (a + b) % 998244353; }
long long sub(long long a, long long b) {
  return (a - b + 998244353) % 998244353;
}
long long fastPower(long long a, long long b);
long long inv(long long a) { return fastPower(a, 998244353 - 2); }
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1)
      Cnt++;
    else
      in[a[i]] = 1, Before[a[i]] = Cnt, numbers.push_back(a[i]);
  }
  for (long long i = 1; i <= n; i++) {
    if (!in[i])
      v.push_back(i);
    else
      After[i] = Cnt - Before[i];
  }
  sort(v.begin(), v.end());
  for (long long i = 1; i <= n; i++) {
    if (!in[i]) continue;
    vector<long long>::iterator it = lower_bound(v.begin(), v.end(), i);
    long long id = it - v.begin();
    Smaller[i] = id;
    Larger[i] = v.size() - id;
  }
  Res = mul(mul(Cnt, Cnt - 1), inv(4));
  for (long long i = 1; i <= n; i++) {
    if (!in[i]) continue;
    Res = add(Res, mul(Before[i], mul(Larger[i], inv(v.size()))));
    Res = add(Res, mul(After[i], mul(Smaller[i], inv(v.size()))));
  }
  for (long long i = 0; i < numbers.size(); i++) {
    Res = add(Res, Query(1, 1, n, numbers[i] + 1, n));
    Update(1, 1, n, numbers[i]);
  }
  cout << Res << endl;
  return 0;
}
long long fastPower(long long a, long long b) {
  if (!b) return 1ll;
  long long res = fastPower(a, b / 2);
  res = mul(res, res);
  if (b & 1) return mul(res, a);
  return res;
}
void Update(long long node, long long st, long long en, long long idx) {
  if (st == en)
    seg[node] = 1;
  else {
    long long mid = (st + en) / 2;
    if (mid >= idx) {
      Update(node * 2, st, mid, idx);
    } else {
      Update(node * 2 + 1, mid + 1, en, idx);
    }
    seg[node] = seg[2 * node] + seg[2 * node + 1];
  }
}
long long Query(long long node, long long st, long long en, long long left,
                long long right) {
  if (left > en || right < st) return 0;
  if (st >= left && en <= right) return seg[node];
  long long mid = (st + en) / 2;
  long long p1 = Query(2 * node, st, mid, left, right);
  long long p2 = Query(2 * node + 1, mid + 1, en, left, right);
  return (p1 + p2);
}
