#include using namespace std; using i64 = long long; const int N = 2e5 + 10, P = 998244353; int n, a[N], m, b[N]; int inv[N], fact[N], invFact[N]; int A(int n, int m) { if(m < 0 || m > n) return 0; return fact[n] * (i64)invFact[n - m] % P; } int main() { inv[1] = fact[0] = fact[1] = invFact[0] = invFact[1] = 1; for(int i = 2; i < N; i ++) { inv[i] = (P - P / i) * (i64)inv[P % i] % P; fact[i] = fact[i - 1] * (i64)i % P; invFact[i] = invFact[i - 1] * (i64)inv[i] % P; } ios::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i <= n; i ++) { if(a[i] == -1) m ++; else b[a[i]] ++; } for(int i = 1; i <= n; i ++) b[i] = b[i - 1] + (1 - b[i]); int ans = 0; for(int i = 1, p = 0, q = 0; i <= n; i ++) { if(a[i] == -1) { q ++; ans = ans + (fact[m] + P - A(b[p], q) * (i64)fact[m - q] % P) * inv[q] % P; }else{ if(a[i] < p) continue; p = a[i]; ans = (ans + A(b[p], q) * (i64)fact[m - q]) % P; } } cout << ans; }