#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &a) {
  T x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  a = f ? x : -x;
}
int n, m;
long long ans;
int num[500008 << 1], tre[500008 << 1], le[500008 << 1], ri[500008 << 1],
    cnt[500008 << 1];
inline long long qpow(long long x, long long y) {
  long long res = 1;
  for (; y; y >>= 1, x = x * x % 998244353)
    if (y & 1) res = res * x % 998244353;
  return res;
}
inline void add(int x, int y) {
  for (; x <= n; x += x & -x) tre[x] += y;
}
inline int qury(int x) {
  int res = 0;
  for (; x; x -= x & -x) res += tre[x];
  return res;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) read(num[i]);
  for (register int i = 1; i <= n; ++i) {
    if (num[i] != -1) ++cnt[num[i]];
    le[i] = le[i - 1] + (num[i] == -1);
  }
  for (register int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1];
  for (register int i = n; i; --i) {
    if (num[i] == -1) {
      ++m;
      continue;
    }
    add(num[i], 1);
    ans = (ans + 1ll * qury(num[i] - 1)) % 998244353;
  }
  ans = (ans +
         1ll * m * (m - 1) % 998244353 * qpow(4, 998244353 - 2) % 998244353) %
        998244353;
  for (register int i = n; i; --i) {
    ri[i] = ri[i + 1] + (num[i] == -1);
    if (num[i] == -1) continue;
    ans = (ans + 1ll * (num[i] - cnt[num[i]]) * ri[i] % 998244353 *
                     qpow(m, 998244353 - 2) % 998244353) %
          998244353;
    ans = (ans + 1ll * (m - num[i] + cnt[num[i]]) * le[i] % 998244353 *
                     qpow(m, 998244353 - 2) % 998244353) %
          998244353;
  }
  while (ans < 0) ans = (ans % 998244353 + 998244353) % 998244353;
  printf("%lld\n", (ans % 998244353 + 998244353) % 998244353);
  return 0;
}
