#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 2e5 + 5;
int vis[maxn];
int a[maxn];
long long qpow(long long a, long long x) {
  long long ret = 1;
  long long tmp = a;
  while (x) {
    if (x & 1) ret = ret * tmp % mod;
    tmp = tmp * tmp % mod;
    x >>= 1;
  }
  return ret;
}
int b[maxn];
int cnt[maxn];
int c[maxn];
int z[maxn];
int lowbit(int i) { return i & (-i); }
int insert(int i, int x) {
  while (i < maxn) {
    z[i] += x;
    i += lowbit(i);
  }
  return 0;
}
int getsum(int i) {
  int sum = 0;
  while (i > 0) {
    sum += z[i];
    i -= lowbit(i);
  }
  return sum;
}
int main() {
  int n;
  scanf("%d", &n);
  int ind2 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != -1) {
      vis[a[i]]++;
      c[ind2++] = a[i];
    }
  }
  int ind = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      b[ind++] = i;
    }
  }
  long long sum = 0;
  for (int i = 1; i <= ind2; i++) {
    insert(c[i - 1], 1);
    sum += i - getsum(c[i - 1]);
    if (sum > mod) sum -= mod;
  }
  int num = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] == -1) {
      num++;
    } else {
      cnt[i] = num;
    }
  }
  if (num == 0) {
    printf("%I64d\n", sum % mod);
    return 0;
  }
  long long fz = 1ll * ind * (ind - 1) % mod * ind % mod;
  fz = (fz + 4ll * num * sum % mod) % mod;
  long long fm = 4ll * num;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) continue;
    int r = lower_bound(b, b + num, a[i]) - b;
    fz =
        (fz + 4ll * r * cnt[i] % mod + 4ll * (num - r) * (num - cnt[i]) % mod) %
        mod;
  }
  printf("%I64d\n", fz * qpow(fm, 1ll * mod - 2) % mod);
}
