from _collections import defaultdict n=int(input()) a=list(map(int,input().split())) ans=0 mod=998244353 dp=defaultdict(int) for x in a: dp[x]+=1+dp[x-1] dp[x]%=mod for x in dp:ans+=dp[x] ans-=n print(ans%mod)