#include using namespace std; const int N = 2e5 + 5, mod = 998244353; int g[N], f[N], inv[N], n, a[N], vis[N], maxx, cnt, ans, s[N]; int A(int n, int m){ if(m > n)return 0; return 1ll * f[n] * g[n - m] % mod; } int main(){ inv[1] = f[0] = g[0] = 1; for(int i = 1; i <= 200000; ++i){ f[i] = 1ll * f[i - 1] * i % mod; if(i > 1){ inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod; } g[i] = 1ll * g[i - 1] * inv[i] % mod; } cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i]; if(a[i] > 0){ vis[a[i]] = 1; } } for(int i = 1; i <= n; ++i){ s[i] = s[i - 1] + !vis[i]; } maxx = 0; for(int i = 1; i <= n; ++i){ maxx = max(maxx, a[i]); cnt += (a[i] == -1); if(a[i] > 0){ if(maxx == a[i]){ ans = (ans + 1ll * A(s[a[i]], cnt) * f[s[n] - cnt] % mod) % mod; } } else{ ans = (ans + 1ll * (A(s[n], cnt) - A(s[maxx], cnt) + mod) % mod * f[s[n] - cnt] % mod * inv[cnt] % mod) % mod; } } cout << ans; return 0; }