#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
int n, tree[200000 + 5];
inline int lowbit(int x) { return x & -x; }
int Sum(int i) {
  int cnt = 0;
  while (i) cnt += tree[i], i -= lowbit(i);
  return cnt;
}
void Add(int i, int x) {
  while (i <= n) tree[i] += x, i += lowbit(i);
  return;
}
long long Cal(long long x) {
  return x * (x - 1) % 998244353 * 499122177ll % 998244353 * 499122177ll %
         998244353;
}
long long Pow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = (ret * x) % 998244353;
    x = (x * x) % 998244353;
    y >>= 1;
  }
  return ret;
}
inline long long Inv(long long x) { return Pow(x, 998244353 - 2); }
map<int, int> Map;
long long s[200000 + 5], inv[200000 + 5];
int a[200000 + 5], se[200000 + 5];
struct node {
  int val, pos;
  friend bool operator<(node a, node b) { return a.val < b.val; }
} num[200000 + 5];
int main() {
  unsigned long long Ans = 0;
  int E = 0, len = 0;
  long long S1 = 0, S2 = 0, S3 = 0;
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    se[i] = se[i - 1];
    if (a[i] == -1) {
      E++, se[i]++;
      continue;
    }
    num[++len] = (node){a[i], i};
    S1 = (S1 + i - E - Sum(a[i] - 1) - 1) % 998244353, Add(a[i], 1);
  }
  sort(num + 1, num + len + 1);
  for (int i = 1; i <= len; i++) Map[num[i].val] = num[i].pos;
  for (int i = 1; i <= len; i++) {
    int p = Map[num[i].val];
    S2 = (S2 + 1ll * se[p] * (n - num[i].val - (len - i)) % 998244353 +
          1ll * (se[n] - se[p]) * (num[i].val - 1 - (i - 1)) % 998244353) %
         998244353;
  }
  S3 = Cal(E) % 998244353;
  Ans = (S1 + S3) % 998244353;
  Ans = (Ans + S2 * Inv(E) % 998244353) % 998244353;
  printf("%lld\n", Ans);
  return 0;
}
