#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
const int mod = 998244353;
int p[maxn];
int C[maxn];
int cgt[maxn], gt[maxn];
int N;
inline int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
  return a;
}
inline int mul(int a, int b) { return a * 1ll * b % mod; }
inline int pow_mod(int x, int n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  int y = pow_mod(x, n / 2);
  y = mul(y, y);
  if (n & 1) y = mul(y, x);
  return y;
}
inline int inv(int x) { return pow_mod(x, mod - 2); }
inline void update(int x) {
  for (; x <= N; x += x & (-x)) ++C[x];
}
inline int get(int x) {
  int ret = 0;
  for (; x > 0; x -= x & (-x)) ret += C[x];
  return ret;
}
int main() {
  int n, cnt = 0;
  scanf("%d", &n);
  N = n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p[i]);
    if (p[i] == -1)
      ++cnt;
    else
      cgt[p[i]] = 1;
  }
  int res = mul(mul(cnt, cnt - 1), inv(4));
  int mcnt = 0;
  for (int i = n; i >= 1; --i) {
    gt[i] = mcnt;
    mcnt += !cgt[i];
  }
  int lft = 0, rgt = 0;
  int invcnt = inv(cnt);
  for (int i = 1; i <= n; ++i) {
    if (p[i] == -1)
      ++lft;
    else
      res = add(res, mul(mul(invcnt, lft), gt[p[i]]));
  }
  for (int i = n; i >= 1; --i) {
    if (p[i] == -1)
      ++rgt;
    else
      res = add(res, mul(mul(invcnt, rgt), (cnt - gt[p[i]])));
  }
  int tcnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (p[i] != -1) {
      res = add(res, tcnt - get(p[i]));
      update(p[i]);
      ++tcnt;
    }
  }
  printf("%d\n", res);
  return 0;
}
