import sys input = sys.stdin.readline N=int(input()) P=list(map(int,input().split())) mod=998244353 ANS=1 P_INV=[-1]*N for i in range(N): P_INV[P[i]]=i LEN=N+10 BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。 def update(v,w): # index vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v): # [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ return ANS L=10**8 R=-100 for i in range(N): x=P_INV[i]+5 L2=min(L,x) R2=max(R,x) if R2-L2==R-L: sc=(R-L+1)-(getvalue(R)-getvalue(L-1)) ANS*=sc ANS%=mod update(x,1) L=L2 R=R2 print(ANS)