#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int mod = 998244353;
int c[N], a[N], s[N], n, m;
long long ans, dp[N], inv2, inv;
inline void update(int x, int y) {
  for (int i = x; i < N; i += i & -i) c[i] += y;
}
inline int getsum(int x) {
  int res = 0;
  for (int i = x; i; i -= i & -i) res += c[i];
  return res;
}
inline int qpow(int x, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res = (long long)res * x % mod;
    x = (long long)x * x % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  ans = m = 0;
  scanf("%d", &n);
  inv2 = qpow(2, mod - 2);
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1];
    scanf("%d", &a[i]);
    if (a[i] == -1)
      m++;
    else {
      ans += i - 1 - m - getsum(a[i]);
      update(a[i], 1);
      s[i]++;
    }
  }
  inv = qpow(m, mod - 2);
  dp[0] = 0;
  ans %= mod;
  for (int i = 1; i <= m; i++)
    dp[i] = (dp[i - 1] + (long long)(i - 1) * inv2 % mod) % mod;
  ans = (ans + dp[m]) % mod;
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) continue;
    ans = (ans + (long long)(n - i - s[n] + s[i]) *
                     (a[i] - 1 - getsum(a[i] - 1)) % mod * inv % mod) %
          mod;
  }
  for (int i = n; i; i--) {
    if (a[i] == -1) continue;
    ans = (ans + (long long)(i - 1 - s[i - 1]) *
                     (n - a[i] - getsum(n) + getsum(a[i])) % mod * inv % mod) %
          mod;
  }
  printf("%lld\n", ans);
  return 0;
}
