#include using namespace std; const int N = 2e5 + 5; const int mod = 998244353; int n, a[N]; bool vis[N]; vector s; long long pl[N], inv[N], ipl[N]; void init(int inf){ pl[0] = pl[1] = 1, inv[0] = inv[1] = 1, ipl[0] = ipl[1] = 1; for(int i = 2; i <= inf; i++){ pl[i] = pl[i - 1] * i % mod; inv[i] = (mod - mod / i) * inv[mod % i] % mod; ipl[i] = ipl[i - 1] * inv[i] % mod; } } long long A(long long n, long long m){ if(m > n) return 0; if(n < 0 || m < 0) return 0; return pl[n] * ipl[n - m] % mod; } int main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n; int sum = 0; for(int i = 1; i <= n; i++){ cin >> a[i]; if(a[i] >= 1) vis[a[i]] = 1; sum += (a[i] < 0); } init(n); for(int i = 1; i <= n; i++){ if(!vis[i]) s.push_back(i); } long long ans = 0; for(int i = 1, cnt = 0, maxx = 0; i <= n; i++){ if(a[i] >= 0){ if(a[i] > maxx){ int l = lower_bound(s.begin(), s.end(), a[i]) - s.begin(); ans = (ans + A(l, cnt) * pl[sum - cnt] % mod) % mod; } } else{ /*for(int j = lower_bound(s.begin(), s.end(), maxx + 1) - s.begin(); j < s.size(); j++){ ans = (ans + A(j, cnt) * pl[sum - cnt - 1] % mod) % mod; }*/ int l = lower_bound(s.begin(), s.end(), maxx + 1) - s.begin(); ans = (ans + (A(s.size(), cnt + 1) - A(l, cnt + 1) + mod) % mod * inv[cnt + 1] % mod * pl[sum - cnt - 1] % mod) % mod; } cnt += (a[i] < 0), maxx = max(maxx, a[i]); } cout << ans; return 0; } /* 4 1 -1 3 -1 6 2 4 5 3 6 1 17 -1 -1 8 2 10 9 12 -1 7 -1 -1 -1 11 -1 13 -1 -1 */