#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 2e5 + 5, D = (1 << 19) + 5, pods = (1 << 18) - 1;
const long long MOD = 998244353;
int n, tab[N], d[D], pref[N], suf[N];
bool inv[N];
long long k;
void add(int x, int val) {
  x += pods;
  d[x] += val;
  while (x != 1) {
    x /= 2;
    d[x] = d[2 * x] + d[2 * x + 1];
  }
}
int sum(int x, int y) {
  x += pods;
  y += pods;
  int ans = d[x];
  if (x != y) ans += d[y];
  while (x / 2 != y / 2) {
    if (x % 2 == 0) ans += d[x + 1];
    if (y % 2 == 1) ans += d[y - 1];
    x /= 2;
    y /= 2;
  }
  return ans;
}
long long pot(long long a, long long p) {
  if (p == 0) return 1;
  long long w = pot(a, p / 2);
  w = w * w % MOD;
  if (p % 2) w = w * a % MOD;
  return w;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &tab[i]);
    inv[tab[i]] = 1;
  }
  long long ans1 = 0;
  for (int i = 1; i <= n; i++)
    if (tab[i] != -1) {
      if (tab[i] != n) ans1 += sum(tab[i] + 1, n);
      add(tab[i], 1);
    }
  for (int i = 1; i <= n; i++) k += (!inv[i]);
  for (long long s = 2; s <= k; s++) ans1 = (ans1 * s) % MOD;
  long long ans4 = (k * (k - 1) / 2) % MOD;
  ans4 = ans4 * ans4 % MOD;
  for (long long s = 2; s <= k - 2; s++) ans4 = (ans4 * s) % MOD;
  for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + (!inv[i]);
  for (int i = n; i > 0; i--) suf[i] = suf[i + 1] + (!inv[i]);
  long long ans2 = 0;
  long long cnt = 0;
  for (int i = 1; i <= n; i++)
    if (tab[i] != -1) {
      ans2 = (ans2 + (long long)suf[tab[i]] * cnt) % MOD;
    } else
      cnt++;
  for (long long s = 2; s <= k - 1; s++) ans2 = (ans2 * s) % MOD;
  cnt = 0;
  long long ans3 = 0;
  for (int i = n; i > 0; i--)
    if (tab[i] != -1) {
      ans3 = (ans3 + (long long)pref[tab[i]] * cnt) % MOD;
    } else
      cnt++;
  for (long long s = 2; s <= k - 1; s++) ans3 = (ans3 * s) % MOD;
  long long ans = (ans1 + ans2 + ans3 + ans4) % MOD;
  long long kk = 1;
  for (long long s = 2; s <= k; s++) kk = (kk * s) % MOD;
  ans = ans * pot(kk, MOD - 2) % MOD;
  printf("%lld\n", ans);
  return 0;
}
