import heapq mod=998244353 n=int(input()) a=list(map(int,input().split())) hq=[] for i in range(n): heapq.heappush(hq,(a[i],i)) b=[] while hq: q,w=heapq.heappop(hq) if b and b[-1]>w: continue b.append(w) ans=1 for i in range(1,len(b)): ans*=(b[i]-b[i-1]+1);ans%=mod print(ans)