#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 998244353;
struct bit {
  long long base[maxn];
  void add(int i, long long x) {
    for (; i < maxn; i += (i & -i)) {
      base[i] = (base[i] + x) % mod;
    }
  }
  long long getSum(int i) {
    long long res = 0;
    for (; i; i -= (i & -i)) {
      res = (res + base[i]) % mod;
    }
    return res;
  }
} it[2];
long long qpow(long long a, long long t = mod - 2) {
  long long b = 1;
  for (; t > 0; t >>= 1, a = a * a % mod) {
    if (t & 1) b = b * a % mod;
  }
  return b;
}
int a[maxn], vis[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > 0) vis[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) it[1].add(i, 1);
  }
  long long ans = 0, cand = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0) {
      long long tmp = (it[0].getSum(n) - it[0].getSum(a[i]) + mod) % mod;
      ans = (ans + tmp) % mod;
      it[0].add(a[i], 1);
    } else {
      cand++;
    }
  }
  if (cand == 0) cout << ans << endl, exit(0);
  ans += cand * (cand - 1) % mod * qpow(2) % mod * qpow(2) % mod;
  ans %= mod;
  if (ans < 0) ans += mod;
  long long cnt = 0, invc = qpow(cand);
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0) {
      long long big = cand - it[1].getSum(a[i]);
      ans = (ans + big * invc % mod * cnt % mod) % mod;
      ans = (ans + (cand - big) * invc % mod * (cand - cnt) % mod) % mod;
    } else {
      cnt++;
    }
  }
  cout << ans << endl;
}
