#include using namespace std; const int MAXN = 200005, MOD = 998244353; int n, a[MAXN], f[MAXN], ans, Max, cnt, sum[MAXN], res[MAXN], inv[MAXN], Inv[MAXN]; vector pos; int A(int n, int m) { return (n < m ? 0 : 1ll * f[n] * Inv[n - m] % MOD); } int C(int n, int m) { return (n < m ? 0 : 1ll * f[n] * Inv[m] % MOD * Inv[n - m] % MOD); } int Pow(int a, int b) { int ret = 1; for(; b; a = 1ll * a * a % MOD, b >>= 1) { if(b & 1) { ret = 1ll * ret * a % MOD; } } return ret; } int Calc(int n, int x, int a) { return (1ll * f[a] * ((x - a + MOD) % MOD) % MOD * Pow(f[a - x], MOD - 2) % MOD + 1ll * f[n + 1] * (n - x + 1) % MOD * Pow(f[n - x + 1], MOD - 2) % MOD) % MOD * 1ll * Pow(x + 1, MOD - 2) % MOD; } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; f[0] = inv[1] = Inv[0] = res[0] = 1; for(int i = 1; i < MAXN; ++i) { f[i] = 1ll * f[i - 1] * i % MOD; res[i] = (res[i - 1] + Pow(f[i], MOD - 2)) % MOD; inv[i] = (i > 1 ? 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD : 1); Inv[i] = 1ll * Inv[i - 1] * inv[i] % MOD; } for(int i = 1; i <= n; ++i) { cin >> a[i]; if(a[i] != -1) { sum[a[i]] = 1; } } for(int i = 1; i <= n; ++i) { if(!sum[i]) { pos.emplace_back(i); } sum[i] = sum[i - 1] + !sum[i]; } for(int i = 1; i <= n; ++i) { Max = max(Max, a[i]), cnt += (a[i] == -1); if(a[i] == -1) { int x = lower_bound(pos.begin(), pos.end(), Max) - pos.begin(); if(x == pos.size()) { continue; } ans = (ans + 1ll * Calc(sum[n] - 1, cnt - 1, max(cnt - 1, x)) % MOD * f[sum[n] - cnt] % MOD) % MOD; }else if(a[i] == Max) { ans = (ans + 1ll * A(sum[Max], cnt) * f[sum[n] - cnt] % MOD) % MOD; } } cout << ans; return 0; }