#include <bits/stdc++.h>
using namespace std;
long long int po(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return po((x * x) % 998244353, n / 2);
  else
    return (x * po((x * x) % 998244353, (n - 1) / 2)) % 998244353;
}
long long int GCD(long long int A, long long int B) {
  if (B == 0)
    return A;
  else
    return GCD(B, A % B);
}
int tree[800001] = {0};
int query(int node, int start, int end, int l, int r) {
  if (r < start or end < l) {
    return 0;
  }
  if (l <= start and end <= r) {
    return tree[node];
  }
  int mid = (start + end) / 2;
  int p1 = query(2 * node, start, mid, l, r);
  int p2 = query(2 * node + 1, mid + 1, end, l, r);
  return (p1 + p2);
}
void update(int node, int start, int end, int idx, int val) {
  if (start == end) {
    tree[node] = val;
  } else {
    int mid = (start + end) / 2;
    if (start <= idx and idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update(2 * node + 1, mid + 1, end, idx, val);
    }
    tree[node] = tree[2 * node] + tree[2 * node + 1];
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long int ct = 0;
  long long int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == -1)
      ct++;
    else {
      ans += query(1, 0, n, a[i], n);
      ans %= 998244353;
      update(1, 0, n, a[i], 1);
    }
  }
  for (int i = 1; i <= n; ++i) update(1, 0, n, i, 1);
  for (int i = 0; i < n; ++i)
    if (a[i] != -1) update(1, 0, n, a[i], 0);
  long long int r = ct * (ct - 1);
  r %= 998244353;
  r *= po(4, 998244353 - 2);
  r %= 998244353;
  ans += r;
  ans %= 998244353;
  long long int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == -1)
      ++cnt;
    else {
      long long int r = cnt * query(1, 0, n, a[i], n);
      r %= 998244353;
      r *= po(ct, 998244353 - 2);
      r %= 998244353;
      ans += r;
      ans %= 998244353;
      r = (ct - cnt) * query(1, 0, n, 1, a[i]);
      r %= 998244353;
      r *= po(ct, 998244353 - 2);
      r %= 998244353;
      ans += r;
      ans %= 998244353;
    }
  }
  cout << ans << "\n";
}
