#include <bits/stdc++.h>
using namespace std;
const int N = 200007, M = 998244353;
int seg[N + N];
int v[N];
int query(int l, int r) {
  int ans = 0;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans += seg[l++];
    if (r & 1) ans += seg[--r];
  }
  return ans;
}
void update(int p, int val) {
  for (seg[p += N] = val; p > 0; p >>= 1) {
    seg[p >> 1] = seg[p] + seg[p ^ 1];
  }
}
long long fat[N], inv[N];
int has[N], cnt[N];
long long fast_pow(long long a, int b) {
  long long ans = 1, aux = a;
  while (b) {
    if (b & 1) ans = (ans * aux) % M;
    aux = (aux * aux) % M;
    b >>= 1;
  }
  return ans;
}
int main() {
  inv[1] = 1;
  for (int i = 2; i < N; i++) inv[i] = M - (M / i) * inv[M % i] % M;
  fat[0] = 1;
  for (int i = 1; i < N; ++i) fat[i] = (fat[i - 1] * i) % M;
  int n;
  scanf("%d", &n);
  long long lac = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", v + i);
    lac += v[i] == -1;
    has[v[i]] = 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (v[i] == -1) continue;
    ans += query(v[i], n + 1);
    ans %= M;
    update(v[i], 1);
  }
  ans += (((lac * (lac - 1)) / 2) % M * inv[2]) % M;
  ans %= M;
  int cnt_lac = 0;
  long long tot = 0;
  for (int i = 1; i <= n; ++i) {
    cnt_lac += v[i] == -1;
    if (v[i] == -1) continue;
    cnt[v[i]] += cnt_lac;
  }
  long long acc = 0;
  for (int i = 1; i <= n; ++i) {
    acc += cnt[i];
    if (has[i]) continue;
    tot += (acc * fat[lac - 1]) % M;
    tot %= M;
  }
  memset(cnt, 0, sizeof cnt);
  cnt_lac = 0;
  for (int i = n; i > 0; --i) {
    cnt_lac += v[i] == -1;
    if (v[i] == -1) continue;
    cnt[v[i]] += cnt_lac;
  }
  acc = 0;
  for (int i = n; i > 0; --i) {
    acc += cnt[i];
    if (has[i]) continue;
    tot += (acc * fat[lac - 1]) % M;
    tot %= M;
  }
  tot = (tot * fast_pow(fat[lac], M - 2)) % M;
  ans = (ans + tot) % M;
  printf("%lld\n", ans);
}
