#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long mod = 998244353;
long long ar[N], l[N], a[N], lis[N], sum1 = 0, ans = 0, sortt[N], fact[N];
bool cnt[N];
void mergee(long long l, long long r, long long mid) {
  long long ite1 = 1, ite2 = 1, sum = 1;
  while (sum <= r - l + 1) {
    if (ite1 == mid - l + 1) {
      while (ite2 < r - mid + 2) {
        sortt[sum] = lis[ite2 + mid - 1];
        sum++;
        ite2++;
      }
      break;
    }
    if (ite2 == r - mid + 2) {
      while (ite1 < mid - l + 1) {
        ans = (ans + ite2 - 1) % mod;
        sortt[sum] = lis[ite1 + l - 1];
        sum++;
        ite1++;
      }
      break;
    }
    if (lis[ite1 + l - 1] > lis[ite2 + mid - 1]) {
      sortt[sum] = lis[ite2 + mid - 1];
      sum++;
      ite2++;
    } else {
      ans = (ans + ite2 - 1) % mod;
      sortt[sum] = lis[ite1 + l - 1];
      ite1++;
      sum++;
    }
  }
  for (long long i = l; i <= r; i++) {
    lis[i] = sortt[i - l + 1];
  }
}
void m_sortt(long long l, long long r) {
  if (l == r) {
    return;
  }
  long long mid = (l + r) / 2;
  m_sortt(l, mid);
  m_sortt(mid + 1, r);
  mergee(l, r, mid + 1);
}
long long binpow(long long x, long long y) {
  long long tich = 1, mul = x;
  while (y > 0) {
    if (y % 2 == 1) {
      tich = (tich * mul) % mod;
    }
    mul = (mul * mul) % mod;
    y >>= 1;
  }
  return tich;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, i, j, k;
  cin >> n;
  fact[0] = 1;
  for (i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    cin >> ar[i];
    l[i] = l[i - 1];
    if (ar[i] != -1) {
      cnt[ar[i]] = true;
      sum1++;
      lis[sum1] = ar[i];
    }
    if (ar[i - 1] < 0) {
      l[i]++;
    }
  }
  if (sum1 > 1) {
    m_sortt(1, sum1);
  }
  for (i = 1; i <= n; i++) {
    a[i] = a[i - 1];
    if (!cnt[i - 1] && i > 1) {
      a[i]++;
    }
  }
  ans = (ans * fact[n - sum1]) % mod;
  if (n - sum1 >= 2) {
    i = n - sum1;
    i = ((i * (i - 1)) / 2) % mod;
    ans = (ans + ((((fact[n - sum1 - 2] * i) % mod) * i) % mod)) % mod;
  }
  for (i = 1; i <= n; i++) {
    if (ar[i] != -1) {
      ans = (ans + (((l[i] * (n - sum1 - a[ar[i]])) % mod) +
                    (((n - sum1 - l[i]) * a[ar[i]]) % mod)) *
                       fact[n - sum1 - 1]) %
            mod;
    }
  }
  cout << (ans * binpow(fact[n - sum1], mod - 2)) % mod;
}
