#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
double error = 1e-8;
inline long long int MOD(long long int x, long long int m = mod) {
  long long int y = x % m;
  return (y >= 0) ? y : y + m;
}
const int inf = INT_MAX;
const long long int infl = LLONG_MAX;
const int nmax = 2e5 + 5;
long long int inv[nmax];
void precal(int n, long long int m) {
  inv[1] = 1;
  for (int i = 2; i < n; ++i) inv[i] = (m - (m / i) * inv[m % i] % m) % m;
}
bool in[nmax];
int arr[nmax];
int BIT[nmax], n;
int prefix(int i) {
  int ret = 0;
  while (i >= 1) {
    ret += BIT[i];
    i -= i & -i;
  }
  return ret;
}
void update(int i, int x) {
  while (i <= n) {
    BIT[i] += x;
    i += i & -i;
  }
}
int main() {
  precal(nmax, mod);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] != -1) in[arr[i]] = true;
  }
  long long int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] == -1) continue;
    ans = (prefix(arr[i]) + ans) % mod;
    update(arr[i], 1);
  }
  long long int tmp = 0;
  memset(BIT, 0, sizeof(BIT));
  for (int i = 1; i <= n; i++)
    if (!in[i]) {
      update(i, 1);
      tmp++;
    }
  ans = (ans + (tmp * (tmp + mod - 1) % mod) * inv[4] % mod) % mod;
  long long int gaps = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] == -1) {
      gaps++;
      continue;
    }
    long long int x = prefix(arr[i]);
    ans = (ans + (x * gaps % mod) * inv[tmp] % mod) % mod;
    x = tmp - x;
    ans = (ans + (x * (tmp - gaps) % mod) * inv[tmp] % mod) % mod;
  }
  printf("%lld", ans);
}
