#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <class T>
bool cmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
struct starter {
  high_resolution_clock::time_point t1, t2;
  starter() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    t1 = high_resolution_clock::now();
  }
  ~starter() {
    t2 = high_resolution_clock::now();
    duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
    cerr << "It took " << time_span.count() << " seconds.";
  }
} starter_;
const int64_t MOD = 998244353;
struct mi {
  using ll = long long;
  ll v;
  explicit operator ll() const { return v; }
  mi() { v = 0; }
  mi(ll _v) {
    v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
    if (v < 0) v += MOD;
  }
  friend bool operator==(const mi& a, const mi& b) { return a.v == b.v; }
  friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
  friend bool operator<(const mi& a, const mi& b) { return a.v < b.v; }
  mi& operator+=(const mi& m) {
    if ((v += m.v) >= MOD) v -= MOD;
    return *this;
  }
  mi& operator-=(const mi& m) {
    if ((v -= m.v) < 0) v += MOD;
    return *this;
  }
  mi& operator*=(const mi& m) {
    v = v * m.v % MOD;
    return *this;
  }
  mi& operator/=(const mi& m) { return (*this) *= inv(m); }
  friend mi pow(mi a, ll p) {
    mi ans = 1;
    assert(p >= 0);
    for (; p; p /= 2, a *= a)
      if (p & 1) ans *= a;
    return ans;
  }
  friend mi inv(const mi& a) {
    assert(a.v != 0);
    return pow(a, MOD - 2);
  }
  mi operator-() const { return mi(-v); }
  mi& operator++() { return *this += 1; }
  mi& operator--() { return *this -= 1; }
  mi operator++(int32_t) {
    mi temp;
    temp.v = v++;
    return temp;
  }
  mi operator--(int32_t) {
    mi temp;
    temp.v = v--;
    return temp;
  }
  friend mi operator+(mi a, const mi& b) { return a += b; }
  friend mi operator-(mi a, const mi& b) { return a -= b; }
  friend mi operator*(mi a, const mi& b) { return a *= b; }
  friend mi operator/(mi a, const mi& b) { return a /= b; }
  friend ostream& operator<<(ostream& os, const mi& m) {
    os << m.v;
    return os;
  }
  friend istream& operator>>(istream& is, mi& m) {
    ll x;
    is >> x;
    m.v = x;
    return is;
  }
};
struct BIT {
  int64_t N;
  vector<int64_t> bit;
  void init(int64_t n) {
    N = n;
    bit.assign(n + 1, 0);
  }
  void update(int64_t idx, int64_t val) {
    while (idx <= N) {
      bit[idx] += val;
      idx += idx & -idx;
    }
  }
  void updateMax(int64_t idx, int64_t val) {
    while (idx <= N) {
      bit[idx] = max(bit[idx], val);
      idx += idx & -idx;
    }
  }
  int64_t pref(int64_t idx) {
    int64_t ans = 0;
    while (idx > 0) {
      ans += bit[idx];
      idx -= idx & -idx;
    }
    return ans;
  }
  int64_t rsum(int64_t l, int64_t r) { return pref(r) - pref(l - 1); }
  int64_t prefMax(int64_t idx) {
    int64_t ans = -2e9;
    while (idx > 0) {
      ans = max(ans, bit[idx]);
      idx -= idx & -idx;
    }
    return ans;
  }
} T;
const int64_t inf = 1e18;
const int64_t N = 2e5 + 5;
int64_t n, p[N], have[N];
int64_t unknown, cnt_unknown[N];
int32_t main() {
  cin >> n;
  for (int64_t i = (1); i <= (n); ++i) {
    cin >> p[i];
    if (~p[i]) {
      have[p[i]] = 1;
    } else {
      unknown++;
      cnt_unknown[i] = 1;
    }
  }
  for (int64_t i = (1); i <= (n); ++i) {
    cnt_unknown[i] += cnt_unknown[i - 1];
    have[i] += have[i - 1];
  }
  mi ans = mi(unknown) * (unknown - 1) / 2;
  ans /= 2;
  auto get_poss = [&](int64_t L, int64_t R) {
    if (L > R) return int64_t(0);
    return (R - L + 1) - (have[R] - have[L - 1]);
  };
  if (unknown)
    for (int64_t i = (1); i <= (n); ++i) {
      if (p[i] == -1) continue;
      int64_t tot = cnt_unknown[i - 1];
      int64_t poss = get_poss(p[i] + 1, n);
      ans += mi(tot) * poss / unknown;
    }
  if (unknown)
    for (int64_t i = n; i; --i) {
      if (p[i] == -1) continue;
      int64_t tot = cnt_unknown[n] - cnt_unknown[i - 1];
      int64_t poss = unknown - get_poss(p[i] + 1, n);
      ans += mi(tot) * poss / unknown;
    }
  T.init(n);
  for (int64_t i = (1); i <= (n); ++i) {
    if (~p[i]) {
      ans += T.rsum(p[i] + 1, n);
      T.update(p[i], 1);
    }
  }
  cout << ans;
}
