#include <bits/stdc++.h>
using namespace std;
int n, tot, p[200020], tr[200020], pre[200020], suf[200020];
inline int lowbit(int x) { return x & (-x); }
inline void add(int x) {
  for (int i = x; i <= n; i += lowbit(i)) ++tr[i];
}
inline int sum(int x) {
  int ans = 0;
  for (int i = x; i; i -= lowbit(i)) ans += tr[i];
  return ans;
}
inline int qpower(int x, int k) {
  int ans = 1;
  for (; k; k >>= 1, x = 1ll * x * x % 998244353)
    if (k & 1) ans = 1ll * ans * x % 998244353;
  return ans;
}
inline int inv(int x) { return qpower(x, 998244353 - 2); }
void init() {
  tot = 0;
  memset(tr, 0, sizeof(tr));
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) pre[i] = suf[i] = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p[i]);
    if (~p[i])
      pre[p[i]] = suf[p[i]] = 0;
    else
      ++tot;
  }
}
inline int calc1() {
  int s = 0;
  for (int i = n; i; --i)
    if (~p[i]) {
      s += sum(p[i] - 1);
      if (s >= 998244353) s -= 998244353;
      add(p[i]);
    }
  return s;
}
inline int calc2() {
  return 1ll * tot * (tot - 1) % 998244353 * inv(4) % 998244353;
}
inline int calc3() {
  int ans = 0;
  for (int i = 2; i <= n; ++i) pre[i] = pre[i - 1] + pre[i];
  int cnt = 0;
  for (int i = n; i; --i)
    if (~p[i])
      ans = (ans + 1ll * pre[p[i]] * cnt % 998244353 * inv(tot)) % 998244353;
    else
      ++cnt;
  return ans;
}
inline int calc4() {
  int ans = 0;
  for (int i = n - 1; i; --i) suf[i] = suf[i + 1] + suf[i];
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (~p[i])
      ans = (ans + 1ll * suf[p[i]] * cnt % 998244353 * inv(tot)) % 998244353;
    else
      ++cnt;
  return ans;
}
void solve() {
  int ans = calc1();
  ans += calc2();
  if (ans >= 998244353) ans -= 998244353;
  ans += calc3();
  if (ans >= 998244353) ans -= 998244353;
  ans += calc4();
  if (ans >= 998244353) ans -= 998244353;
  printf("%d\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
