#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const int mod = 998244353;
inline int qpow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = (long long)res * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return res;
}
inline int get_inv(int x) { return qpow(x, mod - 2); }
int n;
int sum_emp[maxn], a[maxn];
int bit[maxn];
int fac[maxn];
int fin_sum[maxn];
bool in_a[maxn];
inline int lowbit(int x) { return x & -x; }
inline void modify(int pos, int add) {
  for (int i = pos; i <= n; i += lowbit(i)) bit[i] += add;
}
inline int query(int pos) {
  int res = 0;
  for (int i = pos; i; i ^= lowbit(i)) res += bit[i];
  return res;
}
int main() {
  scanf("%d", &n);
  int emp_cnt = 0, fin_cnt = 0;
  int ans = 0;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    sum_emp[i] = sum_emp[i - 1];
    if (a[i] == -1)
      sum_emp[i]++, emp_cnt++;
    else {
      ans = (ans + fin_cnt - query(a[i])) % mod;
      modify(a[i], 1);
      in_a[a[i]] = true;
      fin_cnt++;
    }
    fac[i] = (long long)fac[i - 1] * i % mod;
  }
  for (int i = 1; i <= n; i++) {
    fin_sum[i] = fin_sum[i - 1] + 1;
    if (in_a[i]) fin_sum[i]--;
  }
  int add = 0;
  for (int i = 1; i <= emp_cnt; i++) {
    long long cur =
        (long long)get_inv(i) * (((long long)(i - 1) * i / 2) % mod) % mod;
    add = (add + cur) % mod;
  }
  ans = (ans + add) % mod;
  add = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != -1) {
      int pre_emp = sum_emp[i - 1], lar_emp = fin_sum[n] - fin_sum[a[i]];
      add =
          (add + (long long)pre_emp * lar_emp % mod * get_inv(emp_cnt) % mod) %
          mod;
      int nxt_emp = sum_emp[n] - sum_emp[i], sma_emp = fin_sum[a[i] - 1];
      add =
          (add + (long long)nxt_emp * sma_emp % mod * get_inv(emp_cnt) % mod) %
          mod;
    }
  }
  ans = (ans + add) % mod;
  printf("%d\n", ans);
  return 0;
}
