#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7, mod = 998244353;
int n, m, ans, p[N], a[N], b[N], c[N], sp[N], sv[N], inv[N], f[N];
void merge(int l, int r) {
  if (l >= r) return;
  int m = (l + r) / 2, i, j, n1 = m - l + 1, n2 = r - m;
  merge(l, m);
  merge(m + 1, r);
  for (i = 1; i <= n1; i++) b[i] = a[l + i - 1];
  for (i = 1; i <= n2; i++) c[i] = a[m + i];
  i = j = 1;
  b[n1 + 1] = c[n2 + 1] = 1e9;
  for (int k = l; k <= r; k++)
    if (b[i] <= c[j])
      a[k] = b[i++];
    else
      a[k] = c[j++], ans = (ans + n1 - i + 1) % mod;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) sv[i] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    sp[i] = sp[i - 1];
    if (p[i] > 0)
      a[++m] = p[i], sv[p[i]] = 0;
    else
      sp[i]++;
  }
  for (int i = 1; i <= n; i++) sv[i] += sv[i - 1];
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 2; i <= n; i++) f[i] = (f[i - 1] + 1ll * (i - 1) * inv[2]) % mod;
  merge(1, m);
  ans = (ans + f[n - m]) % mod;
  for (int i = 1; i <= n; i++)
    if (p[i] > 0) {
      int P = 1ll * (sv[n] - sv[p[i]]) * sp[i - 1] % mod * inv[sp[n]] % mod;
      ans = (ans + P) % mod;
      P = 1ll * sv[p[i] - 1] * (sp[n] - sp[i]) % mod * inv[sp[n]] % mod;
      ans = (ans + P) % mod;
    }
  printf("%d", ans);
}
