#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
inline int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
inline int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
inline int mul(int a, int b) { return (int)((long long)a * b % MOD); }
inline int binpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b /= 2;
  }
  return res;
}
inline int inv(int a) { return binpow(a, MOD - 2); }
int gcd(int a, int b, int &x, int &y) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  int x1, y1;
  int d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
const int N = 2e5 + 5;
long long n, p[N], pos[N], num[N], prefix[N], suffix[N], bit[2 * N], ans,
    sum_prefix[N];
void update(int id, int val) {
  for (; id <= n; id = id | (id + 1)) bit[id] += val;
}
int find(int id) {
  int res = 0;
  for (; id >= 0; id = (id & (id + 1)) - 1) res += bit[id];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    if (p[i] != -1) pos[p[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    prefix[i] = prefix[i - 1] + (p[i] == -1);
  }
  for (int i = n; i >= 1; --i) suffix[i] = suffix[i + 1] + (p[i] == -1);
  for (int i = 1; i <= n; ++i) {
    num[i] = num[i - 1] + !pos[i];
  }
  for (int i = 1; i <= n; ++i) {
    sum_prefix[i] = sum_prefix[i - 1] + prefix[pos[i]];
    sum_prefix[i] %= MOD;
  }
  int total = num[n];
  double ans1 = 0;
  for (int i = 1; i <= n; ++i) {
    long long less = i - 1 - num[i - 1] - find(pos[i] - 1);
    if (!total)
      ans += less, ans1 += less;
    else if (pos[i]) {
      ans += less + num[i - 1] * suffix[pos[i]] % MOD * inv(total);
      ans1 += less + 1.0 * num[i - 1] * suffix[pos[i]] / total;
    } else {
      ans += num[i - 1] * inv(2);
      ans %= MOD;
      ans += sum_prefix[i - 1] * inv(total);
      ans1 += num[i - 1] / 2.0 + 1.0 * sum_prefix[i - 1] / total;
    }
    if (pos[i]) update(pos[i], 1);
    ans %= MOD;
  }
  cout << ans << "\n";
  return 0;
}
