#include using namespace std; #define int long long const int N = 1e6 + 5, mod = 998244353; int n, x[N], ans, sum, cnt[N], now; int inv[N], g[N], f[N]; bool vis[N]; int C(int n, int m) { if (n < m) { return 0; } return f[n] * g[m] % mod * g[n - m] % mod; } signed main() { ios::sync_with_stdio(0); cin.tie(0); inv[1] = f[0] = g[0] = 1; for (int i = 1; i <= 1000000; i++) { f[i] = f[i - 1] * i % mod; if (i > 1) inv[i] = inv[mod % i] * (mod - mod / i) % mod; g[i] = g[i - 1] * inv[i] % mod; } cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i]; cnt[max(0ll, x[i])] = 1; now += (x[i] == -1); } cnt[0] = 0; for (int i = 1; i <= n; i++) { cnt[i] = !cnt[i]; cnt[i] += cnt[i - 1]; } int maxi = 0, c = 0; for (int i = 1; i <= n; i++) { maxi = max(maxi, x[i]); if (x[i] == -1) { c++; ans += (C(now, c) - C(cnt[maxi], c) + mod) % mod * f[c - 1] % mod * f[now - c] % mod; ans %= mod; } else { if (maxi == x[i] && cnt[maxi] >= c) { ans += C(cnt[maxi], c) * f[c] % mod * f[now - c] % mod; ans %= mod; } } } cout << ans << "\n"; 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 */