#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 998244353;
inline long long pow(long long X, long long Y) {
  long long ans = 1;
  for (long long i = 1; i <= Y; i <<= 1) {
    if (Y & i) ans = ans * X % MOD;
    X = X * X % MOD;
  }
  return ans;
}
inline long long inv(long long X) { return pow(X, MOD - 2); }
long long FT1[1234567], FT2[1234567];
inline void FI1(long long i, long long dif) {
  for (; i <= 1048576; i += i & -i) FT1[i] += dif;
  return;
}
inline void FI2(long long i, long long dif) {
  for (; i <= 1048576; i += i & -i) FT2[i] += dif;
  return;
}
inline long long FS1(long long i) {
  long long ans = 0;
  for (; i > 0; i = i & i - 1) ans += FT1[i];
  return ans % MOD;
}
inline long long FS2(long long i) {
  long long ans = 0;
  for (; i > 0; i = i & i - 1) ans += FT2[i];
  return ans % MOD;
}
long long ans1, ans2, ans3;
long long N, i;
long long P[1234567];
bool chk[1234567];
long long cnt, cnt2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> P[i];
    if (P[i] != -1)
      chk[P[i]] = true;
    else
      cnt++;
  }
  ans1 = cnt * (cnt - 1) / 2 % MOD * inv(2) % MOD;
  for (i = 0; i < N; i++) {
    if (P[i] == -1)
      cnt2++;
    else {
      FI1(P[i], cnt - cnt2);
      FI2(P[i], cnt2);
    }
  }
  for (i = 1; i <= N; i++)
    if (!chk[i]) ans2 = (ans2 + FS1(1048576) - FS1(i) + FS2(i)) % MOD;
  ans2 = ans2 * inv(cnt) % MOD;
  for (i = 1; i <= 1048576; i++) FT1[i] = FT2[i] = 0;
  for (i = 0; i < N; i++) {
    if (P[i] != -1) {
      ans3 += FS1(1048576) - FS1(P[i]);
      FI1(P[i], 1);
    }
  }
  cout << (ans1 + ans2 + ans3 + MOD) % MOD << endl;
  return 0;
}
