n = int(input()) A = list(map(int,input().split())) mod = 998244353 ans = 0 dic = {} for a in A: ans += dic.get(a-1,0) ans %= mod dic[a] = (dic.get(a,0)+dic.get(a-1,0)+1)%mod print(ans)