#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const int maxn = (2e5) + 7, N = 2e5;
int n;
int a[maxn], pos[maxn], E, v[maxn], vs, S[maxn];
long long ans, cur, inv2, inve, frac[maxn], ans_1[maxn], c[maxn];
bool M[maxn];
void EX_gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
  } else {
    EX_gcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
}
long long Inv(long long k) {
  long long x, y;
  EX_gcd(k, MOD, x, y);
  while (x < 0) x += MOD;
  return x;
}
int lowbit(int x) { return x & (-x); }
void add(int x, int k) {
  while (x <= n) {
    c[x] += k;
    x += lowbit(x);
  }
}
int sum(int x) {
  int ans = 0;
  while (x > 0) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
void init() {
  memset(c, 0, sizeof(c));
  ans = 0;
  for (int i = n; i >= 1; i--) {
    ans = (ans + sum(a[i] - 1)) % MOD;
    if (a[i] != -1) add(a[i], 1);
  }
  frac[0] = 1;
  for (int i = 1; i <= N; i++) frac[i] = (frac[i - 1] * (long long)(i)) % MOD;
  inv2 = Inv(2), inve = Inv((long long)(E));
  ans_1[1] = 0;
  for (int i = 2; i <= E; i++)
    ans_1[i] =
        (ans_1[i - 1] * (long long)(i) + ((frac[i] * (i - 1)) % MOD) * Inv(2)) %
        MOD;
  ans = (ans + ans_1[E] * Inv(frac[E])) % MOD;
}
int search_pos(int l, int r) { return S[r] - S[l - 1]; }
int main() {
  scanf("%d", &n);
  memset(M, 0, sizeof(M));
  S[0] = 0, E = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    M[a[i]] = true;
    if (a[i] == -1)
      S[i] = S[i - 1] + 1, ++E;
    else
      S[i] = S[i - 1], pos[a[i]] = i;
  }
  vs = 0, v[0] = 0;
  for (int i = 1; i <= n; i++)
    if (!M[i]) v[++vs] = i;
  v[vs + 1] = n + 1;
  init();
  cur = 0;
  for (int i = vs; i >= 1; i--) {
    for (int j = v[i + 1] - 1; j >= v[i] + 1; j--)
      cur += (long long)(search_pos(pos[j] + 1, n));
    ans = (ans + cur * inve) % MOD;
  }
  cur = 0;
  for (int i = 1; i <= vs; i++) {
    for (int j = v[i - 1] + 1; j <= v[i] - 1; j++)
      cur += (long long)(search_pos(1, pos[j] - 1));
    ans = (ans + cur * inve) % MOD;
  }
  printf("%lld\n", ans);
  return 0;
}
