#include #include using namespace std; const int MAXN = 2e5 + 5, Mod = 998244353; bool vis[MAXN]; vector se; int n, m, k, ans, a[MAXN], b[MAXN], fac[MAXN] = {1, 1}, inv[MAXN] = {0, 1}, facinv[MAXN] = {1, 1}; int A(int n, int m) { if (n < m) return 0; return 1ll * fac[n] * facinv[n - m] % Mod; } int qpow(int x, int k) { int ret = 1; for (; k; k >>= 1, x = 1ll * x * x % Mod) { if (k & 1) ret = 1ll * x * ret % Mod; } return ret; } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > 0) { vis[a[i]] = 1; } } if (!vis[1]) se.push_back(1); for (int i = 2; i <= n; i++) { fac[i] = 1ll * fac[i - 1] * i % Mod; inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod; facinv[i] = 1ll * facinv[i - 1] * inv[i] % Mod; if (!vis[i]) se.push_back(i); } m = se.size(); for (int i = 1, x = 0, c = 0; i <= n; i++) { if (a[i] > 0) { if (a[i] > x) { int y = lower_bound(se.begin(), se.end(), a[i]) - se.begin(); ans = (ans + 1ll * A(y, c) * fac[m - c]) % Mod; } } else { int y = lower_bound(se.begin(), se.end(), x) - se.begin(); c++, ans = (ans + 1ll * (A(m, c) - A(y, c) + Mod) * qpow(c, Mod - 2) % Mod * fac[m - c]) % Mod; } x = max(x, a[i]); } cout << ans; return 0; }