#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10, M = 998244353;
struct Fenwick_Tree {
  unsigned long long mx, a[N];
  void clear(long long x) {
    mx = x;
    memset(a, 0, sizeof(a));
  }
  void add(long long x, long long y) {
    for (; x <= mx; x += x & -x) a[x] += y;
  }
  long long query(long long x) {
    long long ret = 0;
    for (; x; x -= x & -x) ret += a[x];
    return ret;
  }
};
long long n, p[N], a[N], b[N];
Fenwick_Tree t;
inline long long qpow(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % M) {
    if (b & 1) ans = ans * a % M;
  }
  return ans;
}
long long inv(long long a) { return qpow(a, M - 2); }
int main() {
  scanf("%lld", &n);
  t.clear(n);
  long long ans = 0, tmp = 0, invm, s = 0;
  memset(b, 0, sizeof(b));
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &p[i]);
    if (p[i] != -1) {
      ans = (ans + i - tmp - 1 - t.query(p[i])) % M;
      t.add(p[i], 1);
      b[p[i]] = 1;
    } else
      tmp++;
  }
  for (long long i = 1; i <= n; i++) a[i] = a[i - 1] + (b[i] ^ 1);
  ans = (ans + tmp * (tmp - 1) % M * inv(4) % M) % M;
  invm = inv(tmp);
  s = 0;
  for (int i = 1; i <= n; i++)
    if (~p[i])
      s += a[p[i]];
    else
      ans = (ans + s * invm % M) % M;
  s = 0;
  for (int i = n; i; i--)
    if (~p[i])
      s += tmp - a[p[i]];
    else
      ans = (ans + s * invm % M) % M;
  printf("%lld", ans);
  return 0;
}
