#include <bits/stdc++.h>
using namespace std;
long long tree[8000100] = {0};
void update(long long node, long long l, long long r, long long x) {
  if (x < l || x > r) return;
  if (l == r && r == x) {
    tree[node] = 1;
    return;
  }
  update(2 * node + 1, l, (l + r) / 2, x);
  update(2 * node + 2, (l + r) / 2 + 1, r, x);
  tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
long long get(long long node, long long l, long long r, long long x,
              long long y) {
  if (l > y || r < x) return 0;
  if (l >= x && r <= y) return tree[node];
  return get(2 * node + 1, l, (l + r) / 2, x, y) +
         get(2 * node + 2, (l + r) / 2 + 1, r, x, y);
}
long long fast(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long x = fast(a, b / 2) % 998244353;
    return (x * x) % 998244353;
  }
  return ((a % 998244353) * (fast(a, b - 1) % 998244353)) % 998244353;
}
long long fact[300002] = {0};
int main() {
  long long n;
  cin >> n;
  fact[0] = 1;
  for (long long i = 1; i <= n; i++)
    fact[i] = ((fact[i - 1] % 998244353) * (i % 998244353)) % 998244353;
  vector<long long> p(n + 1);
  for (long long i = 1; i <= n; i++) cin >> p[i];
  vector<long long> ones(n + 1);
  vector<long long> index(n + 1);
  for (long long i = 1; i <= n; i++) {
    ones[i] = ones[i - 1] + (p[i] == -1);
    if (p[i] != -1) index[p[i]] = i;
  }
  long long ans = 0;
  for (long long i = n; i >= 1; i--) {
    if (p[i] == -1) continue;
    ans = ans + get(0, 0, n, 1, p[i]);
    update(0, 0, n, p[i]);
  }
  ans = (ans % 998244353) * (fact[ones[n]]);
  long long c = 0;
  if (ones[n] >= 1) {
    for (long long i = 1; i <= n; i++) {
      if (index[i] == 0)
        ans = (ans % 998244353 +
               ((c % 998244353) * ((fact[ones[n] - 1]) % 998244353)) %
                   998244353) %
              998244353;
      else
        c = c + ones[index[i]];
    }
    c = 0;
    for (long long i = n; i >= 1; i--) {
      if (index[i] == 0)
        ans = (ans % 998244353 +
               ((c % 998244353) * ((fact[ones[n] - 1]) % 998244353)) %
                   998244353) %
              998244353;
      else
        c = c + (ones[n] - ones[index[i]]);
    }
  }
  if (ones[n] >= 2) {
    long long z = (ones[n] * (ones[n] - 1)) / 2;
    for (long long i = 1; i <= n; i++) {
      if (p[i] == -1) {
        ans = (ans % 998244353 +
               (((((ones[n] - ones[i] + 998244353) % 998244353) *
                  (z % 998244353)) %
                 998244353) *
                ((fact[ones[n] - 2] % 998244353) % 998244353)) %
                   998244353) %
              998244353;
      }
    }
  }
  ans = ((ans % 998244353) * (fast(fact[ones[n]], 998244353 - 2) % 998244353)) %
        998244353;
  cout << ans << '\n';
  return 0;
}
