## https://yukicoder.me/problems/no/2898 MOD = 998244353 class CombinationCalculator: """ modを考慮したPermutation, Combinationを計算するためのクラス """ def __init__(self, size, mod): self.mod = mod self.factorial = [0] * (size + 1) self.factorial[0] = 1 for i in range(1, size + 1): self.factorial[i] = (i * self.factorial[i - 1]) % self.mod self.inv_factorial = [0] * (size + 1) self.inv_factorial[size] = pow(self.factorial[size], self.mod - 2, self.mod) for i in reversed(range(size)): self.inv_factorial[i] = ((i + 1) * self.inv_factorial[i + 1]) % self.mod def calc_combination(self, n, r): if n < 0 or n < r or r < 0: return 0 if r == 0 or n == r: return 1 ans = self.inv_factorial[n - r] * self.inv_factorial[r] ans %= self.mod ans *= self.factorial[n] ans %= self.mod return ans def calc_permutation(self, n, r): if n < 0 or n < r: return 0 ans = self.inv_factorial[n - r] ans *= self.factorial[n] ans %= self.mod return ans def main(): N = int(input()) A = list(map(int, input().split())) # 下準備 free = 0 used = 0 for i in range(N): if A[i] == -1: free += 1 else: used += 1 # 下準備2 a_array = [a for a in A if a != -1] a_array.sort() a_map = {} for i in range(len(a_array)): a_map[a_array[i]] = i + 1 answer = 0 combi = CombinationCalculator(N, MOD) fixed_max_a = -1 before_used = 0 for m in range(N): if A[m] == -1: free -= 1 ans = combi.calc_permutation(N - used, m + 1 - before_used) if fixed_max_a != -1: ans -= combi.calc_permutation(fixed_max_a - a_map[fixed_max_a], m + 1 - before_used) ans %= MOD ans *= pow(m + 1 - before_used, MOD - 2, MOD) ans %= MOD # 残り部分の組み合わせ ans *= combi.factorial[free] ans %= MOD else: before_used += 1 if fixed_max_a > A[m]: continue ans = combi.calc_permutation(A[m] - a_map[A[m]], m + 1 - before_used) # 残り部分の組み合わせ ans *= combi.factorial[free] ans %= MOD fixed_max_a = max(fixed_max_a, A[m]) answer += ans answer %= MOD print(answer) if __name__ == "__main__": main()