#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long sum = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
  return sum * ff;
}
const long long mod = 1e9 + 7;
const long long mo = 998244353;
const long long N = 2e5 + 5;
long long n, m, a[N], cl[N], cr[N], ca[N], C[N], ans;
inline long long ksm(long long x, long long y) {
  long long z = 1ll;
  while (y) {
    if (y & 1ll) z = z * x % mo;
    x = x * x % mo;
    y >>= 1ll;
  }
  return z;
}
inline void Add(long long &x, long long y) {
  x += y;
  if (x >= mo) x -= mo;
}
inline void add(long long x, long long y) {
  while (x <= n) {
    C[x] += y;
    x += x & (-x);
  }
}
inline long long ask(long long x) {
  long long ans = 0;
  while (x) {
    ans += C[x];
    x -= x & (-x);
  }
  return ans;
}
signed main() {
  n = read();
  for (long long i = (1); i <= (n); i++) {
    a[i] = read();
    if (~a[i]) ca[a[i]]++;
    cl[i] = cl[i - 1] + (a[i] == -1);
  }
  for (long long i = (1); i <= (n); i++) ca[i] += ca[i - 1];
  long long INV4 = ksm(4ll, mo - 2) % mo;
  Add(ans, cl[n] * (cl[n] - 1) % mo * INV4);
  long long INVM = ksm(cl[n], mo - 2) % mo;
  for (long long i = (n); i >= (1); i--) {
    cr[i] = cr[i + 1] + (a[i] == -1);
    if (~a[i]) {
      long long gs = ask(a[i]);
      add(a[i], 1ll);
      Add(ans, gs);
      long long R = cr[i] * (a[i] - ca[a[i]]) % mo * INVM % mo;
      Add(ans, R);
      long long L = cl[i] * (cl[n] - (a[i] - ca[a[i]])) % mo * INVM % mo;
      Add(ans, L);
    }
  }
  printf("%lld\n", (ans + mo) % mo);
}
