#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long n, a[200005], ft[200005], b = 0, _b, inv = 0, ans = 0;
bool pre[200005];
void update(int i, int x) {
  for (; i <= n; i += i & -i) ft[i] += x;
}
long long query(int i) {
  int s = 0;
  for (; i; i -= i & -i) s += ft[i];
  return s;
}
long long bpw(long long b, int p) {
  long long ans = 1;
  for (; p; p >>= 1, b = b * b % mod)
    if (p & 1) ans = ans * b % mod;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] ^ -1) {
      ans += i - b - 1 - query(a[i]);
      update(a[i], 1);
      pre[a[i]] = 1;
    } else {
      b++;
    }
  }
  memset(ft, 0, sizeof(ft));
  for (int i = 1; i <= n; i++)
    if (!pre[i]) update(i, 1);
  ans = (ans + b * (b - 1) % mod * bpw(4, mod - 2)) % mod;
  inv = bpw(b, mod - 2);
  _b = b;
  for (int i = 1; i <= n; i++)
    if (a[i] ^ -1) {
      ans += query(a[i]) * b % mod * inv % mod;
      if (ans >= mod) ans -= mod;
    } else {
      b--;
    }
  b = _b;
  for (int i = n; i; i--)
    if (a[i] ^ -1) {
      ans += (_b - query(a[i])) * b % mod * inv % mod;
      if (ans >= mod) ans -= mod;
    } else {
      b--;
    }
  cout << ans << '\n';
  fflush(stdout);
  ;
  return 0;
}
