#include <bits/stdc++.h>
namespace io {
int F() {
  int F = 1, n = 0;
  char ch;
  while ((ch = getchar()) != '-' && (ch < '0' || ch > '9'))
    ;
  ch == '-' ? F = 0 : n = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0';
  return F ? n : -n;
}
long long G() {
  long long F = 1, n = 0;
  char ch;
  while ((ch = getchar()) != '-' && (ch < '0' || ch > '9'))
    ;
  ch == '-' ? F = 0 : n = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0';
  return F ? n : -n;
}
}  // namespace io
namespace SubTask9 {
const int maxn = 500010;
const int M = 998244353;
int ex(int b, int e = M - 2) {
  int ans = 1;
  for (; e; e >>= 1, b = (long long)b * b % M)
    if (e & 1) ans = (long long)b * ans % M;
  return ans;
}
int a[maxn];
int fac[maxn];
int ifac[maxn];
int d[maxn];
int vis[maxn];
int s0[maxn];
void add(int p) {
  for (register int i = p; i <= 500000; i += i & -i) d[i]++;
}
int sum(int p) {
  int ans = 0;
  for (register int i = p; i; i -= i & -i) ans += d[i];
  return ans;
}
void main() {
  int n = io::F();
  for (int i = 1; i <= n; ++i) a[i] = io::F(), a[i] == -1 ? a[i] = 0 : 0;
  fac[0] = fac[1] = 1;
  for (register int i = 2; i <= n; ++i) fac[i] = fac[i - 1] * (long long)i % M;
  ifac[n] = ex(fac[n]);
  for (register int i = n - 1; i >= 0; --i)
    ifac[i] = ifac[i + 1] * 1ll * (i + 1) % M;
  int c0 = 0;
  for (register int i = 1; i <= n; ++i) c0 += a[i] == 0;
  for (register int i = 1; i <= n; ++i) vis[i] = 1;
  for (register int i = 1; i <= n; ++i)
    if (a[i]) vis[a[i]] = 0;
  int ans = 0;
  for (register int i = 1; i <= n; ++i)
    if (a[i]) ans = (ans + sum(n) - sum(a[i])) % M, add(a[i]);
  for (register int i = 1; i <= n; ++i) vis[i] += vis[i - 1];
  for (register int i = 1; i <= n; ++i) s0[i] = s0[i - 1] + (a[i] == 0);
  int t1 = 0;
  for (register int i = 1; i <= n; ++i)
    if (a[i]) {
      int fr = s0[i], bk = c0 - s0[i];
      t1 = (t1 + 1ll * fr * (vis[n] - vis[a[i]]) + 1ll * bk * vis[a[i]]) % M;
    }
  if (c0) t1 = t1 * 1ll * fac[c0 - 1] % M;
  ans = (ans + 1ll * t1 * ifac[c0]) % M;
  int t2 = 1ll * (c0 - 1) * c0 / 2 % M * (M + 1 >> 1) % M;
  printf("%d\n", (ans + t2) % M);
  return;
}
}  // namespace SubTask9
int main() {
  SubTask9::main();
  return 0;
}
