#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long double EPS = 1e-9;
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const unordered_set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const unordered_map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const multiset<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  long long idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
struct Fen {
  vector<long long> ft;
  Fen(long long i = 0) { ft.assign(i + 1, 0); }
  long long rsq(long long b) {
    b++;
    long long sumer = 0;
    for (; b > 0; b -= (b & (-b))) sumer += ft[b];
    return sumer;
  }
  void addat(long long k, long long v) {
    k++;
    for (; k < (long long)ft.size(); k += (k & (-k))) ft[k] += v;
  }
};
long long merger(vector<long long>& arr, long long l, long long r) {
  long long i = l;
  long long mid = (l + r) >> 1;
  long long j = ((l + r) >> 1) + 1;
  long long a[r - l + 1];
  long long c = 0;
  long long ans = 0;
  while (i <= mid && j <= r) {
    if (arr[i] <= arr[j]) {
      a[c++] = arr[i++];
    } else {
      ans += mid + 1 - i;
      a[c++] = arr[j++];
    }
  }
  while (i <= mid) {
    a[c++] = arr[i++];
  }
  while (j <= r) {
    a[c++] = arr[j++];
  }
  c = 0;
  for (int i = l; i <= r; i++) {
    arr[i] = a[c++];
  }
  return ans;
}
long long mergesort(vector<long long>& arr, long long l, long long r) {
  if (l == r) {
    return 0;
  }
  int mid = (l + r) >> 1;
  long long ans = 0;
  ans += mergesort(arr, l, mid);
  ans += mergesort(arr, mid + 1, r);
  ans += merger(arr, l, r);
  return ans;
}
vector<long long> notseen;
long long arr[200200];
bool seen[200200];
vector<long long> getcomp;
void solve() {
  long long n;
  cin >> n;
  Fen ff(n + 1);
  long long cnt = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> arr[i];
    if (arr[i] != -1) {
      seen[arr[i]] = 1;
      getcomp.emplace_back(arr[i]);
    } else {
      ff.addat(i, 1);
      cnt++;
    }
  }
  for (long long i = 1; i <= n; ++i) {
    if (!seen[i]) {
      notseen.emplace_back(i);
    }
  }
  long long ans = (cnt * (cnt - 1) % MOD) * binpow(4, MOD - 2, MOD) % MOD;
  if (cnt != n) {
    ans = (ans + mergesort(getcomp, 0, (int)getcomp.size() - 1)) % MOD;
  }
  if (cnt != 0) {
    for (long long i = 0; i < n; ++i) {
      if (arr[i] != -1) {
        long long pos = cnt - ff.rsq(i);
        long long lessnums =
            lower_bound((notseen).begin(), (notseen).end(), arr[i]) -
            notseen.begin();
        ans = (ans +
               (((lessnums * pos) % MOD) * binpow(cnt, MOD - 2, MOD)) % MOD) %
              MOD;
        long long pos2 = ff.rsq(i);
        long long morenums = cnt - lessnums;
        ans = (ans +
               (((morenums * pos2) % MOD) * binpow(cnt, MOD - 2, MOD)) % MOD) %
              MOD;
      }
    }
  }
  cout << ans % MOD << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
