#include using namespace std; using ll = long long; const int N = 2e5 + 10, mod = 998244353; int n, a[N], cnt[N], mmax, ct, c; bool f[N]; ll ans, fact[N], factinv[N], inv[N]; ll C(int n, int m) { return fact[n] * factinv[m] % mod * factinv[n - m] % mod; } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], f[a[i]] = 1; for (int i = 1; i <= n; i++) ct += a[i] == -1; inv[1] = 1; for (int i = 2; i <= n; i++) { inv[i] = (mod - mod / i) * inv[mod % i] % mod; } fact[0] = factinv[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = fact[i - 1] * i % mod; factinv[i] = factinv[i - 1] * inv[i] % mod; } for (int i = 1; i <= n; i++) cnt[i] = cnt[i - 1] + !f[i]; for (int i = 1; i <= n; i++) { mmax = max(mmax, a[i]); if (a[i] == -1) c++, (ans += (C(ct, c) - C(cnt[mmax - 1], c) + mod) % mod * fact[c - 1] % mod * fact[ct - c] % mod) %= mod; else if (mmax == a[i] && cnt[mmax - 1] >= c) (ans += C(cnt[mmax - 1], c) * fact[c] % mod * fact[ct - c] % mod) %= mod; } cout << ans; return 0; }