#include #include using namespace std; const int MAXN = 2e5 + 5, Mod = 998244353; bool vis[MAXN]; vector se; int n, m, 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 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; } } 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) * A(m - c, m - c)) % Mod; } } else { int y = lower_bound(se.begin(), se.end(), x) - se.begin() + 1; y = max(y, c + 1); for (int i = y; i <= se.size(); i++) { ans = (ans + 1ll * A(i - 1, c) * A(m - c - 1, m - c - 1)) % Mod; } c++; } x = max(x, a[i]); } cout << ans; return 0; }