#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <typename T>
void DBG(const char* name, T&& H) {
  cerr << name << " = " << H << ')' << '\n';
}
template <typename T, typename... Args>
void DBG(const char* names, T&& H, Args&&... args) {
  const char* NEXT = strchr(names + 1, ',');
  cerr.write(names, NEXT - names) << " = " << H << " |";
  DBG(NEXT + 1, args...);
}
using ll = long long;
using ld = long double;
const long long mod = 1e9 + 7;
const long double PI = acos(-1.0);
const long long INF = 1e18;
const int maxN = 1e5 + 1;
struct modint {
  static constexpr int MOD = 998244353;
  using lli = long long;
  int vv;
  static int minv(int a, int m) {
    a %= m;
    assert(a);
    return a == 1 ? 1 : int(m - lli(minv(m, a)) * lli(m) / a);
  }
  modint() : vv(0) {}
  modint(lli v_) : vv(int(v_ % MOD)) {
    if (vv < 0) vv += MOD;
  }
  explicit operator int() const { return vv; }
  friend std::ostream& operator<<(std::ostream& out, const modint& n) {
    return out << int(n);
  }
  friend std::istream& operator>>(std::istream& in, modint& n) {
    lli v_;
    in >> v_;
    n = modint(v_);
    return in;
  }
  friend bool operator==(const modint& a, const modint& b) {
    return a.vv == b.vv;
  }
  friend bool operator!=(const modint& a, const modint& b) {
    return a.vv != b.vv;
  }
  modint inv() const {
    modint res;
    res.vv = minv(vv, MOD);
    return res;
  }
  friend modint inv(const modint& m) { return m.inv(); }
  modint neg() const {
    modint res;
    res.vv = vv ? MOD - vv : 0;
    return res;
  }
  friend modint neg(const modint& m) { return m.neg(); }
  modint operator-() const { return neg(); }
  modint operator+() const { return modint(*this); }
  modint& operator++() {
    vv++;
    if (vv == MOD) vv = 0;
    return *this;
  }
  modint& operator--() {
    if (vv == 0) vv = MOD;
    vv--;
    return *this;
  }
  modint& operator+=(const modint& o) {
    vv += o.vv;
    if (vv >= MOD) vv -= MOD;
    return *this;
  }
  modint& operator-=(const modint& o) {
    vv -= o.vv;
    if (vv < 0) vv += MOD;
    return *this;
  }
  modint& operator*=(const modint& o) {
    vv = int(lli(vv) * lli(o.vv) % MOD);
    return *this;
  }
  modint& operator/=(const modint& o) { return *this *= o.inv(); }
  friend modint operator++(modint& a, int) {
    modint r = a;
    ++a;
    return r;
  }
  friend modint operator--(modint& a, int) {
    modint r = a;
    --a;
    return r;
  }
  friend modint operator+(const modint& a, const modint& b) {
    return modint(a) += b;
  }
  friend modint operator-(const modint& a, const modint& b) {
    return modint(a) -= b;
  }
  friend modint operator*(const modint& a, const modint& b) {
    return modint(a) *= b;
  }
  friend modint operator/(const modint& a, const modint& b) {
    return modint(a) /= b;
  }
};
struct BIT {
  using T = int;
  vector<T> arr;
  T total;
  BIT(T s = 1e6) {
    total = 0;
    arr.assign(s + 1, 0);
  }
  T sum(T pos) {
    T ans = 0;
    while (pos > 0) {
      ans += arr[pos];
      pos = pos - (pos & (-pos));
    }
    return ans;
  }
  void update(T pos, T val) {
    while ((pos > 0) && (pos < arr.size())) {
      arr[pos] += val;
      pos = pos + (pos & (-pos));
    }
  }
  void insertElement(T x) {
    update(x, 1);
    total++;
  }
  void deleteElement(T x) {
    update(x, -1);
    total--;
  }
  T findRank(T x) { return sum(x); }
};
void Solve() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<int> left(N, 0), right(N, 0);
  if (a[0] == -1) left[0] = 1;
  if (a[N - 1] == -1) right[N - 1] = 1;
  for (int i = 1; i < N; i++) {
    if (a[i] == -1) left[i] = 1;
    left[i] += left[i - 1];
  }
  for (int i = N - 2; i >= 0; i--) {
    if (a[i] == -1) right[i] = 1;
    right[i] += right[i + 1];
  }
  modint ans = 0;
  ans += ((modint(left[N - 1]) * modint(left[N - 1] - 1)) / modint(4));
  BIT oset(N);
  for (int i = 1; i <= N; i++) {
    oset.insertElement(i);
  }
  for (int i = 0; i < N; i++) {
    if (a[i] != -1) oset.deleteElement(a[i]);
  }
  modint cnt = left[N - 1];
  if (int(cnt)) {
    for (int i = 0; i < N; i++) {
      if (a[i] == -1) continue;
      modint less = oset.findRank(a[i]);
      modint greater = oset.total - less;
      ans += (modint(left[i]) * greater) / cnt;
      ans += (modint(right[i]) * less) / cnt;
    }
  }
  oset.arr.assign(N + 1, 0);
  oset.total = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == -1) continue;
    ans += oset.total - oset.findRank(a[i]);
    oset.insertElement(a[i]);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    Solve();
  }
  return 0;
}
