class BIT: #0-indexed __slots__ = ["size", "tree","depth","n0"] def __init__(self, n): self.size = n self.tree = [0]*(n+1) self.depth = n.bit_length() self.n0 = 1< 0: s += self.tree[i] i -= i & -i return s def range_sum(self,l,r): #a_l + ... + a_r 閉区間 return self.get_sum(r) - self.get_sum(l-1) def range_sum_larger(self,l): #a_l + ... (端まで) return self.get_sum(self.size-1) - (self.get_sum(l-1) if l else 0) def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i SIZE=10**5+1; MOD=998244353 #10**9+7 #ここを変更する inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD inv[i] = finv[i]*fac[i-1]%MOD def choose(n,r): # nCk mod MOD の計算 if 0 <= r <= n: return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD else: return 0 def perm(n,r): # nPr mod MOD if 0 <= r <= n: return fac[n]*finv[n-r]%MOD else: return 0 import sys readline = sys.stdin.readline #n = int(readline()) #n,Q = map(int,readline().split()) n = int(readline()) *a, = map(int,readline().split()) # from itertools import permutations # cnt = [0]*n # for lst in permutations(list(range(1,n+1))): # for i in range(n): # if a[i] != -1 and lst[i] != a[i]: break # else: # m = 0 # for i in range(n): # m = max(m,lst[i]) # if m==lst[i]: cnt[i] += 1 # print(cnt) bit = BIT(n+1) for i in range(1,n+1): bit.add(i,1) for ai in a: if ai != -1: bit.add(ai,-1) tot = a.count(-1) ans = 0 m = 0 cnt = 0 for i,ai in enumerate(a): if ai == -1: cnt += 1 c = bit.get_sum(m) r = (fac[tot]-perm(c,cnt)*fac[tot-cnt])%MOD*inv[cnt] #print((perm(m-i-1+cnt,cnt)*fac[tot-cnt])%MOD,r%MOD) #print(r%MOD) ans = (ans+r)%MOD else: if m < ai: c = bit.get_sum(ai) r = perm(c,cnt)*fac[tot-cnt] #print(r) ans = (ans+r)%MOD m = ai else: r = 0 #print(r%MOD) print(ans)