#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, res = 0;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = res * 10 + ch - '0';
    ch = getchar();
  }
  return res * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 | '0');
}
const long long N = 200005;
const long long P = 998244353;
long long n, a[N], b[N], opt, vis[N], f[N], ans, tr[N], cnt, fac[N];
long long ksm(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % P;
    y >>= 1;
    x = x * x % P;
  }
  return res;
}
long long lowbit(long long x) { return x & (-x); }
long long inv(long long x) { return ksm(x, P - 2); }
void update(long long x) {
  while (x <= n) {
    tr[x]++;
    x += lowbit(x);
  }
}
long long query(long long x) {
  long long res = 0;
  while (x) {
    res += tr[x];
    x -= lowbit(x);
  }
  return res;
}
signed main() {
  n = read();
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) {
    a[i] = read();
    if (a[i] != -1)
      vis[a[i]] = 1;
    else
      cnt++;
    fac[i] = fac[i - 1] * i % P;
  }
  for (long long i = 1; i <= n; i++)
    if (!vis[i]) b[++opt] = i;
  f[2] = fac[cnt] * inv(2) % P;
  for (long long i = 3; i <= n; i++) f[i] = f[i - 1] + f[2];
  long long gs = 0, sum = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] == -1) {
      gs++;
      ans = (ans + f[gs] + sum * fac[cnt - 1] % P) % P;
    } else {
      long long pos = upper_bound(b + 1, b + opt + 1, a[i]) - b - 1;
      sum += pos;
      update(a[i]);
      ans = (ans + (i - gs - query(a[i])) * fac[cnt] % P) % P;
    }
  }
  sum = 0;
  for (long long i = n; i >= 1; i--) {
    if (a[i] == -1) {
      ans = (ans + sum * fac[cnt - 1] % P) % P;
    } else {
      long long pos = upper_bound(b + 1, b + 1 + opt, a[i]) - b;
      sum += opt - pos + 1;
    }
  }
  cout << (ans * inv(fac[cnt])) % P << endl;
}
