#include <bits/stdc++.h>
using namespace std;
long long n, m, init[500010], smaller[500010], bigger[500010], tre[500010],
    S[500010], pre[500010], las[500010], cnt[500010];
inline long long read() {
  long long x;
  cin >> x;
  return x;
}
inline long long upd(long long x) {
  return ((x % 998244353) + 998244353) % 998244353;
}
inline long long ksm(long long x, long long y) {
  long long res = 1;
  for (; y; y >>= 1, x = x * x % 998244353)
    if (y & 1) res = res * x % 998244353;
  return res;
}
inline void add(long long x, long long k) {
  while (x <= n) tre[x] += k, x += x & -x;
}
inline long long get(long long x) {
  long long res = 0;
  while (x) res = res + tre[x], x -= x & -x;
  return res;
}
long long inv, ans;
signed main() {
  n = read();
  for (long long i = 1; i <= n; ++i) init[i] = read();
  for (long long i = 1; i <= n; ++i) cnt[i] = init[i] == -1;
  for (long long i = 1; i <= n; ++i) pre[i] = pre[i - 1] + cnt[i];
  for (long long i = n; i >= 1; --i) las[i] = las[i + 1] + cnt[i];
  for (long long i = 1; i <= n; ++i)
    if (init[i] != -1) S[init[i]] = 1;
  for (long long i = 1; i <= n; ++i)
    if (S[i] ^ 1) add(i, 1);
  for (long long i = 1; i <= n; ++i)
    if (init[i] != -1) bigger[i] = get(n) - get(init[i]);
  for (long long i = n; i >= 1; --i)
    if (init[i] != -1) smaller[i] = get(init[i]);
  long long num = pre[n];
  inv = ksm(4LL, 998244353 - 2);
  ans = ans + num * (num - 1) % 998244353 * inv;
  ans = upd(ans);
  memset(tre, 0, sizeof tre);
  for (long long i = 1; i <= n; ++i)
    if (init[i] != -1)
      ans = ans + get(n) - get(init[i]), add(init[i], 1), ans = upd(ans);
  inv = ksm(num, 998244353 - 2);
  for (long long i = 1; i <= n; ++i)
    if (init[i] != -1) {
      ans = ans + ((bigger[i] * pre[i] % 998244353 * inv) % 998244353);
      ans = upd(ans);
      ans = ans + ((smaller[i] * las[i] % 998244353 * inv) % 998244353);
      ans = upd(ans);
    }
  printf("%lld\n", upd(ans));
  return 0;
}
