#include #define _1 (__int128)1 using namespace std; using ll = long long; void FileIO (const string s) { freopen(string(s + ".in").c_str(), "r", stdin); freopen(string(s + ".out").c_str(), "w", stdout); } const int N = 2e5 + 10, mod = 998244353; int n, a[N], b[N], m, inv[N], X[N], F[N], ans, mx[N], cnt; bool f[N]; inline int C (int a, int b) { return (a >= b ? 1ll * F[a] * X[b] % mod * X[a - b] % mod : 0); } inline int A (int a, int b) { return (a >= b ? 1ll * F[a] * X[a - b] % mod : 0); } int qmod (int x, int y) { int ret = 1; while (y) ret = (y & 1 ? 1ll * ret * x % mod : ret), x = 1ll * x * x % mod, y >>= 1; return ret; } signed main () { ios::sync_with_stdio(0), cin.tie(0); // FileIO(""); cin >> n; inv[1] = X[0] = F[0] = 1; for (int i = 2; i <= n; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; for (int i = 1; i <= n; i++) X[i] = 1ll * X[i - 1] * inv[i] % mod, F[i] = 1ll * F[i - 1] * i % mod; for (int i = 1; i <= n; i++) cin >> a[i], f[(a[i] != -1 ? a[i] : 0)] = 1, mx[i] = max(a[i], mx[i - 1]); for (int i = 1; i <= n; i++) if (!f[i]) b[++m] = i; for (int i = 1; i <= n; i++) { if (a[i] == -1) { cnt++, ans = (ans + 1ll * (A(m, cnt) - A((lower_bound(b + 1, b + m + 1, mx[i]) - b - 1), cnt)) * A(m - cnt, m - cnt) % mod * qmod(cnt, mod - 2)) % mod; } else if (a[i] > mx[i - 1]) { ans = (ans + 1ll * A((lower_bound(b + 1, b + m + 1, a[i]) - b - 1), cnt) * A(m - cnt, m - cnt)) % mod; } } cout << ans; return 0; }